Greesemonkey3
Greesemonkey3

Reputation: 205

Classic ASP: inserting into an array and getting type mismatch

I am trying to insert an int into one array and a string into another. For some reason I can't insert the int or string no matter how I try. Here is the code

dim siteList,siteNameList, strQuery
Set oConn = Server.CreateObject("ADODB.Connection") 
set oRs = Server.CreateObject("ADODB.Recordset")
oConn.Open strConnQuery
strQuery = "Select zSiteID as id, zSiteNm as Name from vSite"
set ors = oConn.Execute(strQuery)
z=0
Do While Not oRs.EOF
   sID=oRs("id")
   sName=oRs("Name")
   if InStr(oRs("Name"),"'")>0 then
       sOut = replace(strorigFileName,"'"  ,"")
       siteList(z)=sID
       siteNameList(z)=sOut
   else
       siteList(z)=sID(this is where the error occurs first)
       siteNameList(z)=sName

   end if
   z=z+1
   oRs.MoveNext
Loop
oConn.Close

I have tried converting it to different things but that hasn't helped at all. I have no idea what is wrong so any information would be greatly appreciated!

Upvotes: 1

Views: 2913

Answers (2)

El Kabong
El Kabong

Reputation: 717

Here's an answer to a similar question that describes why that's happening.

You want to check the number of records in the return set(ors) and either ReDim the array or initialize it after you know the size needed.

Upvotes: 3

Diodeus - James MacFarlane
Diodeus - James MacFarlane

Reputation: 114417

In classic ASP you need to declare a size for arrays:

dim siteList(5)

Upvotes: 2

Related Questions