View Full Version : populate array (easy)
maxpouliot
08-28-2006, 09:38 PM
hi,
having problems here with something easy. i want to populate an array. Why does this code doesnt work
sqlMulti="SELECT nom FROM " & table & " ORDER BY nom"
Dim rsMulti
Set rsMulti = Server.CreateObject("ADODB.Recordset")
rsMulti.Open sqlMulti,Conn
Dim myArray()
i=0
While Not rsMulti.EOF
myArray(i)=1
i=i+1
rsMulti.MoveNext
Wend
Thanks
prototyp3
08-29-2006, 08:52 AM
your just assigning value 1 to your array
myArray(i)=1
maxpouliot
08-29-2006, 03:27 PM
your just assigning value 1 to your array
myArray(i)=1
I don't understand what you mean? This isn't ok?
Even with this :
sqlMulti="SELECT nom FROM " & table & " ORDER BY nom"
Dim rsMulti
Set rsMulti = Server.CreateObject("ADODB.Recordset")
rsMulti.Open sqlMulti,Conn
Dim myArray()
i=0
While Not rsMulti.EOF
myArray(i)=rsMulti("nom")
i=i+1
rsMulti.MoveNext
Wend
i get the error : Subscript out of range: 'myArray'
skalag
08-29-2006, 04:21 PM
This would probably help solve it for now but its not the best solution i think as im pretty new at this stuff, hope it helps for now anyway
Dim rsMulti
Set rsMulti = Server.CreateObject("ADODB.Recordset")
rsMulti.Open sqlMulti,Conn
i=0
Dim myArray()
While Not rsMulti.EOF
ReDim Preserve myArray(i + 1)
myArray(i) = rsMulti("nom")
i = i + 1
rsMulti.MoveNext
Wend
Spudhead
08-30-2006, 03:41 PM
sqlMulti="SELECT nom FROM " & table & " ORDER BY nom"
Dim rsMulti
Set rsMulti = Server.CreateObject("ADODB.Recordset")
rsMulti.Open sqlMulti,Conn
if not rsMulti.EOF then myArray = rsMulti.getRows() (http://www.devguru.com/technologies/ado/8678.asp)
rsMulti.Close
set rsMulti = nothing
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.