-
For/next
I am using Liberty BASIC v4.03 on a PC with Windows XP.
I wrote a program using FOR/NEXT commands. The first time I use it is in a section for entering data. I have no trouble entering the data until I hit enter after the last number. Then I get an error message saying "Runtime Error: Subscript out of range: 11, xO."
Here is the code for that section:
[EnterData]
FOR i=0 to 11
PRINT
PRINT "Enter temperature for data point "; i+1; "."
INPUT Temperature(i)
PRINT
PRINT "Enter pressure for data point "; i+1; "."
INPUT Pressure(i)
NEXT i
PRINT
What am I doing wrong? Should I just go back to using:
IF i > 11, GOTO [Next]
GOTO [EnterData]
?
Thanks!
-
Re: For/next
I tried changing all of my FOR/NEXTs to IF/THEN GOTOs, but I got the same error message.
-
Re: For/next
"Subscript out of range" is indicating your array isn't large enough to handle whatever is going into it.
Temperature(i), where "i" is out of bounds for your array size. Incease that by one or so in the declaration to resolve.