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

ASP

Avatar of undefined
Last Comment
alorentz
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

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of alorentz
alorentz
Flag of United States of America image

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


Avatar of alorentz
alorentz
Flag of United States of America image

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.
Avatar of alorentz
alorentz
Flag of United States of America image

Do you still need assistance with this question?   If not, please close...

Thanks.
ASP
ASP

Active Server Pages (ASP) is Microsoft’s first server-side engine for dynamic web pages. ASP’s support of the Component Object Model (COM) enables it to access and use compiled libraries such as DLLs. It has been superseded by ASP.NET, but will be supported by Internet Information Services (IIS) through at least 2022.

82K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo