M
MikeB
I'm trying to use a variable to track the depth of nesting of
procedures, but am having difficulty. I thought I understood this from
the help, but apparently not.
Option Compare Database
Option Explicit
Sub MainSub()
Dim intNest As Integer
intNest = 0
Debug.Print intNest
SubNest1 intNest
Debug.Print intNest
SubNest2 intNest
Debug.Print intNest
End Sub
Sub SubNest1(intNest As Integer)
Debug.Print "." & intNest
intNest = intNest + 1
Debug.Print "." & intNest
End Sub
Sub SubNest2(intNest As Integer)
Debug.Print ".." & intNest
intNest = intNest + 1
Debug.Print ".." & intNest
SubSubNest2 intNest
Debug.Print ".." & intNest
End Sub
Sub SubSubNest2(intNest As Integer)
Debug.Print "+++" & intNest
intNest = intNest + 1
Debug.Print "+++" & intNest
End Sub
What I get from this is;
0
..0
..1
1
...1
...2
+++2
+++3
...3
3
What I was hoping to get was:
0
..0
..1
0
...0
...1
+++1
+++2
...1
0
How do I define variables so that they are local in scope to the
procedure using them? I tried using Private, but that wasn't allowed
inside a Sub.
Thanks
procedures, but am having difficulty. I thought I understood this from
the help, but apparently not.
Option Compare Database
Option Explicit
Sub MainSub()
Dim intNest As Integer
intNest = 0
Debug.Print intNest
SubNest1 intNest
Debug.Print intNest
SubNest2 intNest
Debug.Print intNest
End Sub
Sub SubNest1(intNest As Integer)
Debug.Print "." & intNest
intNest = intNest + 1
Debug.Print "." & intNest
End Sub
Sub SubNest2(intNest As Integer)
Debug.Print ".." & intNest
intNest = intNest + 1
Debug.Print ".." & intNest
SubSubNest2 intNest
Debug.Print ".." & intNest
End Sub
Sub SubSubNest2(intNest As Integer)
Debug.Print "+++" & intNest
intNest = intNest + 1
Debug.Print "+++" & intNest
End Sub
What I get from this is;
0
..0
..1
1
...1
...2
+++2
+++3
...3
3
What I was hoping to get was:
0
..0
..1
0
...0
...1
+++1
+++2
...1
0
How do I define variables so that they are local in scope to the
procedure using them? I tried using Private, but that wasn't allowed
inside a Sub.
Thanks