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

Error with array

Status
Not open for further replies.

snowboardr

Programmer
Feb 22, 2002
1,401
PH
Im trying to load some course names in an array, via the database, but I can't specify the number of items in the array so it gives me a type match error, what could I do to get around this?

- Jason


Dim sAllCourseNames


strSelect = "SELECT cID, cTitle FROM course"

Set conn = createobject("ADODB.Connection")
Set rsCourseNames = Server.CreateObject("ADODB.RecordSet")

Database("open")
Set rsCourseNames = conn.Execute(strSelect)

If NOT rsCourseNames.eof then
Do while not rsCourseNames.eof
tempTitle = rsCourseNames("cTitle")
tempID = rsCourseNames("cID")

sAllCourseNames(tempID) = tempTitle

rsCourseName.movenext
loop

Else
NoCourses = True
End If
Database("close")
End If

www.vzio.com
ASP WEB DEVELOPMENT



 
I'm not sure if you can guarentee the courseID ("CID") sequential. but for flexibility sakes i'd probably make a 2d array somthing like. that way it doesn't matter if you delete a course and the id's skip a few etc.

dim courseNames

If NOT rsCourseNames.eof then
Do while not rsCourseNames.eof
if not isarray(courseNames) then
redim courseNames(1,0)
else
redim preserve courseNames(1,ubound(courseNames,2)+1)
end if
courseNames(0,ubound(courseNames,2)) = rsCourseNames("cTitle")
courseNames(1,ubound(courseNames,2)) = rsCourseNames("CID")

rsCourseName.movenext
loop

Else
NoCourses = True
End If


Later to get the results

for lng_ct1 = 0 to ubound(courseName,2)
'then just grab out the results
next



 
I think from your example that snowboardr wants to use some kind of "asociative arrays".
You can use asociative arrays by using "Scriptding.DictionaryObject" or using Session itself
This way it's not to eficient.

You can use arrays but first you need to dim the array with the max tempID that you can have, i presume that they are not consecutive values so it will be an partially filed array.
Code:
strSelect = "SELECT cID, cTitle FROM course"
            
            Set conn = createobject("ADODB.Connection")
            Set rsCourseNames = Server.CreateObject("ADODB.RecordSet")
            Dim sAllCourseNames(1)
            
            Database("open")
            Set rs = conn.Execute("select max(cID) as maxcid")
            Redim sAllCourseNames(rs("maxcid"))
            Set rsCourseNames = conn.Execute(strSelect)
             
        If NOT rsCourseNames.eof then        
            Do while not rsCourseNames.eof
                    tempTitle = rsCourseNames("cTitle")
                    tempID = rsCourseNames("cID")
                
                    sAllCourseNames(tempID) = tempTitle
                
            rsCourseName.movenext
            loop    
            
        Else
        NoCourses = True
        End If
        Database("close")
    End If

________
George, M
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top