Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can I use labels in SUBs
I have recently returned to Qbasic after many years.
I never used SUBs before but I am attempting to learn and use them as I think they will make the code cleaner.

I moved some code from the main code to a SUB and it appears labels or line numbers are not allowed in a SUB?
I looked in the help and I don't see any place in the documentation that says this will not work.
Can someone explain if I need to do something different or why this would not work?

SUB init
  KEY 16, CHR$(0) + CHR$(1)
  ON KEY(16) GOSUB foo
  KEY(16) ON

    print "you did it"

I get an error of "Label not defined" when I try to run the code.

Thank you for your help.
You appear to have stumbled on a not-well-documented limitation of QBASIC: the ON...GOTO/GOSUB commands must refer to a module-level label or line number

PDS 7.1 has ON LOCAL ERROR to allow this for ON ERROR, but not for the other commands.

Forum Jump:

Users browsing this thread: 1 Guest(s)