Solved

Error with converted c# code

Posted on 2014-03-29
7
41 Views
Last Modified: 2016-06-20
Hello i have this vb code and i am not sure how to resolve this erorr

here is my function
    Private Shared Sub Main(args As String())
        Dim engine As EmoEngine = EmoEngine.Instance

        engine.EmoEngineConnected += New EmoEngine.EmoEngineConnectedEventHandler(AddressOf engine_EmoEngineConnected)
        engine.EmoEngineDisconnected += New EmoEngine.EmoEngineDisconnectedEventHandler(AddressOf engine_EmoEngineDisconnected)
        engine.UserAdded += New EmoEngine.UserAddedEventHandler(AddressOf engine_UserAdded)
        engine.UserRemoved += New EmoEngine.UserRemovedEventHandler(AddressOf engine_UserRemoved)
        engine.EmoStateUpdated += New EmoEngine.EmoStateUpdatedEventHandler(AddressOf engine_EmoStateUpdated)
        engine.ExpressivEmoStateUpdated += New EmoEngine.ExpressivEmoStateUpdatedEventHandler(AddressOf engine_ExpressivEmoStateUpdated)
        engine.CognitivEmoStateUpdated += New EmoEngine.CognitivEmoStateUpdatedEventHandler(AddressOf engine_CognitivEmoStateUpdated)
        engine.AffectivEmoStateUpdated += New EmoEngine.AffectivEmoStateUpdatedEventHandler(AddressOf engine_AffectivEmoStateUpdated)
        engine.EmoEngineEmoStateUpdated += New EmoEngine.EmoEngineEmoStateUpdatedEventHandler(AddressOf engine_EmoEngineEmoStateUpdated)
        engine.CognitivTrainingStarted += New EmoEngine.CognitivTrainingStartedEventEventHandler(AddressOf engine_CognitivTrainingStarted)
        engine.CognitivTrainingSucceeded += New EmoEngine.CognitivTrainingSucceededEventHandler(AddressOf engine_CognitivTrainingSucceeded)
        engine.CognitivTrainingCompleted += New EmoEngine.CognitivTrainingCompletedEventHandler(AddressOf engine_CognitivTrainingCompleted)
        engine.CognitivTrainingRejected += New EmoEngine.CognitivTrainingRejectedEventHandler(AddressOf engine_CognitivTrainingRejected)
        engine.ExpressivTrainingStarted += New EmoEngine.ExpressivTrainingStartedEventEventHandler(AddressOf engine_ExpressivTrainingStarted)
        engine.ExpressivTrainingSucceeded += New EmoEngine.ExpressivTrainingSucceededEventHandler(AddressOf engine_ExpressivTrainingSucceeded)
        engine.ExpressivTrainingCompleted += New EmoEngine.ExpressivTrainingCompletedEventHandler(AddressOf engine_ExpressivTrainingCompleted)
        engine.ExpressivTrainingRejected += New EmoEngine.ExpressivTrainingRejectedEventHandler(AddressOf engine_ExpressivTrainingRejected)

        engine.Connect()

        Dim cki As New ConsoleKeyInfo()
        ' int x, y;

        While True
            Try
                If Console.KeyAvailable Then
                    cki = Console.ReadKey(True)
                    keyHandler(cki.Key)

                    If cki.Key = ConsoleKey.X Then
                        Exit Try
                    End If
                End If


                'engine.HeadsetGetGyroDelta(0, out x, out y);
                'if (x!=0 || y!=0)
                '    Console.WriteLine("{0}, {1}", x, y);
                engine.ProcessEvents(1000)
            Catch e As EmoEngineException
                Console.WriteLine("{0}", e.ToString())
            Catch e As Exception
                Console.WriteLine("{0}", e.ToString())
            End Try
        End While
        engine.Disconnect()
    End Sub

Open in new window


i am getting this erorr

Error      4      'Public Event EmoEngineDisconnected(sender As Object, e As Emotiv.EmoEngineEventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.      C:\Users\lauren\SkyDrive\Research\LMS\EEGProject\EEGResearchProject\EEGResearchProject\EEG.vb      297      9      EEGResearchProject
0
Comment
Question by:Chris Jones
  • 4
  • 2
7 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 39963726
I think the problem is with your event registration section. You need to use "AddHandler" rather than the C# style of +=:
AddHandler engine.EmoEngineConnected, AddressOf engine_EmoEngineConnected
AddHandler engine.EmoEngineDisconnected, AddressOf engine_EmoEngineDisconnected
AddHandler engine.UserAdded, AddressOf engine_UserAdded
AddHandler engine.UserRemoved, AddressOf engine_UserRemoved
AddHandler engine.EmoStateUpdated, AddressOf engine_EmoStateUpdated
AddHandler engine.ExpressivEmoStateUpdated, AddressOf engine_ExpressivEmoStateUpdated
AddHandler engine.CognitivEmoStateUpdated, AddressOf engine_CognitivEmoStateUpdated
AddHandler engine.AffectivEmoStateUpdated, AddressOf engine_AffectivEmoStateUpdated
AddHandler engine.EmoEngineEmoStateUpdated, AddressOf engine_EmoEngineEmoStateUpdated
AddHandler engine.CognitivTrainingStarted, AddressOf engine_CognitivTrainingStarted
AddHandler engine.CognitivTrainingSucceeded, AddressOf engine_CognitivTrainingSucceeded
AddHandler engine.CognitivTrainingCompleted, AddressOf engine_CognitivTrainingCompleted
AddHandler engine.CognitivTrainingRejected, AddressOf engine_CognitivTrainingRejected
AddHandler engine.ExpressivTrainingStarted, AddressOf engine_ExpressivTrainingStarted
AddHandler engine.ExpressivTrainingSucceeded, AddressOf engine_ExpressivTrainingSucceeded
AddHandler engine.ExpressivTrainingCompleted, AddressOf engine_ExpressivTrainingCompleted
AddHandler engine.ExpressivTrainingRejected, AddressOf engine_ExpressivTrainingRejected

Open in new window

0
 
LVL 1

Author Comment

by:Chris Jones
ID: 39963732
thanks let me try this i seen some examples online when i was researching the issue but could not pinpoint the syntax.
0
 
LVL 1

Author Comment

by:Chris Jones
ID: 39963894
real quick i was converting these functions as well but i tried the addhandler and it still did not work

            Private Sub Train1(sender As Object, e As Emotiv.EmoEngineEventArgs)
                theEmotivPower.m_EmoEngine.CognitivTrainingStarted -= started
                [stop] = New Emotiv.EmoEngine.CognitivTrainingSucceededEventHandler(AddressOf Train2)
                theEmotivPower.m_EmoEngine.CognitivTrainingSucceeded += [stop]
            End Sub
            Private Sub Train2(sender As Object, e As Emotiv.EmoEngineEventArgs)
                theEmotivPower.m_EmoEngine.CognitivTrainingSucceeded -= [stop]
                Semaphore_BlockTraining.Release()
            End Sub

Open in new window


erorr or on these lines

   theEmotivPower.m_EmoEngine.CognitivTrainingSucceeded -= [stop]
     theEmotivPower.m_EmoEngine.CognitivTrainingStarted -= started
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 500 total points
ID: 39963896
You need RemoveHandler for those ones, rather than AddHandler since you are unregistering the event.
0
 
LVL 1

Author Comment

by:Chris Jones
ID: 39963902
ok cool i am slowly understanding it and now the  -= [stop] at the end
0
 
LVL 1

Author Comment

by:Chris Jones
ID: 39963903
never mind i see what is needed
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now