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

Redim 2D Array using PRESERVE 1

Status
Not open for further replies.

JemimaChadwick

Programmer
May 8, 2001
2
IN
I have a combo from which i select values...as i select, i want the HTML table beneath to include the selection...I want all this manipulation done in the client-end itself. I am able to manage the table part of it. Now on submitting the form i have to write the selected items into the Database table. To do this, i use an array and redim the size with the PRESERVE keyword each time the select button is clicked. But the values don't get preserved in the Array. Wat cld be the prblm? Or how else can i achieve this task if i dont use Arrays?
PS: All manipulations have to done as client-side scripts using VBScript only.
-------------------
CODE
-------------------
count=0
if count = 0 then
redim arrStore(0,3)
else
redim Preserve arrStore(count,3)
end if
...
count=count+1
--------------END OF CODE----------------
- Jemima.
 
At the start of your code you have set count=0. Then you increment count at the end. However, this increment doesn;t matter if you initialise it to zero each time. Mise Le Meas,

Mighty :)
 
Oops! The count ought to come outside the function call n the processin is done inside the function. Well, i hope i have conveyed the prob..although i messed up in the code extracts!
- Jemima.
 
Does redim work on multidimensional arrays? I was under the impression that only the last dimension could be redimmed.

I hope my memory is wrong.

Can you use a recordset instead?

Parke
 
From devguru.com --


The ReDim statement allows you to formally declare, and to later redeclare as many times as you need, the size (and hence the memory space allocation) for a dynamic array that was originally declared using either a Dim, Private or Public statement.

The first time you use ReDim to declare an array, you can create either a single or a multiple dimension array. However, after you have set the number of the dimensions, you cannot later go back and change the number of the dimensions. Also, once you have created a multi-dimension array, you can only redeclare the size of the last element.

If you make the array bigger, you can use the keyword Preserve to protect all of the existing elements. If you make the array smaller, you will lose part of the array elements even if you use Preserve. Do not use Preserve the first time that you ReDim an array since it will prohibit setting multiple dimensions.

In this example, we declare myarray() to have a single dimensions and then resize the element. When we resize from 999 down to 9, we lose the data in the other 990 elements.

Code:
<% Dim myarray() %>
<% ReDim myarray(5) %>
<% ReDim Preserve myarray(999) %>
<% ReDim Preserve myarray(9) %>

In this example, we declare myarray() to have three dimensions and then resize the last element. When we resize the last element from 999 down to 9, we lose the data in the other 990 elements.

Code:
<% Dim myarray() %>
<% ReDim myarray(20, 10, 99) %>
<% ReDim Preserve myarray(20, 10, 999) %>
<% ReDim Preserve myarray(20, 10, 9) %>


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top