変数の有効範囲

変数が作成された時、その有効範囲は現在のコンテクストのみです。それは、現在のコンテクストとより大きいコンテクストとを意味しています。 最大範囲はそのモジュールです:

Dim newVar = 12

変数のスコープはそのルーチン内:

Function myRoutine()
    Dim newVar = 12
End Function

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
 
もしルーチンまたはモジュール内に変数がなければ、現在のスコープ内でそれはつくられます。

Function myRoutine()
   myVar = "new value"      ' create a variable scoped to the routine
End Function
 
そのルーチン内の変数は、スコープされるルーチン内だけに限られます。

Function myRoutine()
   myVar = 12
   print myVar   ' myVar is visible here
End Function

myRoutine()
print myVar  ' myVar is invisible here

Option ExplicitステートメントによってsdlBasicが変数を作成することを止めることができます。 その場合使用の前に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