• ** There has been a recent site upgrade. Please clear your browser cache to avoid issues. **
  • New forum feature - post voting and best solution

    Check out this thread for the details: https://www.access-programmers.co.uk/forums/threads/new-forum-feature-post-voting-and-best-answer.314134/

    This new feature looks great to me! :)

  • We now have 3 forum themes

    Go for the default (light) theme, Shades of Grey or Shades of Blue. I just added the Blue one.

    The thread about it is here: https://www.access-programmers.co.uk/forums/threads/new-forum-theme-shades-of-blue.314136/

End is a showstopper (1 Viewer)

Guus2005

AWF VIP
Local time
Today, 13:10
Joined
Jun 26, 2007
Messages
2,584
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

Registered User.
Local time
Today, 07:10
Joined
Apr 9, 2015
Messages
3,622
I never use END. Never needed to. Exit the sub/function does it all.
 

kevlray

Registered User.
Local time
Today, 04:10
Joined
Apr 5, 2010
Messages
854
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, Former MVP, Retired SysAdmin
Staff member
Local time
Today, 06:10
Joined
Feb 28, 2001
Messages
17,989
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, 13:10
Joined
Jun 26, 2007
Messages
2,584
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:10
Joined
Mar 14, 2017
Messages
2,372
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