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!

define array size in vbscript as a variable

Status
Not open for further replies.

avivit

Technical User
Jul 5, 2000
456
IL
I tried to use in asp:
Dim x
x=4
Dim myArray(x)

I get error when I use a variable as the array size (OF COURSE I have no problem when setting a number instaed of the variaBle).

Isn't it a possible thing to do?
Thanks
 
It is also "Good Policy" to define the array with Dim first.
Either
Dim MyArray ' Variant to contain array
Or
Dim MyArray() ' Array of Variants
ReDim MyArray(X) ' Actually allocate it.
....
ReDim Preserve MyArray(X+10) ' Resize saving previous
ReDim Preserve MyArray(X-10) ' Resize dropping 10

Arrays are 0 based so if you want 10 items and you are storing in element 0 then allocate with Ybound of 9.
(9) 0 through 9.
Dim X ' Count of items

If X > 0 then
ReDim Myarray(X-1)
End if

I usually start storing in element 1 and leave element 0 empty so I use X rather than X-1. Compare Code (Text)
Generate Sort in VB or VBScript
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top