Creating Events for a Formless Application

All applications contain events. For applications with forms, the forms package automatically creates controls that can handle events. For a formless application, you must dynamically create an event-aware control using the CreateObjectWithEvents function. The following code example shows how to create a control that responds to events.

Dim C1 as CECOMMCtl.Comm
Sub Main
[…code for the Sub Main…]
Set C1 = CreateObjectWithEvents(“CECOMM.Comm”, “C1_”)

App.WaitForEvents
[…code for the Sub Main waits here…]
[…and resumes here when an event calls EndWaitForEvents…]
End Sub

Public Sub C1_OnComm(…)
  […code for the OnComm event…]
App.EndWaitForEvents
End Sub

When you write event-driven code for a formless application, the procedure that calls WaitForEvents remains suspended until you call App.End or App.EndWaitForEvents. The App.EndWaitForEvents method immediately returns control to the next statement after the App.WaitForEvents statement. If your application is not waiting for events, the App.EndWaitForEvents statement has no effect, so use App.End.