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:[email protected]" & _
        "?subject=Developers Pad Error" & _
        "&body=" & strErrorMessage, _
        "", "", vbNormalFocus
End Sub

You might also like...

Comments

James Crowley James first started this website when learning Visual Basic back in 1999 whilst studying his GCSEs. The site grew steadily over the years while being run as a hobby - to a regular monthly audience ...

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“A computer lets you make more mistakes faster than any other invention in human history, with the possible exceptions of handguns and tequila” - Mitch Ratcliffe