Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
In the scenario you give, it appears that each sub is in a separate module and you've declared keyvar in each. The danger here is knowing which version of keyvar is being referenced at any given time. If you run procedure Main and check the value of keyvar, it will be blank (actually, whatever value it contains when Main runs). This is because within each module, an unqualified reference to keyvar will be to the one declared in that module. Try this modified version of your code to see what I mean:with what i am referring to, this program would end with keyvar having the value "hello" in sub1 and "neither" in sub2, instead of the result passing universally to both
'---------- Module1
Public KeyVar
Sub Main
Call ClearVars 'ensures all variables "blank"
Call Test1
Call Test2
MsgBox "Module1.KeyVar = " & Module1.KeyVar & vbLf & "Module2.KeyVar = " & Module2.KeyVar & vbLf & "Module3.KeyVar = " & Module3.KeyVar
End Sub
Sub ClearVars()
KeyVar = ""
Module2.KeyVar = ""
Module3.KeyVar = ""
End Sub
'------------ Module2
Public KeyVar
Sub Test1
If KeyVar = "" Then
KeyVar = "hello"
End If
End Sub
'------------ Module3
public KeyVar
Sub Test2
KeyVar = "neither"
Call Test1
End Sub