Using Bugz Scout from Visual Basic

To use BugzScout from any ActiveX host, follow these steps:

1. Create an instance of the BugzScoutCtl object. Because BugzScout submits its bug reports asynchronously over HTTP you must ensure that this object does not go out of scope before the success or failure events are posted.

2. Set the properties of the object to represent the bug that you want entered in the FogBugz database.

3. Call the SubmitBug method.

Here's an example of using BugzScout from a Visual Basic 6.0 application: Option Explicit

' Declare the BugzScout object at the form level so ' that it will persist and we can trap its events Dim WithEvents scout As BUGZSCOUTLib.BugzScoutCtl

' User email. We'd prompt for this during setup and

' store it somewhere.

Dim strUserEmail As String

Private Sub cmdMonitor_Click() On Error GoTo ErrHandler

' Do some actual work here

ExitHere: Exit Sub


' Call our bug-handling routine HandleError ("cmdMonitor_Click") Resume ExitHere

End Sub

Private Function HandleError(strCallingFunction As String) ' Generic handler for errors ' Submits the error-causing routine to FogBugz If scout Is Nothing Then

Set scout = New BUGZSCOUTLib.BugzScoutCtl With scout

.Project = "ServiceMonitor" .Area = "Misc"

.URL = "" .UserName = "Robert Evers"

.DefaultMessage = "The error has been sent to MegaUtilities" End With End If

' Submit the bug scout.SubmitBug "Error in " & strCallingFunction, "MainForm", _ strUserEmail, False

End Function

Private Sub scout_Failure(ByVal sError As String)

Debug.Print sError End Sub

Private Sub scout_Success(ByVal sContents As String)

Debug.Print sContents End Sub

This code sample shows a generic function (HandleError) that you'd call from anywhere in your code. This function is responsible for initializing the BugzScoutCtrl object and setting its properties, then calling the SubmitBug method. SubmitBug takes four parameters:

• A string parameter that will be the title of the case created in FogBugz.

• A string parameter containing any extra information you care to pass. This parameter will be appended to the notes of the case.

• A string parameter that is the e-mail address of the person submitting the case. This will be used for the correspondent link on the case.

• A Boolean parameter that you can set to True to force the creation of a new case or False to allow this report to be appended to an otherwise identical existing case.

When the ScoutSubmit method finishes its work, the object will fire one of two events, Success or Failure. Success fires if the communication with the FogBugz server actually happens. It returns with a simple XML payload. It contains either an element called Success or one called Error, similar to these examples:

<Success>Thank you for submitting your bug!</Success> <?xml version="1.0"?>

<Error>No username found: George Swenson</Error>

The Success payload returns with either the DefaultMessage property provided when the bug was submitted, or a message added by someone on the bug server, such as "This bug has been fixed in version 2.0. Please upgrade." If you choose, you can show this to your users after the bug was submitted to give them an idea of why that bug happened or how to fix it. If there's an error after communicating with the server, the Error element contains the error message.

The Failure event fires if the communication with the server failed. For instance, this can happen because the URL field was not set correctly.

0 0

Post a comment