Results 1 to 12 of 12

Thread: RaiseEvent not working

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2009
    Location
    Anywhere I want to.
    Posts
    368

    RaiseEvent not working

    The RaiseEvent does not fire. In the IDE if I step through the code the RaiseEvent it just steps through this line of code.

    Does not fire as an App .exe either (compiled)

    There are o error messages.

    Is my code bad ?
    Too many parameters ?

    Something else.

    I can run the app in the IDE with no errors and all else executes as expected.

    In a Form

    Private WithEvents cControlMoverSizer As clsControlMoverSizer

    In this Form, Form_Load I have

    Set cControlMoverSizer = New clsControlMoverSizer

    I have in this Form
    Public Sub cControlMoverSizer_CoordEvent(sCtrlName As String, _
    lCtrlIdx As Long, sTag As String, _
    ByVal fLft As Single, _
    ByVal fTop As Single, _
    ByVal fWid As Single, _
    ByVal fHgt As Single, _
    ByVal fRgt As Single, _
    ByVal fBot As Single)

    ' Some processing code

    End sub


    ' ===================
    In my Class

    Public Event CoordEvent(sCtrlName As String, lCtrlIdx As Long, sTag As String, _
    ByVal fLft As Single, ByVal fTop As Single, _
    ByVal fWid As Single, ByVal fHgt As Single, _
    ByVal fRgt As Single, ByVal fBot As Single)

    In a Sub in this Class I have
    RaiseEvent CoordEvent(oCtrl.Name, oCtrl.Index, oCtrl.Tag, oCtrl.Left, oCtrl.Top, oCtrl.Width, oCtrl.Height, oCtrl.Left + oCtrl.Width, oCtrl.Top + oCtrl.Height)

  2. #2
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,722

    Re: RaiseEvent not working

    Does your sub with the RaiseEvent CoordEvent() call use On Error Resume Next? If so, that could cause the RaiseEvent line to be "skipped" if there's an error accessing any of the oCtrl properties (or if oCtrl is Nothing).

  3. #3
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,010

    Re: RaiseEvent not working

    Wasn't there something about NOT passing Properties directly to Functions?

    I'd assign all those Properties to local Variables first, and CHECK them before raising the Event
    Next: The first 3 parameters of your Event are ByRef.
    DON'T!
    An Event is a Shoot and forget. Always pass ByVal

    Lastly: You're registered since 2009. You should know by now how to use Code-Tags
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2009
    Location
    Anywhere I want to.
    Posts
    368

    Re: RaiseEvent not working

    Error Handler there as the way I always do.
    Changed all to ByVal, NOGO.

    made test case using
    Code:
        RaiseEvent CoordEvent(vbNullString, 0, vbNullString, 0, 0, 0, 0, 0, 0)
    NOGO !
    Event still does not go.

  5. #5
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,010

    Re: RaiseEvent not working

    Just saw it: Since when is an Event-Handler Public????

    in your Form (!!)
    Public Sub cControlMoverSizer_CoordEvent(sCtrlName As String, _
    lCtrlIdx As Long, sTag As String, _
    ByVal fLft As Single, _
    ByVal fTop As Single, _
    ByVal fWid As Single, _
    ByVal fHgt As Single, _
    ByVal fRgt As Single, _
    ByVal fBot As Single)
    Did you write that Handler by Hand, or did you use the Dropdown?

    Never ever write Event-Handlers by Hand.
    Use the Dropdown-Menu in the Code-Window for your Form
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2009
    Location
    Anywhere I want to.
    Posts
    368

    Re: RaiseEvent not working

    I have been using my own handlers since day one without any problems what so ever.
    I also use MZTools, again with not one problem.

    BTW, I also have used RaiseEvents in many large app using ByRef and returning a value to the method raising the event with no problem. IDE and compiled apps work just fine. So what is wrong with that ?

    So I change to ByVal only on the Raise side and saw an error on the receiving end so I know the IDES is detecting the missing ByVal..Changing all to ByVal did not fix the problem.

    This app has 44K lines of code plus additional 16K of comments.. Other apps I have are larger with no problems.

    I have another thing I will try and get back later with results.

    I have another simpler Event in the Same form and Class and it too will not fire. Was ByRef and Now ByVal, NOGO.

  7. #7
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,010

    Re: RaiseEvent not working

    You're right regarding ByRef/ByVal. There are Events with ByRef (KeyPress being one).

    Otherwise i'm out of ideas.

    Have you checked the Values before raising the Event?
    Maybe you want to pass an invalid Value, and your code chokes on it.
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2009
    Location
    Anywhere I want to.
    Posts
    368

    Re: RaiseEvent not working

    Yes, mouse hover over variables shows expected values.

    I moved code to a Win 7 x64 laptop and have the same issues.
    I must be doing something wrong in my code but so far it alludes me.
    I moved the method code from the class back to the Form where it was originally called and this works fine not using the Events but still I do not understand what was wrong using Events. Are there some Class attributes that can cause this ?

  9. #9
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,839

    Re: RaiseEvent not working

    > In a Sub in this Class I have
    > RaiseEvent CoordEvent(oCtrl.Name, oCtrl.Index, oCtrl.Tag, oCtrl.Left, oCtrl.Top, oCtrl.Width, oCtrl.Height, oCtrl.Left + oCtrl.Width, oCtrl.Top + oCtrl.Height)

    Just before RaiseEvent put an On Error GoTo 0 statement.

    Most probably your oCtl instance does not have Index propery (or Tag).

    When it bombs on RaiseEvent try all props you are accessing one by one in Immediate Window.

  10. #10
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,010

    Re: RaiseEvent not working

    Quote Originally Posted by LorinM View Post
    Yes, mouse hover over variables shows expected values.

    I moved code to a Win 7 x64 laptop and have the same issues.
    I must be doing something wrong in my code but so far it alludes me.
    I moved the method code from the class back to the Form where it was originally called and this works fine not using the Events but still I do not understand what was wrong using Events. Are there some Class attributes that can cause this ?
    Don't use "Mouse Hover"
    Use local variables, assigning each Property to the vars, and then try to pass the vars in the Event.
    What wqweto wrote not withstanding: Switch off Error-Handling
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2009
    Location
    Anywhere I want to.
    Posts
    368

    Re: RaiseEvent not working

    I will try your suggestions, some of which I have already tried.

    My Error Handling structure aircode SAMPLE
    I have been using this construct since VB6 emerged and it always works as needed.
    Code:
    Public Function Method(lX As Long) As String
    
        On Error GoTo Method_Err  ' This goes on top line as MOST important
    
        Dim sThis  As String
        Dim bThat as Boolean
    
         ' BODY OF METHOD CODE
    
        Method = "Done"    ' or whatever needs returning
    
    Method_Exit:
        ' Cleanup code here if necessary
        Exit Function
    
    Method_Err:
        ' I put a break on this next LogCodeError Line
        LogCodeError "MethodName Error: " & Err.Description ' This is in a module and while in the IDE it pops up a Message Box
    
        Resume Method_Exit
    
    Resume   ' Here to easily go back to my code line with error.
    
    End Function ' Method

  12. #12
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,839

    Re: RaiseEvent not working

    Looks solid. Just make sure cleanup code after Method_Exit does not bomb or you’ll get infinite loop. Probably an OERN there will take care of all edge cases.

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