Chapter 1 -- 13
Discover ActiveX Automation for your labeling software
For example, add the following code to the
MyDoc
_
ProgressPrint
event procedure:
Private Sub MyDoc_ProgressPrinting (ByVal Percent as
integer,Cancel as integer)
lblPercentDone.caption = CInt (100 * Percent) & “%”
DoEvents
If mblnCancel Then Cancel = True
End Sub
Whenever the
ProgressPrinting
event is raised, the event
procedure displays the percent complete in a Label control. The
DoEvent
statement allows event processing to occur. The
module-level variable mblnCancel is set to True, and the
MyDoc_ProgressPrinting
event then tests it and sets the
ByRef Cancel argument to True.
When you declare a variable
WithEvents
at design time, there
is no object associated with it. A
WithEvents
variable is just like
any other object variable. You have to create an object and
assign a reference to the object to the
WithEvents
variable.
Add the following code to the
Form_Load
event procedure to
create the
LabelManager2.Application
.
Private Sub Form_Load()
Set MyApp = New LabelManager2.Application
Set MyDoc = MyDoc.Documents.Add (”My Document”)
MyApp.EnableEvents = True
End Sub
When the code above is executed, Visual Basic creates a
LabelManager2.Application
and a new document called “My
Document” then connects its events to the event procedures
associated with
MyDoc
. From that point on, whenever the
MyDoc
raises its
ProgressingPrinting
event, the
MyDoc_PrintProgressing
event procedure will be executed.
Connecting a
WithEvents
variable to an
object