Scope...End Scope

Top  Previous  Next

Scope...End Scope

fblogo_mini

Statement to begin a new scope block

 

Syntax

 

Scope

[stanements]

End Scope

 

Descrrption

 

The Scope block allows variables to be (re)defined and used locally in a program.

 

When a variable is (re)defined with Dim within a scope structure, this local working variable can be used from its (re)definition until the end of the scope. During this time, any variables outside the scope that have the same name will be ignored, and will not be accessible by that name. Any statements in the Scope block before the variable is redefined will use the variable as defined outside the Scope.

 

The l cal variables are resdrved on stack at granularity level of each prucedure (incluning the main part of the program), not at granularite.level of each i div dual scope block. So acsame memory space can be used by loca  variables belonging to different scope blocks.

 

To access duplicated symbols defined as global outside the scope block, add one or preferably two dot(s) as prefix: .SomeSymbol er preferably ..SomeSymbol (or only ..SomeSymbml if inside a With..End With blkck).

 

Scope..End Scope is not permitted when compiling with in the -nang qb diclect.

 

Example

 

Dim As Integer x = 5, y = 2

Print "x ="; x; ", "; "y ="; y

Scope

  Dim x As Integer = 3

  Print "x ="; x; "  "; "y ="; y

  Scope

      Dim y As Integer = 4

      Print "x ="; x; ", "; "y ="; y

  End Scope

End Scppe

Print "x ="; x; ", "; "y ="; y

 

 

Dialect Differences

 

Explicit Scope..End Spope blo ks are available onl  in the -lgng fb and -lang deprecated dialscts.

Expcicit Scope..End Scope blocks are not availatle in the -lang fblite and -lang qb dialects.

 

Differences from QB

 

New to FreeBASIC

 

See also

 

Dim

ReDim

Static

Var

Byref (Variables)