Crash when Stopping All Code Execution (1 Viewer)

craigachan

Registered User.
Local time
Today, 14:33
Joined
Nov 9, 2007
Messages
282
I'm getting a application crash after I try to stop all code.

Code:
Private Function Func1()
  on error goto Func1Err
  
  if something then call Func2
  Do some more stuff

Func1Exit:
   Exit Function
Func1Err:
   msgbox "Error Message"
   resume Func1Exit
End Function

Private Function Func2()
   on error goto Func2Err

   Do some stuff...
   If something happens then gosub StopAll

Func2Exit:
   Exit Function
Func2Err:
   Msgbox "Error Message"
   resume Func2Exit

StopAll:
  Msgbox "Getting Ready to Stop"
  End

end function

Everything runs well and my code gets to msgbox "Getting Ready To Stop", but then crashes the application. I don't want my code to return to do other things in Func1(). I want everything to stop. Any idea why this is happening? I'm stumped. Thanks for any help.
 

TJPoorman

Registered User.
Local time
Today, 15:33
Joined
Jul 23, 2013
Messages
402
Set your second function to return as a Boolean then set it to false if you want to stop. Like this:
Code:
Private Function Func1()
On Error GoTo Func1Err

If something Then
    [COLOR="red"]If Func2 Then[/COLOR]
        Do some more stuff
    End If
End If

Func1Exit:
    Exit Function
Func1Err:
    MsgBox "Error Message"
    Resume Func1Exit
End Function

Private Function Func2()[COLOR="Red"] As Boolean[/COLOR]
On Error GoTo Func2Err

Do some stuff...
If something happens then gosub StopAll

Func2Exit:
    Func2 = True
    Exit Function
Func2Err:
    MsgBox "Error Message"
    Resume Func2Exit
StopAll:
    MsgBox "Getting Ready to Stop"
    Exit Function
End Function
 

craigachan

Registered User.
Local time
Today, 14:33
Joined
Nov 9, 2007
Messages
282
Yes that took care of it perfectly. There is something to learn every day. Thank you for your expert advise.
 

Users who are viewing this thread

Top Bottom