Solved

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

Posted on 2004-04-02
5
348 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
  • 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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Leverage browser caching 2 55
Update function to validate checkbox is checked 4 65
ASP Sessions Being Cleared/Modified 6 61
If-Then-Else ASP problem 6 46
I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

929 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now