CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Guest

    on error goto whatever

    how come when i put on erro goto error, then under the error: i put msgbox "error" to test things out, why does it message box me "error" even though theres been no error


  2. #2
    Join Date
    Feb 2000
    Location
    Indiana
    Posts
    308

    Re: on error goto whatever

    My guess is that you don't have Exit Sub before your error handler. Does your code look like this?

    public Sub Foo()
    on error GoTo error 'I wouldn't use a keyword for a label. How about "on error Goto Handler"?
    'Do some stuff that may cause an error
    ExtProc:
    Exit Sub
    error:
    MsgBox "error"
    resume ExtProc
    End Sub





  3. #3
    Join Date
    Dec 1999
    Location
    Texas
    Posts
    96

    Re: on error goto whatever

    I'm not sure I understand your problem EXACTLY, but if I am right you have some code like this:

    public Sub MySub()
    '
    on error Goto MyError
    '
    'Some code here...
    '
    MyError:
    MsgBox "error"
    End Sub



    And everytime you run the code, you still get the messagebox telling you that an error has occurred. Am I right? If I am, the solution is to add an Exit Sub right before the MyError (or whatever yours is named) label. For example, try this:


    public Sub MySub()
    '
    on error GoTo MyError
    '
    'Some code here...
    '
    Exit Sub
    '
    MyError:
    MsgBox "error"
    End Sub




    Hope this helps,
    Rippin


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

Featured