FireEvent Example (Visual Basic)

   Applies To

This example shows how to define the data passed with a Visual Studio Analyzer event as well as the process of calling FireEvent to generate the event. Refer to ISystemDebugEventFire Example (Visual Basic) to see this code in context.

Public Sub fire(e As String)
   
   'This is one of the functions that fires the VSA events. This function
   'fires the events with default source information and no other info.
   
   'First you need to initialize the array that you will use to pass
   'data. Since you are not passing any data this time, the array will be
   'one element; that is, an empty string.
   Const MAXVALUE = 1
   Dim Keys(1 To MAXVALUE) As Variant, Values(1 To MAXVALUE) As Variant
   Keys(1) = ""
   Values(1) = ""
   lCount = MAXVALUE
   
   'The cVSAEventDefaultSource flag causes source information to be
   'stamped into the event by the LEC.
   lFlags = cVSAEventDefaultSource
   
   Debug.Print "Firing :" + e
   
   'This is the statement that fires the events.
   IEC.FireEvent e, Keys, Values, lCount, lFlags
   
End Sub

Public Sub fire2(e As String)

   'This is another function that fires the VSA events. This function
   'fires the events with default parameter information and other info
   'as well.
   
   'First you need to initialize the array that you will use to pass
   'data. Since you are passing some data, you will need an array of as
   'many elements as you are passing.
   Const MAXVALUE = 5
   Dim Keys(1 To MAXVALUE) As Variant, Values(1 To MAXVALUE) As Variant
   lCount = MAXVALUE
   
   'Using the cVSAEventDefaultSource or CVSAEventDefaultTarget
   'flags allow the IEC and LEC to stamp all default data into the event.
   'Use the cVSAEventDefaultSource flag for Call/Return events from the
   'caller.
   'Use the cVSAEventdefaultTarget flag for the Enter/Leave events from
   'the callee.
   lFlags = cVSAEventDefaultSource

   Keys(1) = PARAM_Arguments   'Arguments you may want to know were
                              'passed
   Keys(2) = PARAM_ReturnValue 'ReturnValue of the corresponding event
   Keys(3) = PARAM_Exception   'Exception of the corresponding event
   
   'The following are custom fields that are being added to the stock
   'events. The string in the Keys argument is used as the field name.
   Keys(4) = "Custom Text Parameter"
   Keys(5) = "Custom Value Parameter"
   
   Values(1) = "Arg1 = 2, Arg2 = 5"   'Sample arguments
   Values(2) = "Return Value = 25"    'Sample Return value
   Values(3) = "Oops: Out of Memory!"  'Sample Exception data
   
   'The following are values for the custom fields that were defined
   'above.
   'Note that all values are passed as strings.
   Values(4) = "Frank Codeslinger's Age"
   Values(5) = "42"
   
   Debug.Print "Firing :" + e
   
   'This is the statement that fires the events.
   IEC.FireEvent e, Keys, Values, lCount, lFlags
End Sub