Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-04-02
5
Medium Priority
?
387 Views
Last Modified: 2009-12-16
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

0
Comment
Question by:kwcowboy1226
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 10

Expert Comment

by:Shailesh15
ID: 10743689
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)  
0
 
LVL 10

Accepted Solution

by:
D_M_D earned 2000 total points
ID: 10744031
Here's the code...

<%
Dim i, j
Dim intContactId(4)
Dim intAddressId(4)
Dim intSCcnt, intCcnt

strStudentContact = "exec ssrSP_GetStudentContact '" & strKISDID & "'"
set rsStudentContact = ExecSQLRS(strStudentContact)
intSCcnt = rsStudentContact.RecordCount
Redim Preserve intContactId(intSCcnt )

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)
          intCcnt = rsContact.RecordCount
          Redim Preserve rsContact(intCcnt )

          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
%>



--------
D_M_D
0
 
LVL 31

Expert Comment

by:alorentz
ID: 10745388
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


0
 
LVL 31

Expert Comment

by:alorentz
ID: 10745413
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.
0
 
LVL 31

Expert Comment

by:alorentz
ID: 11394207
Do you still need assistance with this question?   If not, please close...

Thanks.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question