Results 1 to 6 of 6

Thread: pinpointing an error

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2003
    Posts
    601

    pinpointing an error

    How can you find which line of code an error occurs on without the compiler? On some computers, the program works fine. On other computers, it gets a Type Mismatch error, and on other computers, it gets a overflow error.

    I could add a counter after everyline then pop up a message box with the counter # to find out where exactly the error is occuring, but is there an easier way?

  2. #2
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: pinpointing an error

    Download MZ-Tools, it has a feature to add line numbers, and error handler. You can make it tell you at what line the error occured even when the code is compiled, and it's very easy to use.

  3. #3
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: pinpointing an error

    well you cant make it to find your line with the error because its encrypted...heres how i do it:

    VB Code:
    1. on error goto errhandler
    2.  
    3. errhandler:
    4. error:
    5.     If Len(Err.Description) & Len(Err.Source) = 0 Then
    6.     Print vbNullString
    7.     Else
    8.      MsgBox Err.Description & " Source : " & Err.Source
    9.      End If

  4. #4
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: pinpointing an error

    i have mztools and ive never seen that feature anywhere, being able to see what line it is on after being compiled

  5. #5
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: pinpointing an error

    Check picture attached...
    Attached Images Attached Images  

  6. #6
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: pinpointing an error

    Quote Originally Posted by psychotomus
    How can you find which line of code an error occurs on without the compiler? On some computers, the program works fine. On other computers, it gets a Type Mismatch error, and on other computers, it gets a overflow error.

    I could add a counter after everyline then pop up a message box with the counter # to find out where exactly the error is occuring, but is there an easier way?
    You should always add error handlers to every new procedure you write.
    The following is just a quick sample so you can modify:
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim a%
    3.  
    4. On Error GoTo ErrHandler
    5.  
    6.     a = 1 / 0
    7.     Exit Sub
    8.  
    9. ErrHandler:
    10. '-----------
    11.  
    12.     MsgBox "An error occured in" & vbNewLine & _
    13.            "Module: Form1" & vbNewLine & _
    14.            "Procedure: Command1_Click" & vbNewLine & _
    15.            "Error Number: " & Err.Number & vbNewLine & _
    16.            "Error Desc: " & Err.Description
    17.     Err.Clear
    18.     Resume Next 'if you need to
    19.  
    20. End Sub

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