Results 1 to 3 of 3

Thread: For/next

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2007
    Posts
    8

    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!

  2. #2

    Thread Starter
    New Member
    Join Date
    Oct 2007
    Posts
    8

    Re: For/next

    I tried changing all of my FOR/NEXTs to IF/THEN GOTOs, but I got the same error message.

  3. #3
    Hyperactive Member
    Join Date
    Oct 2007
    Location
    Godzone, oops Oz
    Posts
    355

    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.

Posting Permissions

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



Click Here to Expand Forum to Full Width