Common

FreeBASIC

Common
 
Variable declaration and scope modifier

Syntax

Common [Shared] symbolname[()] [AS DataType] [, ...]

Description

Declares a variable which is shared between code modules. A matching Common statement must appear in all other code modules using the variable.

The Shared optional parameter makes the variable global so that it can be used inside Subs and Functions, as well as at module level. Common arrays are always variable-length, and must be defined with an empty parameter list (), and its dimensions set in a later Dim or ReDim statement.

Example

'' common1.bas

Declare Sub initme()

Common Shared foo() As Double

ReDim foo(0 To 2) As Double

initme()

Print foo(0), foo(1), foo(2)


'' common2.bas

Common Shared foo() As Double

Sub initme()
  foo(0) = 4*Atn(1)
  foo(1) = foo(0)/3
  foo(2) = foo(1)*2
End Sub

Output:
 3.141592653589793           1.047197551196598           2.094395102393195

Differences from QB

  • The arrays will be always variable-length.
  • blockname is not needed and must be removed because the order of declaration no longer matters, only the symbol names.

See also