Scope
Local variables:
Declared in any event, subroutine, or function with the keywords Dim or Static. These variables only exist within the context of the procedure in which they are declared. There is no problem with having local variables in many procedures with the same name. They all will refer to different storage spaces. If there is a conflict in names between a local variable and a more global variable, the local variable always wins. Use Static only if you don't want to lose the value in a local variable between calls to the procedure. Usually you will use Dim.
Module-level variables:
Declared in a form or BASIC module's General Declarations section, with the keywords Dim or Private. Dim is the old syntax; Private is preferred. These variables are accessible from any event, subroutine, or function procedure in the module.
old: Global variables:
Declared in any Basic Module in the project using the keyword "Global". These variables can be accessed and changed by any procedure in the project. It's best to avoid these and use the new "Public" type.
new: Public variables:
These are declared in a form or BASIC module's General Declarations section. They belong to the module in which they are declared, but they can be accessed from any procedure in the project. More about these in a later lesson...
Declaring Variables
within a procedure (local variables):
Dim i As Integer, j As Integer
Static a As Integer, b As Integer, c As Integer
in General Declarations:
Private name As String
Public datafilename As String, ID As Long
WARNING! Do not use:
Dim A, B, C As Integer