locked
[VB] How do I use RaiseEvent inside a procedual If...Then statement? RRS feed

  • Question

  • Hi. I am trying to use an Event inside of a If...Then statement, but I read you can only use Events on the Module level and not the procedure level. When I try to do this I get the following error:

    Do I need an event handler somewhere or is there no way around this, since I can't use RaiseEvent inside my If...Then statement. Here's the Sub I put this in if you need more info.

    Code:

    Private Sub Update()
                If GazeTransform Is Nothing Then
                    Return
                End If
    
                UpdateGazeInfo()
    
                ' Perform raycast to determine gazed object
                Dim previousFocusObject As GameObject = RaycastPhysics()
    
                ' If we have a unity event system, perform graphics raycasts as well to support Unity UI interactions
                If EventSystem.current IsNot Nothing Then
                    ' NOTE: We need to do this AFTER we set the HitPosition and HitObject since we need to use HitPosition to perform the correct 2D UI Raycast.
                    RaycastUnityUI()
                End If
    
                ' Dispatch changed event if focus is different
    
                If previousFocusObject <> HitObject AndAlso FocusedObjectChanged IsNot Nothing Then
                    RaiseEvent FocusedObjectChanged(previousFocusObject, HitObject)
                End If
            End Sub

    Wednesday, June 21, 2017 8:51 AM

All replies

  • Hi dvdalimi,

    According to your screenshot, I guess that you want to know whether the FocusedObjectChanged event is executed.

    But your code is not allowed in vb.net.

    You could define a global variable Flag=false, if the FocusedObjectChanged event is executed, you set Flag=true, then you can use Flag to determine whether the FocusedObjectChanged event is executed.

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, June 29, 2017 7:01 AM