sdlBasicはルーチンにおいて変数に遭遇した時に、スコープ内に同じ名前の変数がないかどうかをチェックしてからそれを使います。
Dim myVar = "module variable" ' This is declared at the module level
Function myRoutine()
Dim myVar = "routine variable" ' This is declared at the routine level
myVar = "new
value" '
Use the local routine version of myVar
return myVar
End Function
print myRoutine()
print myVar
もしなければ、モジュールをチェックして使います。
Dim myVar = "module variable" ' This is declared at the module level
Function myRoutine()
myVar = "new value" ' use the module version of myVar
return myVar
End Function
print myRoutine()
print myVar
もしルーチンまたはモジュール内に変数がなければ、現在のスコープ内でそれはつくられます。
その場合使用の前にOption Explicit によって、変数を宣言する必要があるでしょう:
Option Explicit
Dim newVar = "create me"
Option Explicit を使えば、特に Shared または Common (またはGlobal)と宣言しない限りは、モジュールレベルの変数は、ルーチンから隠されます。
Option Explicit
Dim myVar = "module variable"
Function myFunction()
Shared myVar
myVar = "new value"
End Function
または:
Option Explicit
Dim Common myVar = "module variable"
Function myFunction()
myVar = "new value"
End Function