Results 1 to 10 of 10

Thread: C# as VB.NET in dotMSN? [RESOLVED]

  1. #1

    Thread Starter
    Fanatic Member LITHIA's Avatar
    Join Date
    Dec 2002
    Location
    UK, England
    Posts
    575

    C# as VB.NET in dotMSN? [RESOLVED]

    Hi,

    I am trying out dotMSN and its great, and I am going from the sample.

    Unfortunately, the sample is in C# and I don't know C#

    I have managed to make my VB.NET app successfully connect to MSN Messenger but I can't to much more than that...

    Here is a section I want to concentrate on:
    Code:
    private void ConversationCreated(Messenger sender, ConversationEventArgs e)
    		{
    e.Conversation.ContactJoin += new Conversation.ContactJoinHandler(ContactJoined);
    }
    and the line here:
    Code:
    e.Conversation.ContactJoin += new Conversation.ContactJoinHandler(ContactJoined);
    And i have no idea how I write that in VB.NET

    First of all, I don't know what its trying to do. the += thing baffles me... and second, VB.NET won't even let me write e.Conversation.ContactJoin because ContactJoin is an event. So I am completely confused...

    And by the above bit, should I be writing it like this in vb?
    VB Code:
    1. Private Sub ConversationCreated(ByVal Sender As Messenger, ByVal e As ConversationEventArgs)

    Thanks very much for the help! Sorry for including C# but I needed to post it in this forum, so please help me with this! I am so confused!
    Last edited by LITHIA; May 24th, 2004 at 10:37 AM.

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    You figured this part right :

    VB Code:
    1. Private Sub ConversationCreated(ByVal Sender As Messenger, ByVal e As ConversationEventArgs)

    There other one is wirring the event with the event handler . In C# + means , add and - means remove . So in VB.NET , it should be something like this :

    VB Code:
    1. AddHandler Conversation.ContactJoin , AddressOf ContactJoined

    I think in VB.NET , you have to create a delegate that matches the signature of the event , then instantiate it and use it in the event handler .

  3. #3

    Thread Starter
    Fanatic Member LITHIA's Avatar
    Join Date
    Dec 2002
    Location
    UK, England
    Posts
    575
    wow...

    thanks pirate... although i am really inexperienced and don't know anything about the delegates and instantiating stuff...

    Anyway,

    dotMSN is this class with all the stuff in. it has the class of
    Conversation, i've attached the screenshot.

    AddHandler Conversation.ContactJoin , AddressOf ContactJoined

    that doesn't work... when I write AddHandler i get a list of the objects available on my form.
    Conversation.ContactJoin aint an object, shown in the screenshot.

    And i can never seem to get ContactJoin to appear as it keeps saying its an event (its got the yellow lightning bolt next to it) but AddHandler did look right... because it said Object as Event, even though i dont think it's an object, or at least not an object i can get at.

    Thanks for the help pirate, you couldn't - just a tad - explain this delegate thing for me could ya preeeetty please?

    thankies!

    sorry for being so mumbled, im a newb

  4. #4

    Thread Starter
    Fanatic Member LITHIA's Avatar
    Join Date
    Dec 2002
    Location
    UK, England
    Posts
    575
    um ill have a go at attaching that image again...
    Attached Images Attached Images  

  5. #5
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    The thing is , the event signature must match the event handler signature .(in the second step) .

    VB Code:
    1. Public WithEvents ConvClass As dotMSN.Conversation

    Next step is , add the event .

    VB Code:
    1. AddHandler ConvClass.ContactJoin, AddressOf ContactJoinHandler


    'This is the event handler
    Private Sub ContactJoinHandler(ByVal Sender As Messenger, ByVal e As ConversationEventArgs)

    'Do your stuff here

    End Sub

    I don't know if this is correct but I'm guessing since I've never looked at this class . It's just hard in VB.NET

    edit , the delegate thingy , is just a pointer to a method you need to fire . You can call it just like you're calling the method itself .

  6. #6

    Thread Starter
    Fanatic Member LITHIA's Avatar
    Join Date
    Dec 2002
    Location
    UK, England
    Posts
    575
    damn... this just isn't working how its suppost to...

    Here's the sample of the C# version that works, I've attached it.
    Attached Files Attached Files

  7. #7
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Try this :

    1-Class level variable :
    VB Code:
    1. Public msngerClass As New Messenger



    2-Then ,this where we will set up the event and its handler
    VB Code:
    1. Private Sub ConversationCreated()
    2.         AddHandler msngerClass.ConversationCreated, AddressOf MSNConversationCreatedhandler
    3.  
    4. End Sub


    3-Finally , this is the event handler that is hopefully called by ConversationCreated event .


    VB Code:
    1. Private Sub MSNConversationCreatedhandler(ByVal sender As Messenger, ByVal e As ConversationEventArgs)
    2.         'Do this
    3.     End Sub

    I can't test it unless I translate all that code into VB .
    Last edited by Pirate; May 23rd, 2004 at 04:09 PM.

  8. #8

    Thread Starter
    Fanatic Member LITHIA's Avatar
    Join Date
    Dec 2002
    Location
    UK, England
    Posts
    575
    thanks pirate, ill try it out when i get home - at school at the minute. boring ict...

  9. #9

    Thread Starter
    Fanatic Member LITHIA's Avatar
    Join Date
    Dec 2002
    Location
    UK, England
    Posts
    575
    yay!!! thanks so much pirate!!! it works great!

    I'm really getting the hang of this class now, I don't think there is much I can't acomplish now!

    Thanks again so much! I'll tell you how it goes in the future for my program

    Problem resolved by Pirate

  10. #10
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    You're welcome .

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