Current value in Sub:
vGlobalDim = Cat - Updated by Sub
vGlobalNoDim = Dog - Updated by Sub
vLocalDim = Apple - Updated by Sub
vLocalNoDim = Orange - Updated by Sub
vTempDim = Banana - Updated by Sub
vTempNoDim = Grape - Updated by Sub
Current value after Sub:
vGlobalDim = Cat - Updated by Sub
vGlobalNoDim = Dog - Updated by Sub
vLocalDim =
vLocalNoDim =
vTempDim = Bird
vTempNoDim = Grape - Updated by Sub
Here are my comments about this example:
There are 6 variables in this example: vGlobalDim, vGlobalNoDim, vLocalDim, vLocalNoDim, vTempDim, and vTempNoDim.
The behavior of vGlobalDim and vGlobalNoDim is pretty consistent, defined in the main code; and accessible
in the procedure. "Dim" or not makes no difference.
The behavior of vLocalDim and vLocalNoDim is also consistent, define in the procedure, not accessible in the main code.
Notice that vLocalDim and vLocalNoDim are empty in the "after Sub" message.
The behavior of vTempDim and vTempNoDim shows that "Dim" statement forces vTempDim to a new local variable.
So we have two variables of the same name, one in the main code, and one in the procedure. This is why vTempDim
still has the old value after the subroutine call.