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 11 of 11
  1. #1
    New Coder
    Join Date
    Aug 2005
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts

    What does this error mean "Out of range"

    Hi,
    I am having this error :-
    Microsoft VBScript runtime (0x800A0009)
    Subscript out of range: 't'and my code as below:-
    Code:
    RS.Open sql,conn,1,3
    t = 0
    do until rs.eof
    t = t + 1
    aryX1(t) = rs("Filename")
    aryA(t) = rs("Avg1")
    aryB(t) = rs("Range1")
    'aryC(t) = rs("Range1")
    rs.movenext
    loop
    Pls explain what when wrong previously it was working fine. tks

  • #2
    Regular Coder
    Join Date
    Mar 2006
    Location
    Brasília, Brazil
    Posts
    153
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Show the code where you define the arrays. Probably the number of lines returned from the query is bigger than the array defined size. Try using a bigger number.






    Programming Tutorial for absolute beginners

  • #3
    New Coder
    Join Date
    Aug 2005
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Kakao
    Show the code where you define the arrays. Probably the number of lines returned from the query is bigger than the array defined size. Try using a bigger number.
    My full code is as below:-
    Code:
    dim aryX1(10), aryA(10), aryB(10), aryC(10)
    SET RS=CreateObject("ADODB.Recordset") 'create a recordset
    sql="select top 10 Avg1, Range1, Filename from tblFiles order by workweek Desc"
    'response.write sql
    'response.end
    RS.Open sql,conn,1,3
    t = 0
    do until rs.eof
    t = t + 1
    aryX1(t) = rs("Filename")
    aryA(t) = rs("Avg1")
    aryB(t) = rs("Range1")
    'aryC(t) = rs("Range1")
    rs.movenext
    loop
    'now each array has it's values, move them into the chart arrays:
    aryX =  Array(aryX1(10),aryX1(9),aryX1(8),aryX1(7),aryX1(6),aryX1(5),aryX1(4),aryX1(3),aryX1(2),aryX1(1))'Xvalues
    aryY1 = Array(aryA(10),aryA(9),aryA(8),aryA(7),aryA(6),aryA(5),aryA(4),aryA(3),aryA(2),aryA(1))
    aryY2 = Array(aryB(10),aryB(9),aryB(8),aryB(7),aryB(6),aryB(5),aryB(4),aryB(3),aryB(2),aryB(1))
    'aryY3 = Array(aryC(1),aryC(2),aryC(3),aryC(4),aryC(5))'...aryC(10))
    
    'aryY1 = Array(460,520,650,580)  'Y Values
    'aryY2 = Array(390,390,390,390,390,390,390,390,390,390)  'Y Values
    aryY3 = Array(680,680,680,680,680,680,680,680,680,680)  'Y Values
    aryY4 = Array(370,370,370,370,370,370,370,370,370,370)  'Y Values
    aryY5 = Array(46,46,46,46,46,46,46,46,46,46)  'Y Values
    aryY6 = Array(240,240,240,240,240,240,240,240,240,240)  'Y Values
    'initialize owc
       Set objCharts = Createobject("OWC10.Chartspace")
       Set objConstants = objCharts.Constants    
    'layout options
    objCharts.HasChartSpaceTitle = False
    pls help tks

  • #4
    New Coder
    Join Date
    Aug 2005
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Kakao
    Show the code where you define the arrays. Probably the number of lines returned from the query is bigger than the array defined size. Try using a bigger number.
    Programming Tutorial for absolute beginners
    Hi I had change the array to a bigger number as below it was 10 now I change it to 100, is it mean that I need to change it to a bigger number when I add more data in db?
    tks
    Code:
     
    dim aryX1(100), aryA(100), aryB(100), aryC(100)

  • #5
    Regular Coder
    Join Date
    Mar 2006
    Location
    Brasília, Brazil
    Posts
    153
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Run it with these changes and report the biggest t:
    Code:
    do until rs.eof
    t = t + 1
    response.write t & "<br />"
    'aryX1(t) = rs("Filename")
    'aryA(t) = rs("Avg1")
    'aryB(t) = rs("Range1")
    'aryC(t) = rs("Range1")
    rs.movenext
    loop
    response.end

  • #6
    Regular Coder
    Join Date
    Mar 2006
    Location
    Brasília, Brazil
    Posts
    153
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by cs168
    Hi I had change the array to a bigger number as below it was 10 now I change it to 100, is it mean that I need to change it to a bigger number when I add more data in db?
    tks
    Code:
     
    dim aryX1(100), aryA(100), aryB(100), aryC(100)
    Did it work? Your sql query have a TOP 10 limit. If your query don't have a limit anymore your code should be able to handle any number of lines. Create the arrays with a big enough number.

  • #7
    New Coder
    Join Date
    Aug 2005
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Kakao
    Run it with these changes and report the biggest t:
    Code:
    do until rs.eof
    t = t + 1
    response.write t & "<br />"
    'aryX1(t) = rs("Filename")
    'aryA(t) = rs("Avg1")
    'aryB(t) = rs("Range1")
    'aryC(t) = rs("Range1")
    rs.movenext
    loop
    response.end
    As now the last no I get is 18, will it change to bigger no is I add more data into my access db?

  • #8
    Regular Coder
    Join Date
    Mar 2006
    Location
    Brasília, Brazil
    Posts
    153
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Unless you use the TOP X limit it will return all lines in the tblFiles table.
    Last edited by Kakao; 04-12-2006 at 06:26 PM.

  • #9
    Regular Coder
    Join Date
    Mar 2006
    Location
    Brasília, Brazil
    Posts
    153
    Thanks
    0
    Thanked 0 Times in 0 Posts
    if the Access sql do not understand TOP X and you only want 10 lines do like this:

    Code:
    do until rs.eof or t = 10
    t = t + 1
    aryX1(t) = rs("Filename")
    aryA(t) = rs("Avg1")
    aryB(t) = rs("Range1")
    'aryC(t) = rs("Range1")
    rs.movenext
    loop




    Programming Tutorial for absolute beginners

  • #10
    New Coder
    Join Date
    Aug 2005
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Kakao
    Unless you use the TOP X limit it will return all lines in the tblFiles table.
    tks for the help and advise.tq.

  • #11
    New to the CF scene
    Join Date
    Apr 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    if your array is sized to 10, and you're pulling 10 entries from the DB, isn't the real issue that you're incrementing your array BEFORE putting anything into it? Your first iteration through the loop should be putting values in aryX1(0), but your code is inserting the first record in the recordset to aryX1(1) since you're incrementing var "t" at the beginning of the loop instead of the end. That would be why you're getting a subscript error when you get to the last record in the recordset, since "t" would now be a higher index than what you have room for in the array.


  •  

    Posting Permissions

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