Quick Question On Arrays

# Thread: Quick Question On Arrays

1. Member
Join Date
Dec 1969
Posts
68

## Quick Question On Arrays

Hi! Just a quick question of an array. Let&#039;s say this is my array.<BR><BR>array(0)=4<BR>array(1)=a<BR>array(2) =b<BR>array(3)=c<BR>array(4)=d<BR><BR>Now, what would UBound.array equal? Would it be 4 because that is the final position, or would it be 5 because 5 is the actual length? If I did a for statement and said that array(0) was the limit, would it get through all the parts? And if I said Redim Preserve array(array(0)+1) would it get one more spot as position 5?

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

## UBound(myarray)

Not UBound.array -- it&#039;s not a method on an object, it&#039;s a simple VBScript function.<BR><BR>Not UBound( array ) -- "array" is a reserved word, so you can&#039;t use it as a variable name.<BR><BR>Anyway...UBound( anyArray ) give the maximum *element number* for that array, *not* the number-of-elements.<BR><BR>This comes because, in Visual Basic, an array does not *necessarily* have a LBound of zero, so it made a lot more sense to have LBound and UBound return element numbers, so that the operated independently.<BR><BR>In VBS, LBound( anyArray ) will *always* be zero, so maybe VBS could have used Size( anyArray ) or Length( anyArray ) in the fashion of Java and JavaScript, but the VB heritage came through.<BR><BR>**************<BR><BR>&#062; If I did a for statement and said that array(0) was the limit, <BR>&#062; would it get through all the parts? <BR><BR>Why in the world would you *ever* do that????<BR><BR>For ix = 0 To UBound( theArray ) <BR><BR>Nothing else makes much sense.<BR><BR>******************<BR><BR>&#062; And if I said Redim Preserve array(array(0)+1) <BR>&#062; would it get one more spot as position 5?<BR><BR>Why would you ever do *that*???<BR><BR>Why not: <BR><BR>ReDim Preserve myArray( UBound( myArray ) + 1 )<BR><BR>????<BR><BR>But see my FAQ on session arrays [ASPFAQs, category ARRAYS] to see why you really do *not* want to just increase the size by one! There are *much* better techniques available.<BR><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
•