End is a showstopper (1 Viewer)

Guus2005

AWF VIP
Local time
Today, 12:40
Joined
Jun 26, 2007
Messages
2,645
Just dropping it here: FYI:

I didn't know it and never used it but the End statement is a real showstopper.
Code:
Public Sub trythis() As Boolean

    On Error GoTo trythis_Error

    Debug.Print 1 / 0
    
    On Error GoTo 0
    Exit Function

trythis_Error:
    End
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure trythis of Function Game_Control"
    Resume Next
End Function
When the End statement is encountered all code execution stops, waiting for the next event. Even in nested for end loops.
So when you have a callstack, you won't after this command: End

You can use it when you don't want the error code to bubble up?
Can't think of a good purpose for this command. The example code is not a good example of what it does.

Share & Enjoy!
 

Ranman256

Well-known member
Local time
Today, 07:40
Joined
Apr 9, 2015
Messages
4,337
I never use END. Never needed to. Exit the sub/function does it all.
 

kevlray

Registered User.
Local time
Today, 04:40
Joined
Apr 5, 2010
Messages
1,046
I think I have used end once. Do not remember why, But definately needed the code to stop for a reason.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 06:40
Joined
Feb 28, 2001
Messages
26,996
Well, if you think about it, there is

End If
End Sub
End Type
End Do
End
variable (used in a For variable loop)
and of course a long list of others.

If you use the properly qualified "End" it ends some structure. If you DON'T qualify the End then I guess it becomes suicidal and decides to end it all.
 

Guus2005

AWF VIP
Local time
Today, 12:40
Joined
Jun 26, 2007
Messages
2,645
If you use the properly qualified "End" it ends some structure. If you DON'T qualify the End then I guess it becomes suicidal and decides to end it all.
That's probably why!
I think i'm going to use it as my *safe* word from now on!
 

Isaac

Lifelong Learner
Local time
Today, 04:40
Joined
Mar 14, 2017
Messages
8,738
Reminds me a little of Stop, except Stop has the usefulness of resulting in Break mode. Whereas End I can't think of much reason to use it over Exit [sub/function], other than, you might have Exit Sub in other places in your code and for some brief ad-hoc purpose, might put End just to visually differentiate it from your deployed code or something.
 

Users who are viewing this thread

Top Bottom