Results 1 to 4 of 4

Thread: [RESOLVED] Events Redux

  1. #1

    Thread Starter
    Hyperactive Member Fedhax's Avatar
    Join Date
    Aug 2006
    Posts
    293

    Resolved [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:
    1. 'clsButton
    2. Private WithEvents coLbl        As Label
    3.  
    4. Public Event MouseClick(viID As Integer, viButton As Integer, viShift As Integer, viX As Single, viY As Single)
    5.  
    6. '.. Various Code ..
    7.  
    8. Private Sub coLbl_MouseDown(viButton As Integer, viShift As Integer, viX As Single, viY As Single)
    9.     If Not bMouseClick Then
    10.         RaiseEvent MouseClick(ID, viButton, viShift, viX, viY)
    11.     End If
    12. End Sub
    which ends up in clsForm:
    VB Code:
    1. 'clsForm
    2. Public WithEvents foCmdEmp          As clsButton
    3.  
    4. Private WithEvents foForm           As Form
    5.  
    6. Public Event TestEvent()
    7.  
    8. '.. Various Code ..
    9.  
    10. Public Sub TEST_IT()
    11.     RaiseEvent TestEvent
    12. End Sub
    13.  
    14. Public Sub foForm_Click()
    15.     'Set a separate function to test TEST_IT()
    16.     'Call it from this event, it works
    17.     Call TEST_IT  
    18. End Sub
    19.  
    20. Public Sub foCmdEmp_MouseClick(viID As Integer, viButton As Integer, viShift As Integer, viX As Single, viY As Single)
    21.     Call pSet_clsButtonClick(viID)
    22.     Call TEST_IT  ' <--- Fires, TEST_IT is called but no event is sent up
    23. 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?

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    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?

  3. #3

    Thread Starter
    Hyperactive Member Fedhax's Avatar
    Join Date
    Aug 2006
    Posts
    293

    Re: Events Redux

    Quote 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:
    1. Private Sub pSet_clsButtonClick(viIndex As Integer)
    2.  
    3.     Dim li      As Integer
    4.    
    5.     For li = 1 To ceCmdID.All
    6.         If Not foClsButtons(li) Is Nothing Then
    7.             If li = viIndex And foClsButtons(li).Is_Visible Then
    8.                 Call foClsButtons(li).Set_Click(True)
    9.                
    10.             Else
    11.                 Call foClsButtons(li).Set_Click(False)
    12.             End If
    13.         End If
    14.     Next
    15.  
    16. End Sub
    Answer for Second Question: No

  4. #4

    Thread Starter
    Hyperactive Member Fedhax's Avatar
    Join Date
    Aug 2006
    Posts
    293

    Resolved 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
  •  



Click Here to Expand Forum to Full Width