>Option Explicit > >Public cEventname As String, Value As Variant > >Public Event SomethingHappened(ByVal cEventname As String, ByVal Value As Variant) > >Public Sub FireEvent(ByVal tEventName As String, ByVal tEventValue As Variant) > >cEventname = tEventName >Value = tEventValue >RaiseEvent SomethingHappened(cEventname, Value) > >End Sub >>
>When necessary call FireEvent method and pass necessary parameters like: > >myComObject.FireEvent("PROGRESSBAR_RESET") >' >' >' > >myComObject.FireEvent("SHOWNAME", some_name_here) >' >myComObject.FireEvent("PROGRESSBAR_UPDATE", yourvalue_here) >>
>* Test form code >Option Explicit > >Private WithEvents oMyCom As oMyCOM 'Declare the variable using WithEvents keyword >'which will connect the events > >Private Sub Form_Initialize() > Set oMyCom = New oMyCom 'Create your COM object >End Sub > > >Private Sub Form_Terminate() > oMyCom = Nothing > 'Reset the object reference to the COM module >End Sub > > >Private Sub oMycom_SomethingHappened( _ >ByVal tEventname As String, _ >ByVal tEventValue As Variant) > > If tEventname = "PROGRESSBAR_RESET" Then > ShapeBar.Tag = tEventValue > 'reset the progress bar > End If > > If tEventname = "SHOWNAME" Then > lblLastName.Caption = tEventValue > 'Show the current person name processed > 'in the COM module > End If > > If tEventname = "PROGRESSBAR_UPDATE" Then > ShapeBar_SetValue (tEventValue) > End If > > > If tEventname = "ERROR" Then > MsgBox (tEventValue) > End If > >End Sub > >Private Sub cmdProcess_Click() > Call oMyCom.Process1 > ' Run some process in VFP COM module >End Sub > >Private Sub ShapeBar_SetValue(ByVal Value As Variant) >Static nWidth >Dim nPercent, nTotal >nTotal = Val(ShapeBar.Tag) >If nTotal > 0 Then > nPercent = Int(Value / Val(ShapeBar.Tag) * 100) > ShapeBar.Width = Int(nPercent / 100 * _ > (ShapeUnder.Width - 15)) > lblPercent.Caption = CStr(nPercent) & "%" >End If > >End Sub >