Trying to raise an event in an ActiveX control from a module (.bas file).

Been trying to create a timer control that will go past the 1 minute limit of the vb6 timer.ocx. The Windows API SetTimer will do this. But wanted to create an Active X timer control that will raise it's own Timer Event.


In the module.bas file:

Public Sub TimerProc (ByVal hWnd as Long, ByVal uMsg as Long, ByVal idEvent as Long, ByVal lpFunc as long)
' This is where I would like to somehow activate the event in the 
' ActiveX control code. But am stumped. I was wondering if it were
' possible to change a property value in the ActiveX Control at this
' portion of the code? If so, then code could be written in the 
' ActiveX control with the Property Change to fire the Timer event.
End Sub

Any ideas? This is a hard core problem. Who has a hard core solution?

Thanks,

Hank

You want hardcore, these guys have hardcore... http://www.thescarms.com/VBasic/timer.aspx

Good Luck

Thanks, vb5

They have some interesting stuff, but not exactly what I'm looking for.

I figured out one way to do it. But not exactly what I want either. I have to add a class module with a friend method and event to the project which can be instantiated in the standard bas module. Then the Class Module Method can fire its own event independent of the User Control. However, have to instantiate the class module for the client besides adding the user control to the client app.

What I want is the event to fire directly from the User Control so I don't have to instantiate the Class Module in the client app.

Edited 6 Years Ago by hkdani: n/a

Finally, figured it out.

Needed to declare a reference in the Standard bas module to the Control. But the control will not instantiate inside the bas module.

So, you instantiate the reference in the control itself by using the following syntax:

' Code for Module
Public MyTimer as UserControl1
Public sub Timer Proc (ByVal hWnd as long, ......)
       MyTimer.FireEvent
end Sub
' Code in User Control

Public Property Let Enabled(ByVal New_Enabled As Boolean)
   m_Enabled = New_Enabled
   Set MyTimer = Me
   TimerProc
   PropertyChanged "Enabled"
End Property

And then once the MyTimer Variable (Really a reference to the physical address of the User Control) has been set to the UserControl itself, then the event will fire inside the user control. But just notice that MyTimer has to be instantiated before calling the TImerProc function in the Standard .bas module.

Why do you have to use a standard bas module?

Because when using the TimerProc function you have to use the Pointer Value to a function. And VB6 only allows that in a standard bas module:

Using the AddressOf Keyword
Any code you write to call a function pointer from Visual Basic must be placed in a standard .BAS module — you can't put the code in a class module or attach it to a form. When you call a declared function using the AddressOf keyword, you should be aware of the following conditions: (MSDN)

Edited 6 Years Ago by hkdani: n/a

In a very bad explanation... The reason you need to use a bas module is because both the form and class modules are considered to be private and thus protected code and when compiled will resist information being injected into these areas of the executable, as that is what the callback is doing, injecting information into the address space of another process...

Good Luck

This question has already been answered. Start a new discussion instead.