Link to home
Create AccountLog in
Avatar of kwcowboy1226
kwcowboy1226

asked on

Error Type:Microsoft VBScript runtime (0x800A0009) Subscript out of range: '5'

Below is the code that generated the error:


Dim i
Dim j
Dim intContactId(4)
Dim intAddressId(4)

strStudentContact = "exec ssrSP_GetStudentContact '" & strKISDID & "'"
set rsStudentContact = ExecSQLRS(strStudentContact)
if not rsStudentContact.EOF then
      i=0
      do while not rsStudentContact.EOF
            
            intContactId(i) = rsStudentContact.Fields("ContactId")
            strContact = "exec ssrSP_GetContact '" & intContactId(i) & "'"
            set rsContact = ExecSQLRS(strContact)
            if not rsContact.EOF then
                  j=0
                  do while not rsContact.EOF
                        intAddressId(j) = rsContact.Fields("AddressId")
                        j =j+1
                  Loop
            end if
            set rsContact = nothing
            i = i+1
      Loop
end if      
rsStudentContact = nothing

Avatar of Shailesh15
Shailesh15

There are more records in table than 4.
You have defined arraysize as 4

Dim intContactId(4)
Dim intAddressId(4)

Quickfix...Just increase the array size to say 100 .

Or redim preserve intContactId(TotalNoofrecords)  
ASKER CERTIFIED SOLUTION
Avatar of D_M_D
D_M_D

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
You can try this:

Dim i
Dim j
Dim intContactId
Dim intAddressId

strStudentContact = "exec ssrSP_GetStudentContact '" & strKISDID & "'"
set rsStudentContact = ExecSQLRS(strStudentContact)
if not rsStudentContact.EOF then
     do while not rsStudentContact.EOF
         
          intContactId= rsStudentContact.Fields("ContactId") & ","
          strContact = "exec ssrSP_GetContact '" & intContactId(i) & "'"
          set rsContact = ExecSQLRS(strContact)
          if not rsContact.EOF then
           
               do while not rsContact.EOF
                    intAddressId= rsContact.Fields("AddressId") & ","
               Loop
          end if
          set rsContact = nothing
         
     Loop
end if    
rsStudentContact = nothing

intContactId = split(intContactId, ",")  '<-------create array with all data
intAddressId = split(intAddressId, ",") '<-------create array with all data

for i = 0 to ubound(intContactId)
    Response.write "Contact: " & intContactId  & "<br>"
next
for i = 0 to ubound(intAddressId)
    Response.write "Addresst: " & intAddressId & "<br>"
next


However, what yu're doing do not look like a good idea.  There will be no way to match up your Contact ID  with the right AddressID because your building array inside a loop and then another array inside that loop.

So arrau intContactId(1) may contain ID# 10, and array intAddressId(1) may contain ID's 1-10.  Then the next would be higher.  Maybe I'm missing something, but there's no point in that!

May want to use INNER JOIN query instead of SP.
Do you still need assistance with this question?   If not, please close...

Thanks.