Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: Subscript Error

  1. #1
    New to the CF scene
    Join Date
    Aug 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Subscript Error

    Trying to nail down this error I got:

    Subscript out of range: '501'

    Here is the code:
    Dim AirportID(500)
    Dim Cnt
    Dim CntA
    Dim ArTime
    Dim DeTime

    Cnt = 0

    strSQL = "SELECT Name FROM Airports ORDER BY Name ASC"
    RS.Open strSQL,CONN,1,1

    Do Until RS.EOF
    AirportID(Cnt) = RS.Fields("Name")
    Cnt = Cnt + 1
    RS.MoveNext
    Loop

    RS.Close

    ** The ERROR is stating the Line that starts with AirportID, thats where I get the 501 error.. **

    Any help would be great, or pointers..!!!

    I'm not a real good asp\db programmer and in fact someone else did this, but I'm trying to learn and since this broke, i thought what the heck..

    thanks
    Scott

  • #2
    New to the CF scene
    Join Date
    Aug 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I think the problem is within the data..

    Sorry to waste bandwidth on this one

    Scott

  • #3
    Senior Coder Morgoth's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada Remaining Brain Cells: 6
    Posts
    1,402
    Thanks
    2
    Thanked 1 Time in 1 Post
    What is AirportID(0 to 500) equal? Just ID numbers? Where did you get those ID numbers, they didn't just appear out of no where.

    Is this all the asp code related to the problem?

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    You need to ReDim the array to the number of records retrieved.
    But the best solution is to use getRows() to automatically put the contents of the recordset to array.

    Dim AirportID
    ...
    strSQL = "SELECT Name FROM Airports ORDER BY Name ASC"
    RS.Open strSQL,CONN,1,1

    AirportID = RS.getRows()

    RS.close()
    set RS = nothing

    ...

  • #5
    Senior Coder Morgoth's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada Remaining Brain Cells: 6
    Posts
    1,402
    Thanks
    2
    Thanked 1 Time in 1 Post
    Quote Originally Posted by glenngv
    You need to ReDim the array to the number of records retrieved.
    But the best solution is to use getRows() to automatically put the contents of the recordset to array.

    Dim AirportID
    ...
    strSQL = "SELECT Name FROM Airports ORDER BY Name ASC"
    RS.Open strSQL,CONN,1,1

    AirportID = RS.getRows()

    RS.close()
    set RS = nothing

    ...
    I'm an idiot, I didn't even read the code.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •