Question Raise Event problem

alammas

New member
Joined
Sep 18, 2010
Messages
4
Programming Experience
Beginner
Hi.

I am newbie in VB.Net

I am just try to convert C# statement into Vb.net that is


comm.MessageReceived -= new MessageReceivedEventHandler(comm_MessageReceived);

Reference: GSMCommunication.dll

Where MessageReceived is an Event and comm_MessageReceived is a sub function which need to AddressOf with that event


i try this one to

RaiseEvent comm.MessageReceived += New MessageReceivedEventHandler(AddressOf comm_MessageReceived)

but intelligence responds "End of statement expected"

Please Help me to solve it
Thanks in advance
 
That C# code has nothing to do with raising an event. It's about handling an event or, more correctly, about not handling an event. It's removing a handler from an event, which looks like this in VB:
VB.NET:
RemoveHandler comm.MesageReceived, AddressOf comm_MessageReceived
If the C# code was using += instead of -= then it would be adding an event handler rather than removing it. In VB that would be AddHandler rather than RemoveHandler.
 
jmcilhinney: Thanks Allot sir for your help, and apologies for late reply

I require to raise an event when message received by GSM modem

VB.NET:
 Private Delegate Sub MessageReceivedEventHandler(ByVal sender As Object, ByVal e As MessageReceivedEventArgs)
 Private Event MessageReceived As MessageReceivedEventHandler

MessageReceived requires inputs other codes are
VB.NET:
Private Sub comm_MessageReceived(ByVal sender As Object, ByVal e As MessageReceivedEventArgs)
        Try
            Dim obj As IMessageIndicationObject = e.IndicationObject
            If TypeOf obj Is MemoryLocation Then
                Dim loc As MemoryLocation = DirectCast(obj, MemoryLocation)
                Output(String.Format("New message received in storage ""{0}"", index {1}.", loc.Storage, loc.Index))
                Output("")
                Return
            End If
            If TypeOf obj Is ShortMessage Then
                Dim msg As ShortMessage = DirectCast(obj, ShortMessage)
                Dim pdu As SmsPdu = Comm.DecodeReceivedMessage(msg)
                Output("New message received:")
                Output("")
                Return
            End If
            Output("Error: Unknown notification object!")
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

how i can deal it as like C# in VB
VB.NET:
comm.MessageReceived += new MessageReceivedEventHandler(comm_MessageReceived);
 
Back
Top