Results 1 to 7 of 7

Thread: Problem with converting code

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2006
    Posts
    84

    Problem with converting code

    from C# to VB. I have the code working fine in C#.

    C#
    Code:
    interceptor = new MessageInterceptor();
    interceptor.InterceptionAction = InterceptionAction.NotifyAndDelete;
    interceptor.MessageReceived += new MessageInterceptorEventHandler(OnSmsReceived);
    VB
    VB Code:
    1. interceptor = New MessageInterceptor()
    2. interceptor.InterceptionAction = InterceptionAction.NotifyAndDelete
    3. interceptor.MessageReceived += New MessageInterceptorEventHandler(OnSmsReceived)

    I get errors in VB on line 3 saying I have to use a RaiseEvent statement for MessageRecevied. I am not sure how to do this if anyone can help.

    Thanks

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Problem with converting code

    If we as software developers cannot consult help documentation how can we expect our users to do so?

    http://msdn2.microsoft.com/en-us/library/fwd3bwed.aspx
    Last edited by jmcilhinney; Oct 4th, 2006 at 07:22 AM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2006
    Posts
    84

    Re: Problem with converting code

    Yeah thanks. I did actually look at some documentation but still don't understand how to do it. I understand that because MessageReceived is an event you have to RaiseEvent it rather that call it directly, so I would therefore put the RaiseEvent infront of it. I'm still doing something wrong though.

  4. #4
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    710

    Re: Problem with converting code

    The short-form VB equivalent is:
    AddHandler interceptor.MessageReceived, AddressOf OnSmsReceived

    You could also code:
    AddHandler interceptor.MessageReceived, New MessageInterceptorEventHandler(AddressOf OnSmsReceived)
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jul 2006
    Posts
    84

    Re: Problem with converting code

    So it's just like when you create a control at run time and you want to use its Click event for instance.

    Is this the same as Raising and event then?

    Thanks very much

  6. #6
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    710

    Re: Problem with converting code

    No - the original C# code you posted does not raise an event. It wires up the event handler.
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Problem with converting code

    Hmmm... I guess I could have read the code too. Odd that it would point you to RaiseEvent when you're trying to handle an event rather than raise one. The page I linked to does include a link to the AddHandler statement and MSDN also includes pages many topics dedicated to raising an handling events.

    http://search.msdn.microsoft.com/sea...andling+Events
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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