A variable dimmed within a routine has scope only for that routine. You can pass it to another routine as a reference, but that reference will have scope only in the called routine. If it is an effective reference, the variable in the calling routine will hav eits value changed if the value of the reference is changed in the called routine.
A variable Dimmed within a routine never has scope outside the routine, but if it is created with the keyword Static, it will retain its value between calls to the routine, so that in this special case it will have
life beyond the life of the routine, but scope only within the routine itself.
A variable dimmed within the code of a form has scope for the whole form if Private, and can be accessed from outside the form if Public or Global (Public is preferred) when specified in a fully qualified fashion.
The variable will go out of existence if the form is closed/unloaded. Hiding the form will not terminate the variable; it will retain its value.
A variable dimmed in a Class will behave exactly the same, inasmuch as a form is a specialized class.
A variable dimmed in a Module as public will be available to the entire projectâobjects, forms, other modules, everywhereâand will have life for the life of the application.
A variable dimmed in a Module as private will be available only to the code within that module. There is no way to access it from outside the module's code, but a routine within that module can pass the value of the private variable out to other processes in the following fashion:
Code:
Private pvtString As String
Public Function PassString() As String
PassString = pvtString ' Passes the value by changing the
' value of the Function
End Function
Public Sub Pass_String(ByRef TheVal As String)
TheVal = pvtString ' Passes the value by changing the
' value of the reference variable
End Sub
How big is this project?