Page 1 of 1

can I do this in a SUB?

Posted: Thu Jul 26, 2007 8:01 am
by jetq111
hello.

Right now I am making a very large text adventure RPG. My problem is that in one sub after an input command I want it to go to a different sub. Can I do that? here is some source:

DECLARE SUB INTRO ()
DECLARE SUB DOG ()

SUB INTRO
10 PRINT "HELLO "
INPUT A$
SELECT CASE A$
CASE IS = "HELLO"
GOTO SUB DOG ' <--------- this is the line i need help with
CASE IS = ELSE
GOTO 10
END SUB

SUB DOG
PRINT "HELLO"
END SUB



thanks

Posted: Thu Jul 26, 2007 8:47 am
by Stoves
Yes, in fact, you shouldn't have to use the text "GOTO SUB" at all. Just type the name of your sub. QB recognizes the implicit CALL command when you just type the name of the SUB. So the code below should work fine.

Code: Select all

SUB INTRO 
10 PRINT "HELLO " 
INPUT A$ 
SELECT CASE A$ 
CASE IS = "HELLO" 
DOG 
CASE IS = ELSE 
GOTO 10 
END SUB
Good luck.

While learning qbasic and subs try this

Posted: Mon Aug 06, 2007 6:08 pm
by rgreenlaw
While learning to program in Qbasic and using subroutines you might want to try this:

Code: Select all

call dog
instead of

Code: Select all

dog
This will help you to remember that "dog" is a subroutine that you coded.