Results 1 to 7 of 7

Thread: "On Error goto" help

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2007
    Location
    Tamworth, UK
    Posts
    82

    "On Error goto" help

    well, im creating a tool.
    And i've implemented some Error tools (On error goto..and what not)
    but i have a problem, If an error occours i want to show a msgbox - once that msgbox has been clicked it then exits the sub
    I've tried numerous ammount of ways all fail on me
    Someone please enlighten me! pls x[

    e.g.

    vb Code:
    1. Private Sub cmd1_Click()
    2. On Error GoTo 321
    3. Timer1.Interval = txtTimer.Text
    4. On Error GoTo 123
    5. Timer1.Enabled = True 'Start sending messages
    6. 123:
    7. MsgBox "Error123", vbInformation
    8. [B]exit sub[/B]
    9. 321:
    10. MsgBox "Error321", vbInformation
    11. End Sub
    Kankerflecken.

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Apr 2007
    Location
    Tamworth, UK
    Posts
    82

    Re: "On Error goto" help

    Quote Originally Posted by kingzl3y
    well, im creating a tool.
    And i've implemented some Error tools (On error goto..and what not)
    but i have a problem, If an error occours i want to show a msgbox - once that msgbox has been clicked it then exits the sub
    I've tried numerous ammount of ways all fail on me
    Someone please enlighten me! pls x[

    e.g.

    vb Code:
    1. Private Sub cmd1_Click()
    2. On Error GoTo 321
    3. Timer1.Interval = txtTimer.Text
    4. On Error GoTo 123
    5. Timer1.Enabled = True 'Start sending messages
    6. 123:
    7. MsgBox "Error123", vbInformation
    8. [B]exit sub[/B]
    9. 321:
    10. MsgBox "Error321", vbInformation
    11. End Sub
    *Note to self*
    bold tags in vbcode do NOT work.
    Kankerflecken.

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: "On Error goto" help

    You need to restruct how you are doing your error trapping and use only one On Error GoTo.

    In your error trap, you can stipulate what message box appears depending on the error. Example:
    vb Code:
    1. On Error GoTo ErrTrap
    2. 'your code
    3. Exit Sub
    4. ErrTrap:
    5. Select Case Err.Number
    6.      Case 13 'type mistmatch
    7.          Msgbox "You received a Type Mismatch Error"
    8.      Case 9 'subscript out of range
    9.          Msgbox "You received a subscript out of range error."
    10.      Case 91 'Object variable or with block not set
    11.          Msgbox "You receive a object variable of with block not set."
    12.      Case Else
    13.          Msgbox Err.Number & " " & Err.Description
    14. End Select
    15. End Sub

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Apr 2007
    Location
    Tamworth, UK
    Posts
    82

    Re: "On Error goto" help

    Awh, ok - that looks kinda straight forward
    (And yes, sorry - i made that example ..as an example.. hence why its soo crap (: )

    But, those error numbers
    Is there a **** in which is lists all the errors + error numbers?
    Danke
    Edit : ***? **** L I S T
    Edit2: w t f
    Last edited by kingzl3y; Apr 20th, 2007 at 05:42 AM.
    Kankerflecken.

  5. #5
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: "On Error goto" help

    You can find error numbers and their description in your local MSDN or from here:
    http://www.geocities.com/naseem_amja...ror_codes.html
    http://www.1delphistreet.com/URLSEO/...!1/anyname.htm

    But you don't need to know all those numbers. The Err object will help you there.

    Addins like MZTools and CodeSmart can autometically write error handler for you.:
    vb Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4.  
    5.         On Error GoTo Command1_Click_Err
    6.    
    7. 100    MsgBox "Some codes"
    8. 102    MsgBox 1 / 0 'This will generate an error
    9. 104    MsgBox "More Codes"
    10.    
    11.     Exit Sub
    12.  
    13. Command1_Click_Err:
    14.         MsgBox Err.Description & vbCrLf & _
    15.                "in Project1.Form1.Command1_Click " & _
    16.                "at line " & Erl, _
    17.                vbCritical + vbOKOnly, "You've Got An Error"
    18.  
    19. ' Note: "Erl" will not work if you don't have line-numbers in your code.
    20. Resume Next ' This will run the 3rd msgbox. Comment this line and see what happens
    21. End Sub

    Edit: Can't you understand, the system in trying to stop you from posting those words (and trying to protect you from getting banned ) ?
    Last edited by iPrank; Apr 20th, 2007 at 05:56 AM.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: "On Error goto" help

    If you listed every possible error number your error trap would go on for miles. So, I would suggest taking iPrank's approach.

    Another caution.....don't use vbCritical as a msgbox icon. It tends to scare the bejesus out of people. Typically, I use vbExclamation for errors, vbQuestion for Yes/No msgbox's and vbInformation for everything else.

  7. #7
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: "On Error goto" help

    Quote Originally Posted by Hack
    Another caution.....don't use vbCritical as a msgbox icon. It tends to scare the bejesus out of people.

    Possibly the best design tip ever !
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


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