Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data lines in subs

Status
Not open for further replies.

The

Programmer
Jul 30, 2001
92
CA
I have a sub (subroutine), and in it I have some READ + DATA statements. When I try to run the program, it won't accept the data lines; I think Qbasic thinks "data" is my own custom function that I haven't defined. The read/data works fine if it's not in a sub, but that would force me to rearrange my program. Can anyone help?
 
You cannot have DATA lines in subs. You can call them with READ commands in subroutines, but the DATA lines must be in the main module.
 
you can use special labels for the data though...

label1:
DATA bla, bla, bla
label2:
DATA bla, bla, bla


then use RESTORE to reset the data to a specific label...

then in your Sub just Reset the Label before you read...

Such AS this...

Code:
DECLARE SUB print123 ()
DECLARE SUB print456 ()
print123
print456
print123
print456

label123:
  DATA 1,2,3
label456:
  DATA 4,5,6

SUB print123
  RESTORE label123
  FOR n = 1 TO 3
    READ a
    PRINT a
  NEXT n
END SUB

SUB print456
  RESTORE label456
  FOR n = 1 TO 3
    READ a
    PRINT a
  NEXT n
END SUB

Have Fun, Be Young... Code BASIC
-Josh Stribling
cubee101.gif

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top