Results 1 to 8 of 8

Thread: Please Help VB6

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2014
    Posts
    66

    Please Help VB6

    Hello All,

    Code:
    Private Sub Command1_Click()
    On Error GoTo ERROR_HANDLER
    MsgBox "Hello"
    
    ERROR_HANDLER:
    MsgBox Err.Description, vbCritical
    End Sub
    This Code is correct ??


    Thanks

  2. #2
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Please Help VB6

    You need an Exit Sub after MsgBox "Hello". Really no need for error handling for this but anyway that's what you need to have else control falls into error handler routine.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  3. #3
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Please Help VB6

    Just to be clear you need an Exit Sub just before the Error_Handler: label so if there were more lines of code after msgbox the Exit statement would be after those lines as well.
    Code:
    Private Sub Command1_Click()
    On Error GoTo ERROR_HANDLER
    MsgBox "Hello"
    '
    '
    ' possibly many more lines of code
    '
    '
    
    Exit Sub ' this allows the sub to exit if no error has occurred and prevents the code in the error handler portion from executing
    ERROR_HANDLER:
    MsgBox Err.Description, vbCritical
    End Sub

  4. #4
    Hyperactive Member
    Join Date
    Jun 2014
    Location
    Lahore, Pakistan
    Posts
    450

    Re: Please Help VB6

    Yes exit sub is the option.
    P.S. why are you using a err handler for a simple msgbox O_o

  5. #5
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    Re: Please Help VB6

    It's a question about a concept.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Apr 2014
    Posts
    66

    Re: Please Help VB6

    Thanks All...

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Apr 2014
    Posts
    66

    Re: Please Help VB6

    Mr.HAMZA
    Thanks

    I'm showing little model for you..
    Mr.Arnoutdv is right...

    Thanks Again..

  8. #8
    Hyperactive Member
    Join Date
    Jun 2014
    Location
    Lahore, Pakistan
    Posts
    450

    Re: Please Help VB6

    Quote Originally Posted by kamalkumar2023 View Post
    Mr.HAMZA
    Thanks

    I'm showing little model for you..
    Mr.Arnoutdv is right...

    Thanks Again..
    Ok bro.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width