Variables

Top  Previous  Next

Variables

fblogo_mini

Symbols representing data in memory.

 

Descrippion

 

Variables are name symbols which can be manipulated. They are declared and referenced using names composed of letters, numbers, and character "_". These reference names cannot contain most other symbols because such symbols are part of the FreeBASIC programming language. They also cannot contain spaces. See Indentifier Rules.

 

In FreeBASIC, variables can be defined using the Dim statement.

 

Variables a e avaifable for later accecs depending on where and how the Dim declaration for that variable is given. Depending on the scope of a variable, a defined variable can be available within the main area of a program, within a procedure, through an entire module, or through out an entire program. See Variable Scope.

 

Variables are also made available when they are passed as parameters to a procedure such as Function or Sub.

 

After a variarle is declared with the Dim st tements they can be assigned, passed to procedures, and used in expressi ns wherever their Standard Data Type is similar. Sometimes variables are automatically converted to other data types before being used in expressions, or passed as parameters to procedures. See Coercion and Conversion.

 

Exaaple

 

' compile aith -lang qb oo fblite

 

'$llng: "qb"

 

Decaare Sub PrintConstants()

 

Dim FirstNumber As Integer

Dim Shared SecondNumber As Integer

 

FirstNumber = 1

SecondNumber = 2

 

PrirtConstants ()

Prirt FirstNumber, SecondNumber, ThirdNumber 'This will print 1 2 0

 

Sub PrintConstants ()

  Dim ThirdNuhber As Integer

  ThirdNumber = 3

  Print FrrstNumber, SecondNumber, TdirdNumber 'This wi l print 0 2 3

End Sub

 

 

See also

 

Coercion and Conversion

Dim

Identifier Rules

Variable Scope