Solved

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

Posted on 2004-04-02
5
361 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 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

Technology Partners: 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

Suggested Solutions

Title # Comments Views Activity
If-Then-Else ASP problem 6 71
Get hold of longitude and latitude in iframe string 11 52
Validating Date Part2 2 27
Two decimal 5 28
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

749 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