Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 12,139 times

Related Categories

Report an Error to the Developer

When producing a product, you obviously want to be told about any problems the user finds. However, unless there is an easy way to do this, it is unlikely they will bother. The code below enables you to provide the option to automatically email the developer (you) the error.

Public Declare Function ShellExecute Lib "shell32.dll" _
       Alias "ShellExecuteA" _
       (ByVal hwnd As Long, _
        ByVal lpOperation As String, _
        ByVal lpFile As String, _
        ByVal lpParameters As String, _
        ByVal lpDirectory As String, _
        ByVal nShowCmd As Long) As Long

Private Sub cmdCreateError_Click()
On Error GoTo errhandler
    '// create an error
    Err.Raise 13
errhandler:
    ReportError "An Error Occured" & vbCrLf & "Err " & Err & vbCrLf & Error
End Sub

Private Sub ReportError(ByVal strErrorMessage As String)
   
    If MsgBox(strErrorMessage & vbCrLf & vbCrLf & "Do you want to email a developer with this error?", vbCritical + vbYesNo) = vbNo Then Exit Sub
    'Replace CRLF with %0d token to give proper line breaks
    strErrorMessage = Replace(strErrorMessage, vbCrLf, "%0d")
   
    ShellExecute hwnd, "open", "mailto:support@vbweb.f9.co.uk" & _
        "?subject=Developers Pad Error" & _
        "&body=" & strErrorMessage, _
        "", "", vbNormalFocus
End Sub

James first started writing tutorials on Visual Basic in 1999 whilst starting this website (then known as VB Web). Since then, the site has grown rapidly, and James has written numerous tutorials, articles and reviews on VB, PHP, ASP and C#. In October 2003, James formed the company Developer Fusion Ltd, which owns this website, and also offers various development services. In his spare time, he's a 3rd year undergraduate studying Computer Science in the UK. He's also a Visual Basic MVP.

Comments

  • Quick fix

    Posted by meow on 24 Jan 2006

    For use in a module, replace hwnd with vbModal in the ShellExecute line and call ReportError from where you want the error reported

  • Posted by GFORCE on 30 Mar 2005

    hey, i tried to e-mail you but you e-mail says its hidden in you profile

    well that worked, puting it private instead of public, but theres one thing..
    i made the button cmdCreateError to see if it...

  • Posted by James Crowley on 30 Mar 2005

    Try changing "Public Declare Function" to a private one :)

  • Posted by GFORCE on 30 Mar 2005

    when i put it in my form, it gives me a
    Compile Error:
    "Constants, fixed-length string, arrays, user-defin type and declare statements not allowed as public members of object modules."

    and it hi...

  • Posted by James Crowley on 30 Mar 2005

    You should just be able to put it in a form - bearing in mind this is VB 6 code not VB.NET. What error do you get?