By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,022 Members | 1,198 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,022 IT Pros & Developers. It's quick & easy.

Understanding custom events (and the TSI Compactor)

P: n/a
Hi all,

I'm trying to get my head around custom events, and I can't. I can use
custom classes and collections out the wazoo, but I just don't get what
events are for, or how they work. I've used Getz et al's Developer's
Handbook for years, have been over their benign example (reading and
writing text file lines), and just don't see how an event differs from
a regular old procedure--it still must be fired from your code, right?

Anyway, I'm also implementing the eminent Michael Kaplan's TSI
Compactor dll plug-in ( ), which works
very nicely to compact a database at a given path via code. In his
text file, he advertises the various events you can use if you want to
build a progress meter. Which I did want to do, and have done

The one thing I can't get the Compactor to do--and one of the things I
fail to understand about triggering an event--is get it to cancel. So
since I can't attach a little file, picture this: the user has
selected a path and has clicked a go button. The db at said path
begins compacting; a progress meter appears and updates as the
compacting progresses; and a stop button appears, too. (It's not that
useful, obviously, but whatever--I'm trying to get how and why this
works.) When I click the stop button, it sets the Cancel argument of
the CompactProgress event to true... and causes the progress meter to
"blink"... but doesn't stop the process. Code examples below.

What am I missing?

What his text file offers:

Private WithEvents m_jet As TsiCompact.Jet

Public Sub CompactMyDatabase(Source As String, Destination As String)

Set m_jet = New TsiCompact.Jet

m_jet.CompactDatabase Source, Destination

End Sub

Private Sub m_jet_BeginCompact()
Debug.Print "Compact has started!"
End Sub

Private Sub m_jet_CompactFailed()
Debug.Print "Compact has failed. :-( "
End Sub

Private Sub m_jet_CompactProgress(UnitsDone As Long, UnitsTotal As
Long, Cancel As Boolean)
Debug.Print "Compact is " & UnitsDone & "/" & UnitsTotal; " of the
way through."
End Sub

Private Sub m_jet_EndCompact()
Debug.Print "Compact has Finished!"
End Sub
which I've rebuilt in a form, changing all the debug.prints to do form
things. the key parts here:

Private Sub cmdCancel_Click()
m_jet_CompactProgress 0, 0, 1
End Sub

Private Sub m_jet_CompactProgress(UnitsDone As Long, UnitsTotal As
Long, Cancel As Boolean)

If Cancel = False Then
If lblStatusWhite.Visible = False Then Show_Status
lblStatusWhite.Width = (UnitsDone / UnitsTotal) * 7938
boxCompleted.Width = lblStatusWhite.Width
Show_Status False
End If

End Sub

Nov 13 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.