Everytime I think that I get a handle on events in Visual Basic, I always run into a quirk that leaves me baffled. My situation is that I have a class clsButton that functions similar to CommandButtons. I have another class that acts like a collection of buttons to allow me to handle some intermediate code (clsForm) between the basic functions of the buttons and the main form which displays the buttons. My goal is to communication from the very bottom (clsButton) to the very top (frmMain). Apparently, I can raise events to the intermediate level (clsForm), but it will never get to frmMain in this example:which ends up in clsForm:VB Code:
'clsButton Private WithEvents coLbl As Label Public Event MouseClick(viID As Integer, viButton As Integer, viShift As Integer, viX As Single, viY As Single) '.. Various Code .. Private Sub coLbl_MouseDown(viButton As Integer, viShift As Integer, viX As Single, viY As Single) If Not bMouseClick Then RaiseEvent MouseClick(ID, viButton, viShift, viX, viY) End If End SubI've removed tons of code for this snippet, but it should show that I can get one event to fire in another class module, but it seems you can't fire an event up the hierarchy right after an event has been fired?VB Code:
'clsForm Public WithEvents foCmdEmp As clsButton Private WithEvents foForm As Form Public Event TestEvent() '.. Various Code .. Public Sub TEST_IT() RaiseEvent TestEvent End Sub Public Sub foForm_Click() 'Set a separate function to test TEST_IT() 'Call it from this event, it works Call TEST_IT End Sub Public Sub foCmdEmp_MouseClick(viID As Integer, viButton As Integer, viShift As Integer, viX As Single, viY As Single) Call pSet_clsButtonClick(viID) Call TEST_IT ' <--- Fires, TEST_IT is called but no event is sent up End Sub![]()




Reply With Quote