School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,574 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,193 people online right now. Registration is fast and FREE... Join Now!




[VB.NET|MSN] Adding old contacts to a new MSN account

 
Reply to this topicStart new topic

> [VB.NET|MSN] Adding old contacts to a new MSN account, How to add contacts from your old account with ease

RodgerB
Group Icon



post 6 Dec, 2007 - 11:20 PM
Post #1


Welcome to this tutorial on adding old contacts to a new MSN account. This tutorial explains the MessengerAPI COM object, and how we can use this API to make it easier to re-add all of our old contacts.

This process is dependent on the AddContact() subroutine, which we shall be using here. In this tutorial, we will be making a Windows Form that we can use to create a simple GUI for the user to access and add contacts with ease. Lets get started!

1) Goto File > New > Project.. and select Windows Application. Set the Name to "msnAdder" or something simular, and click OK.

2) Set Form1's name property to frmMain, and set the Text property to Msn Contact Adder.

3) Add a CheckedListBox control to the form, and rename it to chlContacts. Adjust both the Form and the CheckBox's size to look neater on the form.

4) Add two buttons to the top of the form, btnGet and btnSet. These buttons will give the option of getting the addresses, or setting the addresses into a new MSN account. Set the Text Properties to "Get" and "Set". Your form should now look like Figure 1.1:

IPB Image
Figure 1.1: What your form should look like now.

5) Now that we have the design set up, it's now time to add the MessengerAPI COM Object. Goto Project > Add Reference.., and click the COM Tab above the list of components. Scroll down until you find Messenger API Type Library, select it and click OK.

IPB Image
Figure 1.2: The COM object we are looking for.

6) Now it's time to add the main object to the form. Double Click on the Get Event so we are in Code View. Just After "Public Class frmMain" and before the button press event, declare this variable:

CODE

Dim objMSN As New MessengerAPI.Messenger


This will create an instance of the MessengerAPI.Messenger object so we can use it to access the MSN session.

7) Now that we have our main instance, we can now use the btnGet button to get all the contacts the user would like to import into their new address. Copy and paste the following code into the btnGet.Click() event.

CODE

Dim msncontact As MessengerAPI.IMessengerContact
Dim msncontacts As MessengerAPI.IMessengerContacts = objMSN.MyContacts

' Get rid of anything in the list.
chlContacts.Items.Clear()

' Loop through all the contacts and add the SigninName to the list.
For Each msncontact In msncontacts
    chlContacts.Items.Add(msncontact.SigninName)
Next


The code above will loop through all the contacts, and add all the MSN Addresses into a CheckBoxList which they will then decide whether they want to add this contact or not.

8) Now that we have the ability to get all the contacts, we can now add them all to our new account. (Note, the user will need to sign into his/her new account in-order to add the new contacts).

Copy and paste this code into the btnSet.Click Event:

CODE

For i As Integer = 0 To chlContacts.CheckedItems.Count - 1
    objMSN.AddContact(0, chlContacts.CheckedItems.Item(i))
    SendKeys.Send("{enter}")
Next

MessageBox.Show("The operation completed successfully.")


The code above will loop through all the Checked ListBox items, and add them to Messenger. An Enter KeyPress is sent to close the Add Contact window, and act as an Ok Button press.

9) Test your project.

I have yet to receive an error with this code, it has been tested with both my computer and my laptop, and I am sure there isn't any bugs with the coding. However, it is good practice to test it anyway.
Go to the top of the page
+Quote Post


Register to Make This Ad Go Away!

xnet
*



post 7 Jun, 2009 - 02:00 AM
Post #2
QUOTE(RodgerB @ 6 Dec, 2007 - 11:20 PM) *

Welcome to this tutorial on adding old contacts to a new MSN account...


Can someone tell me how can i signin in to msn using this objMSN?

thx
Go to the top of the page
+Quote Post


Fast ReplyReply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 


Lo-Fi Version Time is now: 11/8/09 08:12AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month