can I do this in a SUB?

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
jetq111
Newbie
Posts: 6
Joined: Sun Oct 15, 2006 7:03 am

can I do this in a SUB?

Post 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
4815162342
User avatar
Stoves
Veteran
Posts: 101
Joined: Fri Feb 10, 2006 12:24 am
Location: Nashville, TN

Post 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.
rgreenlaw
Newbie
Posts: 9
Joined: Mon Aug 06, 2007 1:20 pm

While learning qbasic and subs try this

Post 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.
Roger Greenlaw
Post Reply