...

View Full Version : What does this error mean "Out of range"



cs168
04-12-2006, 05:25 PM
Hi,
I am having this error :-
Microsoft VBScript runtime (0x800A0009)
Subscript out of range: 't'and my code as below:-


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

Kakao
04-12-2006, 05:46 PM
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 (http://programming-crash-course.com/)

cs168
04-12-2006, 05:56 PM
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:-


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))'Xv alues
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

cs168
04-12-2006, 06:04 PM
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 (http://programming-crash-course.com/)

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


dim aryX1(100), aryA(100), aryB(100), aryC(100)

Kakao
04-12-2006, 06:10 PM
Run it with these changes and report the biggest t:


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

Kakao
04-12-2006, 06:14 PM
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


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.

cs168
04-12-2006, 06:17 PM
Run it with these changes and report the biggest t:


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?

Kakao
04-12-2006, 06:21 PM
Unless you use the TOP X limit it will return all lines in the tblFiles table.

Kakao
04-12-2006, 06:27 PM
if the Access sql do not understand TOP X and you only want 10 lines do like this:



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 (http://programming-crash-course.com/)

cs168
04-12-2006, 06:28 PM
Unless you use the TOP X limit it will return all lines in the tblFiles table.
tks for the help and advise.tq.

dmchale
04-12-2006, 06:57 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum