tl;dr.
I thought a thing should be on the stack but the procedure exits before going back to the caller and takes itself off the stack like it's supposed to. There is no bug.
======================================================
I posted my CallStack demo in the code bank and I've been trying to clean it up to repost and found a pretty nasty bug.
Specifically I am creating an object in a procedure that when it goes out of scope, the object is destroyed and it pops itself off the callstack.
But what's happening is that it's doing that when I think it's still supposed to be in scope.
What am I doing wrong?
Also happening when cmdExit_Click is called so neither the Hourglass or cmdExit_Click event are on the stack when they should be.
The CallStack is behaving as it should. I single-stepped through it and it's incrementing the array of calls properly.
And AddToCount is getting put on the stack properly.
So what I am getting is this:
52440.283 frmCallStackDemo.cmdStartCounting(Private Sub)
52440.283 frmCallStackDemo.AddToCount(Private Sub)
' 50 more AddToCount calls follow
What I should be getting is this:
52440.283 frmCallStackDemo.cmdStartCounting(Private Sub)
#####.### cHourglass.Hourglass(Public Sub)
51 stacks of AddToCount
##### frmCallStackDemo.cmdExit_Click(Private Sub) ' Ignore this. This isn't a problem. It shouldn't be on the stack because it exits and takes itself off the stack before coming back to the cmdStartCounting sub. so that's not an issue. It's just the hourglass.
Code:Private Sub cmdStartCounting_Click() Dim m_CallStacker As New cCallStacker Dim Hourglass As New cHourglass m_CallStacker.Add Me.NAME & ".cmdStartCounting(Private Sub)" Hourglass ' Right here. This is going out of scope immediately after being called instead of when the Sub exits. ' Hourglass cursor is still active but it called its class_terminate event already but still shows an hourglass. Makes no sense. ' When this procedure exits it turns the mousepointer back like it should. It's weird. nCount = 0 AddToCount cmdExit_Click End Sub '====================== Private Sub AddToCount() Dim m_CallStacker As New cCallStacker m_CallStacker.Add Me.NAME & ".AddToCount(Private Sub)" If nCount = 50 Then Exit Sub ' Exit condition. Sleep 25 ' Slow it down. nCount = nCount + 1 lblCount.Caption = nCount DoEvents ' Refresh the Label. AddToCount ' Recursively call self to Pump Up the CallStack, baby! End Sub ====================== ' cHourglass Class: Option Explicit Public Sub Hourglass(Optional ByVal SetHourglass As Boolean = True) ' Default Class Property. Dim m_CallStacker As New cCallStacker m_CallStacker.Add NAME & ".Hourglass(Public Sub)" If SetHourglass = False Then Screen.MousePointer = vbNormal Else Screen.MousePointer = vbHourglass End If DoEvents End Sub Private Sub Class_Terminate() Dim m_CallStacker As New cCallStacker m_CallStacker.Add NAME & ".Class_Terminate(Private Sub)" Screen.MousePointer = vbNormal End Sub




Reply With Quote