Beginner's Programming Tutorial in QBasic

(Kiana) #1
PRINT "Enter some text:";INPUT text$
PRINT "The text you entered was: "; text$
PRINT "Enter some text:";INPUT text$
PRINT "The text you entered was: "; text$

By using a subroutine, the above program can be simplified like this:
CALL GetTextCALL GetText
CALL GetText
CALL GetTextCALL GetText
CALL GetTextCALL GetText


SUB GetText
PRINT "Enter some text:";
INPUT text$PRINT "The text you entered was: "; text$
END SUB

The following is even more concise:
FOR x = 1 TO 7CALL GetText
NEXT
SUB GetTextPRINT "Enter some text:";
INPUT text$
END SUBPRINT "The text you entered was: "; text$


Parameters


Parameters are numbers and strings that you pass to a subroutine, much like a QBasic
command.


' This passes 16 as a parameter:
CALL OutputNumber(16)
' Notice the parentheses around the parameter "num."
' Any variables placed inside the parentheses are set as
Free download pdf