How/Why does this work(array ?)

# Thread: How/Why does this work(array ?)

1. Senior Member
Join Date
Dec 1969
Posts
339

## How/Why does this work(array ?)

so I am confused how getrows sets up an array <BR><BR>if I did this<BR><BR>&#060;%<BR>SQL="SELECT AID,TITLE,SHOW,ADATE from ANNOUNCEMENTS order by AID DESC"<BR>set rs=conn.execute(SQL)<BR><BR> anns=rs.getrows()<BR>for i=0 to ubound(anns,2)<BR>response.write anns(0,i)&"<BR>"<BR>response.write anns(1,i)&"<BR>"<BR>response.write anns(2,i)&"<BR>"<BR>next<BR><BR>i would get something like this as a result:<BR>aidvalue<BR>titlevalue<BR>showvalue<BR> adatevalue<BR><BR>why is the ubound of anns 2 and not 3 if the output has 4 results.. <BR>I don&#039;t get it and I&#039;d like to understand it. <BR><BR>btw: been to the FAQ section, didn&#039;t quite see what I was looking for. <BR><BR>can anyone have mercy and patience and explain to me how the ubound works in getrows. <BR><BR>TIA<BR>

2. Senior Member
Join Date
Dec 1969
Location
Los Angeles, CA
Posts
21,192

## Weeeel

cause the 2 is for the DIMENTION of the array<BR><BR><BR>so you are basically doing the ubound of the SECOND dimention of the array<BR><BR>the first being for the columns and the second for the rows<BR><BR>

3. Senior Member
Join Date
Dec 1969
Posts
339

## RE: Weeeel

just I understand you correctly, you&#039;re saying that the second dimension is the number of rows?<BR><BR>but if there were 10 records in the database, that would be 10 rows.. :confused:

4. Senior Member
Join Date
Dec 1969
Location
Los Angeles, CA
Posts
21,192

## What?

&#062;but if there were 10 records in the database, that would be 10 <BR>&#062;rows<BR>yes<BR><BR>10 ELEMENTS in the array <BR><BR>maybe you just need to do some R&D on how arrays work<BR><BR><BR>

5. Senior Member
Join Date
Dec 1969
Posts
339

## RE: What?

perhaps.. but that is why am here.. :)<BR>Like I said, I went through EVERY ARRAY faq today and I&#039;m just in need of clarification. <BR><BR>Guess I&#039;ll head back and read it all again.

6. Senior Member
Join Date
Dec 1969
Location
Los Angeles, CA
Posts
21,192

## Dude

i have no idea what you claim you do not understand<BR><BR><BR>are you saking why you dont do ubound(array, 10)??<BR><BR><BR>

7. Senior Member
Join Date
Dec 1969
Posts
339

## RE: Dude

yes.. <BR><BR>can I have my dunce hat now? :)<BR><BR>Thank you for being patient with me.

8. Senior Member
Join Date
Dec 1969
Location
Los Angeles, CA
Posts
21,192

## ok lets try this again

your array will look like this<BR><BR>Column1&nbsp;&nbsp;Column2&nbsp;&nbsp; Column3<BR>RowData1&nbsp;&nbsp;&nbsp;RowData2&nbsp ;&nbsp;&nbsp;RowData3<BR>RowData1&nbsp;&nbsp;&nbsp ;RowData2&nbsp;&nbsp;&nbsp;RowData3<BR>RowData1&nb sp;&nbsp;&nbsp;RowData2&nbsp;&nbsp;&nbsp;RowData3< BR>RowData1&nbsp;&nbsp;&nbsp;RowData2&nbsp;&nbsp;& nbsp;RowData3<BR>RowData1&nbsp;&nbsp;&nbsp;RowData 2&nbsp;&nbsp;&nbsp;RowData3<BR><BR><BR>so your first dimention is 3 columns and your second dimention is 5....so when get the ubound of the second dim you get the records as in the rows<BR><BR><BR>make more sense now??<BR><BR>

9. Senior Member
Join Date
Dec 1969
Posts
339

## That is how I understood it

so looking back at my example: <BR>I select 4 columns which is my FIRST dimension right? and truly my SECOND dimension of ROWS is unknown because it&#039;s updated periodically. So if I had 4 rows of records in the database then my ubound should not be 2.. so what am i missing?<BR>

10. Senior Member
Join Date
Dec 1969
Posts
96,118

## One more time...

The value of the second argument to UBOUND is telling UBOUND *which* dimension of the array you want the upper bound *OF*.<BR><BR>Let&#039;s demo this by hardcoding some arrays:<BR><BR>&#060;%<BR>Dim ar1( 13 )<BR>Response.Write UBound( ar1, 1 ) &#039; will display 13<BR>Response.Write UBound( ar1, 2 ) &#039; *ERROR* array has only one dimension!<BR><BR>Dim ar2( 4, 93 )<BR>Response.Write UBound( ar2, 1 ) &#039; will display 4<BR>Response.Write UBound( ar2, 2 ) &#039; will display 93<BR>Response.Write UBound( ar2, 3 ) &#039; *ERROR* array has only two dimensions!<BR><BR>Dim ar3( 3, 7, 5 )<BR>Response.Write UBound( ar3, 1 ) &#039; will display 3<BR>Response.Write UBound( ar3, 2 ) &#039; will display 7<BR>Response.Write UBound( ar3, 3 ) &#039; will display 5<BR><BR>%&#062;<BR><BR>OKAY? The *count* of the *dimensions* has *NOTHING AT ALL* to do with how may elements are *IN* each dimension!<BR><BR>In order for you to do<BR>&#060;%<BR>Response.Write UBound( someArray, 10 ) <BR>%&#062;<BR>You would have had do have put *10 DIMENSIONS* into your DIM statement:<BR>&#060;%<BR>Dim someArray( 2, 3, 2, 5, 2, 1, 3, 2, 5, 8 )<BR>%&#062;<BR>And that array would have around 800,000 total elements, as dimensioned. And if you can figure out a use for a 10-dimensional array outside of some kinds of nuclear physics, I want to hear about it.<BR><BR>Heck, for that matter, I want to see a *GOOD* reason for a 3-dimensional array, at least in VBScript code.<BR><BR>A 2-dimensional one makes sense: rows and columns. What would the third dimension mean to you?<BR><BR><BR><BR>The <BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•