GentleGeek
New Member
- Joined
- May 31, 2009
- Messages
- 8
I have "variable scope problems".
I have read the help, and I think I understand it, and I have my code organized so that I should have no scope problems.. But I do.
Mostly, my problem seems to occur when I have a Function or Subroutine procedure which calls another Function or Subroutine. Variables which are declared in the Outer Sub are not available to the inner Sub. "That's not right!!" They should be available for the entire scope of the Outer Sub.
Here is an example:
The VBA compiler pops up a Message Box saying- "Compile Error Variable Not Defined". When I move the Message Box, I see that MyVar1 in "Sub Inner1()" is highlighted (blue background, white text). When I "Esc" out of the Message Box, I see that "Sub Inner1()" is highlighted in yellow.
What's wrong with this picture?
Thanks for all help!
I have read the help, and I think I understand it, and I have my code organized so that I should have no scope problems.. But I do.
Mostly, my problem seems to occur when I have a Function or Subroutine procedure which calls another Function or Subroutine. Variables which are declared in the Outer Sub are not available to the inner Sub. "That's not right!!" They should be available for the entire scope of the Outer Sub.
Here is an example:
Code:
Option Explicit
Sub Outer()
Dim MyVar1 As Single, MyVar2 As Single, MyVar3 As Single, MyVar4 As Single
Inner1
Inner2
End Sub
Sub Inner1()
MyVar1 = MyVar1 + MyVar2
End Sub
Sub Inner2()
MyVar3 = MyVar3 + MyVar4
End Sub
What's wrong with this picture?
Thanks for all help!