|
-
Sep 11th, 2006, 05:39 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Events Redux
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:
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 Sub
which ends up in clsForm:
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
I'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?
-
Sep 11th, 2006, 06:04 PM
#2
Re: Events Redux
Based on what you posted, a quick and dirty sample application works for me.
What does the procedure pSet_clsButtonClick do?
Does the event fire if you comment out that line?
-
Sep 11th, 2006, 06:46 PM
#3
Thread Starter
Hyperactive Member
Re: Events Redux
 Originally Posted by brucevde
Based on what you posted, a quick and dirty sample application works for me.
What does the procedure pSet_clsButtonClick do?
Does the event fire if you comment out that line?
It sets a boolean flag so I know it has been clicked and changes the coloring of button:
VB Code:
Private Sub pSet_clsButtonClick(viIndex As Integer)
Dim li As Integer
For li = 1 To ceCmdID.All
If Not foClsButtons(li) Is Nothing Then
If li = viIndex And foClsButtons(li).Is_Visible Then
Call foClsButtons(li).Set_Click(True)
Else
Call foClsButtons(li).Set_Click(False)
End If
End If
Next
End Sub
Answer for Second Question: No
-
Sep 12th, 2006, 08:58 AM
#4
Thread Starter
Hyperactive Member
Re: Events Redux
Nevermind. I was able to resolve the issue.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|