COMMON SHARED is used to pass variable values between two or more program modules and sub procedures within that module.
The multi-modular technique goes back to when QBasic and QuickBASIC had module size constraints. In QB64 it has been implemented so that that older code can still be compiled, though it is advisable to use single modules for a single project (not counting $INCLUDE libraries), for ease of sharing and also because the module size constraints no longer exist.
- COMMON [SHARED][/block_name/]variable_list
- COMMON statements must be made before any program code execution.
- The SHARED statement allows the variable values to also be used in module SUB and FUNCTION procedures.
- The list of variables(separated by commas) to pass MUST be in the same type order in ALL modules used!
- COMMON variable list names(but not variable types) can change between modules.
- The list can hold any variable type.
- The list cannot define a variable's value, but can use AS to designate the type.
- Use DIM SHARED variables when working in a module to pass variable values to SUB procedures.
- Data files could be used as an alternative to using COMMON SHARED values.
- In QB64 COMMON values are sent using files instead of memory presently.
- Note: Values assigned to shared variables used as procedure call parameters will not be passed to other procedures! The shared variable value MUST be assigned INSIDE of the SUB or FUNCTION procedure to be passed!
- QuickBASIC 4.5 required you to include BRUN45.EXE when you compile COMMON SHARED values between EXE modules.
- The COMMON block name designates a certain block of variables that certain program modules may use, the name must be within two forward slashes/ (Ex: /thename/ ). Not supported in QB64
COMMON SHARED x%, y%, user$, speed!, score&