Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

array layout and getrows() 1

Status
Not open for further replies.

chris5g

Programmer
Aug 21, 2001
48
US
I'm a little confused about the layout of an array returned by getrows().

It is my understanding that when you create a multidimensional array, myArray(10,3) the first number, 10, is the rows and the second, 3, is the columns.

However, when I pulled the data with getrows, this seems to be reversed. my variable numCols = UBound(myArray,1) + 1 is correct even though the columns should be the second dimension and not the first.

Is it reversed or am i just totally confused?
 
I'll try to explain this.

When you create the array myArray(10, 3), you specify rows then columns.

So when you put UBound(myArray, 1) + 1, we see how many of the first element in the array is (denoted by the , 1). The first "element" in the array is a 1 dimension array with a size of 11.

In this case, there happens to be 4 "elements" that contain 11 rows each. This is the same as saying how many columns there are.


[monkey][snake] <.
 
What I want to know is why do i use the first dimension of my array to get the number of columns when using the getrows() method instead of the the 2nd as in numCols = UBound(myArray,2) + 1?

Is the myArray(rows,cols) reversed when using the getrows() method as in myArray(cols,rows)
 
am i wrong?

Not saying you are cLFlaVA. You just stated what it does and not how it does it.

I tried to explain why it happens the way it does. Apparently, I didn't do a good job.

cheers [cheers]


[monkey][snake] <.
 
There is no rule the says the first index of an array is the row and the second index is a column. This was common practice with array-like matrix variable sin some languages, but there is no hard and fast rule defined for naming array indexes. For example, I could use an array to define water temperature values in a cube of water using indexes longitude, latitude, and depth.

That said, yes, GetRows returns an array that is (column,row) so to get the row count you need to UBound(myArray,1) and to get the row count you need to UBound(myArray,2).

While I agree it would be more comfortable the other way around, after you get used to it you only get it backwards occasionally.

-T

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top