I have researched, and read just about everything I could find on this. It's very likely that I have seen the solution to my problem, but fail to recognize it. It seems the forest is too thick for me.
I have written a dll in vb.net - VS2010. It works perfectly when used in a vb.net project. I have enabled the COM, etc. to allow it to work with VB6.
Up until I need the events, it works just as planned in VB6. But now trying to get the WithEvents part to work is where I'm completely lost!
My VB.Net dll raises an event once a time compare function becomes true (or equal). It also returns the actual time of the event.
In my VB6 project, using the WithEvents function requires the declaration be within a class module. I can't get my head around how this would/should work. As I stated earlier, many post I have read point to the fact it must be in a class module, but none address exactly how to accomplish this in a clean straight forward method. Well, at least what seems straight-forward to me, anyway.
The following code is how I make use of the dll prior to adding an event. All properties, and actions, etc. work correctly. This is located in a .bas module.
Public PT As New PrecisionTimer.PrecisionTimer
This is example of how it might be used on a form:
Private Sub Command3_Click()
Dim aa As Integer
aa = PT.SetTimerEvent(Val(Text6.Text))
Select Case aa
Case -1
OkToInitiate = True
Case False
OkToInitiate = False
End Select
End Sub
But now I need to react to the event within the dll. Here is the line in the VB.Net dll that raises the event:
RaiseEvent OTE(ActualTriggeredTime.ToString())
So, can someone assist me, I'm really having a lot of trouble figuring out how to accomplish this.
Thanks!
More Info:
@TnTinMn, To a point you are right, CM has never been my strong suit. Here is the code in MyClass:
Option Explicit
Public WithEvents PTM As PrecisionTimer.PrecisionTimer
Private Sub PTM_OTE(ByVal ActualTriggeredTime As Variant)
Dim aa As Integer
aa = 1
End Sub
Now the PTM_OTE sub can be deleted, and a new one will automatically appear, without the aa = 1 code of course.
In my Module1.bas:
Option Explicit
Public PT As New MyClass.PTM
Public OkToInitiate As Boolean
Do you see an error in my code?
In the Object Browser, I do see the OTE Event. At this point, I'm thinking I should be able to see PT in the Code Editor drop down in the upper left hand corner, but I don't?!?!
More info:
I added an additional function to the event routine in the VB.Net dll - a TriggeredFlag.
Public Sub OnTimedEvent(source As Object, e As ElapsedEventArgs)
'Other code including basic error handling
RaiseEvent OTE(ActualTriggeredTime.ToString())
TriggeredFlag = True
End Sub
Now when I use the dll in my vb6 project, I can monitor the TriggeredFlag. It does change as expected. Yet the Event doesn't seem to be received. I beleive the problem is in the VB6 code - the WithEvents statement (maybe) in the class module. Here is my entire Class Module:
Option Explicit
Public WithEvents PTM As PrecisionTimer.PrecisionTimer
Public Sub Class_Initialize()
Set PTM = New PrecisionTimer.PrecisionTimer
End Sub
Private Sub PTM_OTE(ByVal ActualTriggeredTime As String)
Dim aa As Integer
aa = 1
End Sub
Final additional info:
Thanks to all that assisted in resolving this! Here is what my Module1.Bas ended up as:
Option Explicit
Public PT As New PrecisionTimer.PrecisionTimer
Public DT As New DTParams
Public OkToInitiate As Boolean
In the General section of the form:
Option Explicit
Public WithEvents TimerEvents As PrecisionTimer.PrecisionTimer
The Form_load routine includes:
Set TimerEvents = PT
This is the TimerEvents_OTE routine:
Private Sub TimerEvents_OTE(ByVal ActualTriggeredTime As String)
'Fires when the "Timer Done" event fires
Call SetTimerText(ActualTriggeredTime)
End Sub
And finally, no Class Module was used.
Thanks again all!