dim x as integer,y as integer,z as string
x=11
y=22
z="hello"
print z;y;x 
F:\learn\fbs>1
hello 22 11F:\learn\fbs>
 
dim  as integer x,y 
dim z as string
x=11
y=22
z="hello"
print z;y;x 
变量声明修饰符,指定整个模块的可见性
 Dim Shared ...
Redim Shared ...
Common Shared ...
Static Shared ...
[Static] Var Shared ... 
共享使模块级变量在Subs和Functions中可见。
 如果在模块级变量的声明中未使用Shared,则该变量仅对该文件中的模块级代码可见(此外,堆栈中只存储使用Dim声明的变量,而不存储在命名空间块中)。
 注意(对于共享变量,不包括公共变量):
.data部分中带有描述符,但指向动态内存块)。.data节)。'' Compile with -lang qb or fblite'$lang: "qb"Declare Sub MySub
Dim Shared x As Integer
Dim y As Integerx = 10
y = 5MySubSub MySubPrint "x is "; x 'this will report 10 as it is sharedPrint "y is "; y 'this will not report 5 because it is not shared
End Sub
 
要从本地作用域块访问全局命名空间中定义的共享变量的重复符号,请添加一个或两个点作为前缀:.SomeSymbol,或最好是..SomeSymbol(如果在With.End With块内,则仅为 ..SomeSymbol)。
F:\learn\fbs>1
x is  10
y is  0
 
Declare Sub MySub
Declare Sub PrintZ
Dim Shared x As Integer
Dim y As Integer
Dim Shared z As Integer
z=111
x = 10
y = 5MySub
printZ
Sub MySubPrint "x is "; x 'this will report 10 as it is shared
End SubSub PrintZDim z As Integerz=19    Print "shared z is ";.z  Print "z is ";z 
End Sub
 
F:\learn\fbs>1
x is  10
shared z is  111
z is  19
 
Declare Sub PrintZ
Dim Shared As Integer z1,z2 
z1=111
z2=109printZSub PrintZDim z1 As Integerz1=19    Print "shared z1 is ";.z1  Print "z1 is ";z1Print "shared z2 is ";z2
End Sub
 
F:\learn\fbs>1
shared z1 is  111
z1 is  19
shared z2 is  109
 
与QB的区别:
作用域块内的Shared语句(函数、subs、if/thens和循环)不受支持。
 在主程序中改用Dim|Redim|Common|StaticShared。
 或者,如果您在一个作用域块内,并重新导入以前使用Shared设置的变量或数组,只需在不使用Shared的情况下执行Redim;它会工作得很好,不会破坏任何东西。
只有在-lang qb和-lang fblite方言中,可以在不首先声明变量的情况下使用变量,在这种情况下,它们被称为隐式变量