Wait, does your code actually work in QBasic or QuickBASIC? QB doesn't have the PUBLIC/PRIVATE declaration (everything is PUBLIC) and all variables are passed BYREF (I don't think you can explicitly use BYVAL unless it's for CALL ABSOLUTE or a non-BASIC procedure.) I'm not sure the code you wrote would execute.
COMMON is typically used when sharing variables between modules (more than one source file, more than one compiled program, or when using libraries;) for instance, you have 1.BAS and 2.BAS. In 1.BAS, you declare a variable using COMMON and then, CHAIN to 2.BAS later on. In 2.BAS, you also declare that variable using COMMON and QBasic should carry the data from one program to the other (only the type and the order in which variables are declared with COMMON is important.) It works with interpreted source code in the IDE, or with BRUN45-dependent EXEs.
Since you're writing a one-file program, I don't think you need to use COMMON. Just go straight for the DIM SHARED <var> AS <type> in your main module and have the variable shared among all routines... that being said COMMON SHARED is still technically valid and the following code works as intended in QuickBASIC 4.5:
Code: Select all
DECLARE SUB PrintTerminalNumber()
COMMON SHARED TerminalNumber AS STRING
TerminalNumber = "1234"
PrintTerminalNumber
SUB PrintTerminalNumber
PRINT "Terminal Number :"; TerminalNumber
END SUB
Typical use would be:
Code: Select all
' 1.BAS
COMMON myName AS STRING
INPUT "What's your name"; myName
CHAIN "2.BAS"
Code: Select all
' 2.BAS
COMMON someName AS STRING
PRINT "So, your name is "; someName
Or, with SHARED:
Code: Select all
' 1.BAS
COMMON SHARED myName AS STRING
INPUT "What's your name"; myName
CHAIN "2.BAS"
Code: Select all
' 2.BAS
DECLARE SUB MyRoutine()
COMMON SHARED someName AS STRING
MyRoutine
SUB MyRoutine
PRINT "So, your name is "; someName
END SUB