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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reDim VBScript Array

Status
Not open for further replies.
Jul 14, 2003
116
CA
I'm having some trouble with a redefining the size of a 2 dimensional array. I keep getting the following error:

Microsoft VBScript runtime error '800a0009'

Here is an example of my code:

dim contArr() 'dynamic array
reDim PRESERVE contArr(0,1) 'set initial size of the array
contArr(0,0) = "default_val"
contArr(0,1) = "default_val"

for a=1 to 10

arrLng = ubound(contArr,1) + 1 'upper bound of the first dimension + 1
reDim PRESERVE contArr(arrLng,1) 'THIS IS WHERE THE ERROR IS POINTING
contArr(arrLng,0) = "some_val"
contArr(arrLng,1) = "some_val"

next
 
thats because the subscript will be out of range...i dont know what you are trying to do here...but just do this and see...what happens...

Code:
dim contArr() 'dynamic array
reDim PRESERVE contArr(0,1) 'set initial size of the array
contArr(0,0) = "default_val"
contArr(0,1) = "default_val"

for a=1 to 10

  arrLng = ubound(contArr,1) 
  reDim PRESERVE contArr(arrLng,1) 
  contArr(arrLng,0) = "some_val"
  contArr(arrLng,1) = "some_val"
response.write contArr(arrLng,0) & "<br>"
next

-DNG
 
Yes. Chris is correct.

It is important to keep in mind that Redim Preserve
only supports redimensioning the "right" most element
of any multi-dimensional array.


-DNG
 
Hey Guys,

Thanks for your help. I was able to resolve this problem by creating a temp array 1 position bigger than the initial array and then used reDim (without preserve) to make the original array bigger. Finally I copied the data from the temp array to the originally array again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top