Most variables which are used on a computer tend to be locally scoped. Line 6 shows a locally scoped variable, D, being defined. The scope of this will be only for the lifetime of that function. As such when we get to line 14, variable D will no longer be available.

 

It is important to remember this as a lot of compiler errors tend to based on variable scoping. Consider the code snippet below

 

Function first()

Dim Test

Test = 1

Second()

End

 

Function second()

Test = 2

End

 

Test = 2 will fail due to the fact that it has not been declared. Even though it was declared in first() it’s scope is only for that function. As such when second() is called the variable test will of dropped out of scope. As such we will no longer have access to it.

 

Later we will look at further scoping rules for local variables. However now it is time to look at the idea of an environment.