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

Array GetRows ReDim Preserve 3

Status
Not open for further replies.

Deadline

Programmer
Feb 28, 2001
367
US
Hi,

My problem in brief :

I can assign
Code:
rs.GetRows
to an array variable only if I declare the array variable like this.

Code:
Dim arrRecords

If I declare the variable as below, assigning
Code:
rs.GetRows
to arrRecords won't work.

Code:
Dim arrRecords()

On the other hand, if I need to use
Code:
ReDim Preserve arrRecords(100,100)
the above points must be vice versa.


My question is, what if I need to 'ReDim Preserve' after I assign the result of getRows function to the same array ? Is it allowed ? If not what could be the alternative ?

Please help.


Thank you,
RR.
__________________________________
The best is yet to come.
 
After the GetRows, the variable is simply an array, so should be able to use ReDim Preserve OK.
codestorm
Fire bad. Tree pretty. - Buffy
Hey, I'm operating on a limited mental budget here.
<insert witticism here>
 
But I found out that if you want to use ReDim our variable must have been declared an array(Dim myArray() instead of Dim myArray ). Otherwise it says 'Type Mismatch' or 'Subscript Out of Range'.

Can you tell me if I am right or wrong ?





Thank you,
RR.
__________________________________
The best is yet to come.
 
Hi,

As far as I know you should be able to declare an array as:
dim MyArray

The subscript out of range can occur if you want to reassign the value of the any dimension of a multiple dimension array other than the last one.

So if the result of your GetRows call is an array with 33 columns and 100 records: Myarray(32,99) and you try something like:

redim preserve MyArray(35, 200), it will give you a subscript out of range error. On the other hand, redimming you array like this:

redim preserve MyArray(Ubound(MyArray,1), 200)
or
redim preserve MyArray(32, 200)

should be OK.

Jordi Reineman
 
Excerpt from VBScript.chm ..

If you use the Preserve keyword, you can resize only the last array dimension, and you can't change the number of dimensions at all.
codestorm
Fire bad. Tree pretty. - Buffy
Hey, I'm operating on a limited mental budget here.
<insert witticism here>
 
Can I ask what you're using this for?
Redim Preserve xxx
is one of the most expensive operations in VBScript, you should try to stay away from it all you can.

Personally, I use getrows religiously... maybe we can build a better mouse trap, so to speak? leo

------------
Leo Mendoza
lmendoza@garbersoft.net
 
When you declare the varible u declare like this

redim arr(5)
redim preserve arr(10)

If u declare like this it will work
 
Thank you very much Vasah, Codestrom, JJH.

I'll ask another question, or may be the same question in different words.

When you use the following syntax, do you guys get an error or not ?

Code:
Dim myArray()
....
...
..
.
myArray = rs.GetRows()
Thank you,
RR.
__________________________________
The best is yet to come.
 
you would get an error.

do it like this

Dim myArr
...
myArr = rs.GetRows()

remember, getrows has a bunch of optional params... sometimes by specifying the param you can save yourself a lot of trouble (ie, taking care of paging, only getting a certain column, etc.)

go see for more details leo

------------
Leo Mendoza
lmendoza@garbersoft.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top