tiredofit
Well-known Member
- Joined
- Apr 11, 2013
- Messages
- 1,924
- Office Version
- 365
- 2019
- Platform
- Windows
My understanding of a variable's lifetime is that if it is declared at the module level, it retains its vaue, even after the sub has finished running.
So in my following code, after first running Test1 to the end, if I run Test2, the messagebox shows the value of 10, as expected.
What I don't understand is if I run Test1 through to the end, then type:
in the Immediate window, I get a blank value.
I thought the variable "retains" its value even after Test1 has finished running?
Thanks
So in my following code, after first running Test1 to the end, if I run Test2, the messagebox shows the value of 10, as expected.
Code:
Dim a As Integer
Sub Test1
a = 10
Msgbox a
End Sub
Sub Test2
Msgbox a
End Sub
What I don't understand is if I run Test1 through to the end, then type:
Code:
? a
in the Immediate window, I get a blank value.
I thought the variable "retains" its value even after Test1 has finished running?
Thanks