Help with Arrays (VBScript)

J

joe

Hello:

I am scratching my head here. I was trying to copy values from a recordset
into an array, but whatever I do,
I keep getting errors. Let me give an example similar to what my code
initially looked like:

'--- sql and recorset creation here ...etc.

Dim MyArray, intTemp
intTemp = 0

Do Until RS.EOF
MyArray(intTemp) = RS("SomeData")
RS.MoveNext
Loop

The above gave me a type mismatch error, without much information.
Apparentely the array didnt like the
variable intTemp. But I thought that maybe its required that I specify the
lenght of the array when decalring it, so
I went:

intTemp = Cint(RS.recordcount - 1)
Dim MyArray(intTemp) '--- hoping that the array would have the same lenght
as the RS

The error I got now is:

Expected integer constant
[sniped reference to specific line in the code]
Dim MyArray(intTemp)

Aren't I making an integer with Cint?

Any help is appreciated.
 
D

dlbjr

'This will be far more efficient

'Connect
MyArray = rs.GetRows()
'DisConnect
intMax = UBound(MyArray ,2)

'Here is an example of looping thru the array if the recordset return 2 columns
For i = 0 To intMax
item1 = MyArray(0,i)
item2 = MyArray(1,i)
item3 = MyArray(2,i)
Next

'dlbjr
'Pleading sagacious indoctrination!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,159
Messages
2,570,879
Members
47,413
Latest member
ReeceDorri

Latest Threads

Top