Dimensions Of An Array
How can I find the dimensions (not the upper and lower bounds!) of an array at run time? For instance, if I have declared:
Dim Arr(10, 6, 11)
the result should be 3
Dim Arr(2, 4)
the result should be 2, etc.
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
2 Dimensions Array
How do u find the upperbound of it?
..besides storing it in a public var everytime u ReDim the array...
Ubound(array) returns only the first dimesnsion (which u cant redim... u can only redim the 2nd dimension)
How do i dim arrays with Variables?
Dim X(1 to 11, 1 to 5) as variant...
This works perfectly...
Now if i try
Dim X(1 to i, 1 to j) as variant
where i and j are variables whose values are obtained once the program starts execution.How do i dimension such arrays?
Any help will be appreciated...
Is there any way to determine the number of dimensions of an array ?
What would be the most efficient way of getting the number of
dimensions in an array?
I've thought about using UBound in a loop and carrying on till I
get an error (and thus loop counter - 1 = # of dimensions), but
that seems awfully inefficient
I'm used to using a basic script which allows me to use a function called ArrayDims() to determine the dimensions of an array. This is very helpful for routines that operate on dynamic arrays, because if i know that the array has been dimensioned i can begin stepping through it to do whatever needs to be done. If it hasn't been dimensioned, then i can skip that step. Is there any way in standard VB to check this? I keep having my code crash because the UBound returns an error if the array has not been dimensioned.
Specifically, this is what i'm talking about. I load values into an array from a database, redimensioning the array as needed. If the table i'm reading from has no records, however, the array stays undimensioned. Next i perform some sort of operation on the items i just read in by stepping through the array (for i = 0 to UBound). In the VB script i've been using, i would simply check arraydims first, and if the array had values i would perform the operation. In VB i can't use that command though, so the code crashes!
Any help would be appreciated.
What If My Array Does Not Have Dimensions?
It's Friday, I can hear my train coming, and I can't think straight......If I have the following code:
Code: FolderNames = Check4DataFolders(vFolder)
If UBound(FolderNames) > 1 Then
I get a "Runtime Error 9: Subscript out of range" if the array does not have dimensions. How do I do the check without raising an error and without using On Error?
+--VB Dot Net
+-- Navman GPS Forums @ http://forum.jdmils.com
Wow just got home from vacation in Florida so back to work time
Anyways, heres my problem...this could be a simple thing but i just dont know how to do it.
I have a data type set as:
Public Type ZipInfo
City() As String * 30
State() As String * 2
First of all just while i was typing that Type declaration i was thinking to ask if I can not define the length of the strings?
So anyways, while i use that type in my code im wondering how to tell if the array is dimensioned already? Is the only way of doing this within error catching in the function?
Also, I'm tryin to not have to set the dimension in the Type declaration. Thanks for your help in advance.
[--HOPE THIS HELPED--]
Shocked With Array Dimensions
I use option base 1 in general section but when i declare a variable (without variable type) and use split function the array begins with 0 index ... , and if I declare a variable with variable type then a redim function with this array the result is an index 1 at the first element ...
What am i doing wrongly ???
This is my code :
option base 1
Private Sub Form_Load()
Dim CADENA As String
Dim cantfrases As Single
Open "serie11.TXT" For Input As #1 'opens a txt file
CADENA = Input(LOF(1), #1)
afrasesinterm = Split(CADENA, "$", -1, 1) 'split sentences
'first index in this array its 0, its type is not declared
'if i declare the type of this variable i get an error of
'variable type , so i leave this variable undeclared
cantfrases = UBound(afrases)
ReDim aexer(cantfrases) ' this is a variable, declared as an array
' the first index of this array is 1
Find Array's Dimensions
Does anyone know how to get the number of dimensions an array has? looked it up in msdn and there is a JScript function called dimension that returns the number of dimensions in a vbArray but doesnt seem to be anything in vb.
Im trying to make a sub that copys one array into another assuming the destination array is bigger than the source, so if A(1 to 5) and B(1 to 3)
then copyarray A,B copys B into A's 1 to 3 and leaves 4 and five empty.
I was hoping there is some way I can just write one sub for any # of dimensions instead of writing one for 1-D arrays, one for 2-D, etc...
2 Dimensions Variant Array
I've got this problem, I want to pass a 2 dimensions array of Variant to a sub but when I do so, it only keeps one dimension...
Here's the code, see what's wrong:
Private Sub CommandButton1_Click()
Dim TempBaseArray() As Variant
Dim TempGMWBArray() As Variant
Dim matBaseExcelOutput() As Variant
Dim matGMWBExcelOutput() As Variant
Dim i As Integer
Dim j As Integer
ReDim matBaseExcelOutput(30, 30)
ReDim matGMWBExcelOutput(30, 30)
For i = 1 To 30
For j = 1 To 30
matBaseExcelOutput(i, j) = i * j + 7
matGMWBExcelOutput(i, j) = i * j + 7
TempBaseArray = CopyArray(matBaseExcelOutput) 'This array has 2 dimensions
TempGMWBArray = CopyArray(matGMWBExcelOutput)
ReDim matBaseExcelOutput(31, 30)
ReDim matGMWBExcelOutput(31, 30)
matBaseExcelOutput = TempBaseArray
matGMWBExcelOutput = TempGMWBArray
Public Function CopyArray(arr() As Variant) As Variant() 'When it gets here, only one dimension remains
Dim i, j As Integer
Dim TempBaseArray() As Variant
For i = 0 To UBound(matBaseExcelOutput, 1)
For j = 1 To UBound(matBaseExcelOutput, 2)
TempBaseArray(i, j) = matBaseExcelOutput(i, j)
CopyArray = TempBaseArray
Best Way To Determine # Of Array Dimensions?
Just curious if there is a way to programmatically determine how many dimensions a dynamic array has. eg:
Sub Test() Dim varArray As Variant Dim lngArray() As Long Debug.Print ArrayDimensions(varArray) & "," & ArrayDimensions(lngArray) ReDim varArray(9) ReDim lngArray(9) Debug.Print ArrayDimensions(varArray) & "," & ArrayDimensions(lngArray) ReDim varArray(9,9) ReDim lngArray(9,9) Debug.Print ArrayDimensions(varArray) & "," & ArrayDimensions(lngArray) Erase varArray, lngArray Debug.Print ArrayDimensions(varArray) & "," & ArrayDimensions(lngArray)End Sub Function ArrayDimensions(pvarArray As Variant) As Long ' ???End Function
Which would ideally look like this in the debug window:
Dynamically Add Dimensions To Array
I have a function which filters a recordset for a value (partNum) and the number of times that value occurs. then gets the next value and starts again.
now , to pass the results I have been using a global array and having the function return the size of the array. so that the value filtered is stored into the array where the array index is equal to the number of times the value occured. pretty neat I thought.....
but what happens when two differnt values occur the same number of times?
then the last value gets overwritten as the second one is written to the same array position.
So I thought maybe when the results are found check to see if that array position is empty, if not create a new dimension and use the same position on the new dimension. (then to check it I could simply cycle throught the positions by dimension)
but I dont think dimensions can be dynamically added using ReDim, anyone know of another way?
I was also thinking of maybe just dynamically creating a new a1D array and having the array names numbered, but then we end up with a lot of seperate arrays and a messy way of checking wether or not arrays exist or not. (like here)
help or suggestions much appreciated in advance, muchos gracias
Array - Fixed - 3 Dimensions- VB6
I need to declare, then populate 3-dimensional fixed array, data from table of of 33 records, 3 columns.
Public myArray(32,32,32) as string (assuming zero based array)
I need now to populate all three columns for all records.
How do I populate this? Cannot find in VB help.
How To Find The Dimensions Of An Array!
Here is some source - the comments explain everything! Cut and paste into a form and you`ll see what I mean!
Option Explicit ' My ParamArray hell!'' Sometimes you want to have a function accept an unknown number of parameters, so you use' the ParamArray keyword. But if you pass an array of strings to a function which accepts' a ParamArray, and then that function then calls another function which also accepts a' ParamArray (and so on) then the innermost function will be receiving a multidimensional' array, where the number of dimensions is unknown, and i`m not sure how you find out.' I wrote the function GetLastArrayColumn to take one of these `unknown dimensional` arrays' and return a 1d array containing the contents of the last `column` of the array.'' There must be a better way which doesnt require:'' 1) so many variables' 2) ugly `on error goto`/ infinite loops' and maybe even' 3) needing to write my own function in the first place?'' If so I`d love to know!'' [email]Pallex@altavista.co.uk[/email] Private Sub Form_Load() Dim mystring As String mystring = funcy1("hello", "world", "this", "is", "an", "array", "of", "strings") MsgBox mystring End End Sub Private Function funcy1(ParamArray blah()) As StringDim i As Integer funcy1 = funcy2(blah) End Function Private Function funcy2(ParamArray blah()) As StringDim i As Integer funcy2 = funcy3(blah) End Function Private Function funcy3(ParamArray blah()) As StringDim i As IntegerDim NiceArray As VariantDim sRetval As String NiceArray = GetLastArrayColumn(blah) For i = 0 To UBound(NiceArray) sRetval = sRetval & NiceArray(i) & " " Next i funcy3 = sRetval End Function Private Function GetLastArrayColumn(ParamArray MyArray()) As VariantDim vNew As VariantDim vOld As VariantDim vOlder As Variant vNew = MyArray vOld = Null vOlder = Null On Error GoTo Done: Do vOlder = vOld vOld = vNew vNew = vNew(0) Loop Done: On Error GoTo 0 GetLastArrayColumn = vOlder End Function
Easy - Array Dimensions
i am just wondering how vb sets up an array, if i want to set up and array like the following, with 2 rows and 4 columns
1 1 1 1
1 1 1 1
do i set it up as Dim Matrix(1 To 2, 1 To 4) As Double
or as Dim Matrix(1 To 4, 1 To 2) As Double
Number Of Dimensions In An Array?
So, Ubound and Lbound give me the upper and lower boundaries of an array, but in a multidimensional array, that doesn't help a great deal.
How can I determine the number of dimensions in my array?
Determine # Dimensions In An Array
How can I determine the # of dimensions in an array?
For example: A(x) has 1 dimension, A(x,x) has 2 dimensions, etc...
I figure there has to be a way...
Is There A Faster Way To Copy Array Dimensions?
I have a dynamic 3D single array TNK(t, 51, 700). Is there a way to set the TNK(t, i, j) values equal to the TNK(t-1, i, j) values that is faster than a nested loop:
for i = 0 to 51
for j = 0 to 700
TNK(t, i, j) = TNK(t-1, i, j)
This occurs for each t (with some processing between), which can reach well over 400 so it can bog down fast. Thanks in advance for any suggestions.
Direct Array Copy When Dimensions Are Different
Now I have a 3D static array A(2,199,199) and a 1D dynamic array B(). What I want to do is some sort of direct assignment as:
B = A(0, , )
-which of course is wrong- so as to assign to B the first of the three 2D subarrays of A. Or maybe there is some other means to do this without using loops. Perhaps some direct memory copy method?
Create Array With Variable Dimensions
Is it possible to create a multidimensional array at runtime?
I know you can do it if you know the number of dimensions you want
i.e. for a 2d array you can do either of these
Dim Test() As IntegerReDim Test(2, 4) Dim Test2(2, 4) As Integer
But I wont know how many dimensions I will need until runtime.
e.g. I read a string that says 1, 4, 5, 6 and it means create a 4 dimensional array, first dimension with 1 element second with 4, 3rd with 5 elements and 4th with 6.
Or I get a different string e.g. 3, 7, 3, 9, 2, 5 and it means create a 6 dimensional array with 3 elements in the 1st dimension, 7 in the 2nd etc etc
Perhaps this could be done via a recursive function that redimmed arrays?
Determine The Number Of Dimensions Of An Array
Can anyone tell me if there is a function in VB to determine the number of dimensions in an array? I found an article on the web saying that there was no such function for VBA (no mention of VB), and it suggested using the ubound function and error catching to determine the number of dimensions. Surely there's a better way than that.
Any help would be appreciated.
'ReDim' Cannot Change The Number Of Dimensions Of An Array.
THIS IS MY CODE AND IM HAVING UPDATE VB 6.0 VB .NET
'ReDim' cannot change the number of dimensions of an array.
HELP PLEASE WHAT'S MISSING
Private Sub cmdStart_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdStart.Click
Dim aryCount() As Integer
Dim HiCard As Integer
Dim Decks As Integer
Select Case MachineType
Case 12, 15, 17 : HiCard = 6 : Decks = 0 : Devices = 2 : CardLength = 1 'craps
Case Else : Err.Raise(vbObjectError + 1086, , "" & MachineType)
If Devices = 0 Then
ReDim aryCount(HiCard + 4)
ReDim aryCount(HiCard, Devices) <<<<<<<THIS IS THE ARRAY IM having the problem with>>>>>>>>>>
THIS IS THE ERROR: I GET
'ReDim' cannot change the number of dimensions of an array.
Array Of Arrays - Detrmining The Second Dimensions Size
Does any one know of a method to count the second dimesion of an 'Array of Arrays' given that its created at run time and each 2nd dimension is different; I have got some functions that determine array sizes etc but dont work with an 'Array of Arrays'. This is brief outline of what im up to
1. The function I have written returns one array - a variant array storing longs
2. This array may have 1-200 sub arrays inside it; determined at run time
3. Each sub array is of a different size, which gives a different second dimension for each element in the array.
4. When the array is returned to the caling function, I need to no the size of the second dimension or in other words the size of the array contained within it, so I can successfully do operations on that data
array(1)(X) contains 5 long integer elements -> I need something that says its 5 elements long, without popping
array(2)(X) contains 3 long integer elements -> I need something that says its 3 elements long, without popping
Bearin in mind that its one array that has many arrays inside it
Any suggestions are very welcome at this stage!!!
Can You Specify The Number Of Dimensions When Dimming A Variable Size Array?
I know you can do
dim A() as double
I'm converting a project to vb.net 2008 and the conversion wizard pretty much leaves that code as it is. The problem is in .net you have to specify the number of dimensions in the dim statement, so this causes an error.
I have so many arrays that the .net has reached its maximum number of errors.
If I manually change all these dim statements after conversion (could take hours), I'll discover new errors which might have been better fixed before conversion.
So I want to know if I can write this code in a way that will convert correctly.
Looping Through Each Element In An Array With A Variable Number Of Dimensions
I am trying to write functions that are general enough to handle arrays of any size and dimension. Lets say I know the dimension size, and I've read somewhere that I should use a recursive for-loop function to loop through each dimension, but how will I access the elements of the array? The only way I know of is:
element = array( i , j , k , ... , N )
The argument of the array parameters doesn't accept anything but numbers so I can't generate a line of text that adds a comma and another number after each dimension iteration and then just plug in the string. It gives me wrong data type error. Maybe this is the wrong way to go about it. Thanks in advance.
Edited by - jtung1027 on 9/5/2007 10:35:26 AM
Dimensions Of A DC
I need to get the height and width of a DC. The method I tryed doesn't seem to work. Can someone tell me what I did wrong?
Private Type BITMAP
bmType As Long
bmWidth As Long
bmHeight As Long
bmWidthBytes As Long
bmPlanes As Integer
bmBitsPixel As Integer
bmBits As Long
Dim tempbmp As Long
Dim tempinfo As BITMAP
Dim width&, height&
SelectObject hDC, tempbmp
GetObject tempbmp, Len(tempinfo), tempinfo
height = tempinfo.bmHeight
width = tempinfo.bmWidth
if is possible to make a tow dimensional aray with labels???? How???
How Many Dimensions?
Is there a way to find out how many dimensions a given array has? And the total ammount of elements in the array? Please help me.
Dimensions With Flash.ocx
I'm not sure if this topic has been touched upon, but here goes.
I've used the Flash.ocx control to create a flash player that has the option of staying on top of all windows (I prefer to watch my flash movies and work at the same time ).
What I want to do now is resize the flash control to match the size of the movie playing in it; is there a way of finding out the height and width of a flash movie through the Flash.ocx control?
Thanks for your help!
Get Image Dimensions
hello i have lots of images and i wish to get image dimensions using api, i am just wondering if any of you know some api code which will let me get the dimensions (width x height) of an image (such as .jpg, .gif, .bmp, .png, tiff)
i use a third party control to support some formats, but in order to get dimensions i must load the image into the picture object, and since i have lots of images i am going through i wish to speed up this process and if possible check image dimensions through api. Hopefully one of you guys know some code which lets me check image dimensions without loading the picture into some object.
thanks for your time and i look forward to your replies.
MDI Form And Dimensions
I have to recreate a program another person worked on. In this program they have a form with a series of buttons along the left side that take you to different sections in the main window.
I think the easiest way to do this would be to have an mdi form that contains the main buttons, then each button will show a seperate child form in the main window. I have already made a test program that does this, but I have a few questions.
1. I am currently using a tool bar along the left side to contain the buttons that will take the user to different pages. I cannot resize the tool bar, it is always set to 630 wide. Is there a way to resize this, or is there another control I can put in an MDI form that will let me add buttos or images to it?
2. Is there a way to turn off the user's ability to resize the MDI form? I can do it for all other forms, but I don't see any options to disable it for the MDI form.
3. For the child form I added a form, made it an MDI child and removed the border. I then place it at 0 left, and 0 top in the MDI form so it is stuck in the upper left corner next to the tool bar. I am trying to get the child form to be the exact dimensions of the inside of the MDI form, so there are no scroll bars and no gaps. I have tried everything I can think of and do not understand the discrepancy.
-I tried making the form the same dimensions as the MDI form, but it overhangs on the bottom and the right.
-I tried making it the same dimensions as the MDI form, but subtracted out the width of the tool bar, but it still overhangs. I even tried subtracting more for the scroll bars, but no luck.
-I finally put some text boxes on the child form and a button that would fill them with the current form height/width and the MDI form height/width. I then resized the MDI form until the child form fit perfectly inside it and clicked the button. These are the numbers it shows: (on this trial)
Child Height: 8130
Child Width: 9090
MDI Height: 8595
MDi Width: 9900
So the child needs to be 465 units skinnier than the MDI form and 810 units shorter. Can someone explain to me why these numbers are what they are?
The problem is that difference between the child and MDI heights and widths changes each time if I resize the child form and rerun the program.
Any help would be appreciated or a pointer to a web site that explains MDI forms a little better. Thanks.
Quick ? On Dimensions
Do the rectangle and description dimensions always have to match? Everytime I change them they dont display the Bitmap i load.
ddsdBackground.lFlags = DDSD_CAPS
ddsdBackground.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
ddsdBackground.lWidth = 200
ddsdBackground.lHeight = 400
Set ddBackGround = ddraw.CreateSurfaceFromFile(App.Path & "3771.bmp", ddsdBackground)
ddBackGround.SetColorKey DDCKEY_SRCBLT, Key
Key.low = 0
Key.high = 0
rBackground.Bottom = ddsdBackground.lHeight
rBackground.Right = ddsdBackground.lWidth
I changed rbackground(a rect) to a different value and it wont display image? Whats the reason for it?
ok, can someone please explain to me exactly how to retrieve the dimensions of a surface??
Find Dimensions Of HDC?
I'm not exactly sure how to word this question, so I'll just tell you where I'm at and where I want to be.
I've created a DC, put a bitmap in it using loadimage, and therefore given the DC dimensions.
I want to use kind of like this:
BitBlt hdcLand, 0, 0, hdcLandConstant.Width, hdcLandConstant.Height, hdcLandConstant, 0, 0, vbSrcCopy
But I don't know how to obtain the width and height of the hDC (or bitmap rather) that I'm using.
Is there an API that would return the size of a bitmap or something, or the dimensions of an hDC?
Is there any way I can find out how big a jpeg is (in code). I want to be able to resize a picture to fit in a picture box on the fly and keep the same aspect ratio. I have found a free utility that will resize, but here is the problem:
Let's say the the picture box is 400 pixels wide x 600 pixels tall. I can tell it to resize the image to a width of 400, and it will keep the aspect ratio the same, but it the picture is really tall, it will not all fit in the box, and I would need ot resize it for 600 height and whatever width (less than 400) it turns out to be.
Unless there is another way to do this
Does anyone know the dimensions of a MsgBox, ie. The height and width...?
Thanks in advance,
Know Matrix Dimensions
I'm using a matrix but this starts without dimension. but in some SUB I need know if my matrix have dimension, How I can know this, I'm using UBOUND function but if the matrix is not dimensioned yet this function return error.
Window Dimensions ?
i am a new member here
i wanted to ask how exactly the values of the window dimensions are related to the screen resolution
for ex: i have a window with height = 4905 and width = 6375
how are these values related to screen resolution or what units are they expressed in
also can you guys tell me how can i reset screen resolution automatically when my app starts to say 800 x 600 and reset it back to original resolution when my app is closed
in the meantime my app must be in fullscreen for ex: like a game
thanks anyway for making such a great forum
have a nice day
Dimensions Of StdPicture?
Does anyone know how to get the dimensions (in pixels) of a picture stored in memory (StdPicture)?
Dim picTest As StdPicture Set picTest = LoadPicture("C:Some_file.bmp") 'Get dimensions?? :confused:
Dimensions Of An Object
I am trying to write a function that mimics the Anchor and Dock properties of Objects in VB.NET. So I need to figure out the positions of the Left Side, Right Side, Top Side and Bottom Side of an object. Additionally, I what to find out at what pixel the Left_Top, Right_Top, Left_Bottom and Right_Bottom are at. Here is what I came up with so far:
Left = Control.Left
Right = Control.Left + Control.Width
Top = Control.Top
Bottom = Control.Top + Control.Height
Left_Top = Control.Left + Control.Top
Left_Bottom = Control.Left + Control.Top + Control.Height
Right_Top = Control.Left + Control.Top + Control.Width
Right_Bottom = Control.Left + Control.Top + Control.Width + Control.Height
How are my calculations?
Get Browser Dimensions!
Often it happens that when a button is clicked in a web page in a browser, a new browser window of smaller (or maybe larger) dimension opens up (for e.g. when the Manage Attachments button is clicked in the page where users post new threads in this forum, a smaller window opens up).
Now using the WebBrowser control, is there any way by which VB can get the dimension of such browser windows before actually opening them? Or in other words, can VB get the width & the height of the web page (not the web browser) just before opening the web page in a new window? Maybe using the BeforeNavigate2 or WindowSetWidth or WindowSetHeight event functions of the WebBrowser control or some other function?
Dimensions Of A Png File
Does anyone know how to get the dimension of a png file? Im looking to read the dimensions and then adjust my form to those dimensions. any help is appreciated
Given a MSFlexGrid and a number N of columns, what is the formula for calculating the column width (same for all columns) so that they all fit i.e. no vertical slidebar pops up?
MSFlexGrid.ColWidth(i) = MSFlexGrid.Width / N
just doesn't work.
hi... how do we declare a multi dimensional (2 dimensional) array in vb... i havent seen any yet... i havent tried it before too. can someone help me? thanks! thanks alot