5 min VB6 program Save msn contacts

  • 0
Not posted any code for a long time on any blog so thought I would publish this vb6 program to save contacts to txt file.

What you need:
  • a brain
Other things you will need!
  • A working VB6 ( we dont need .net, otherwise I would have done this in C# )
  • Msn

Every control on the program is by defualt name. You dont need to rename any control! Start a new project and add
  • 1 Textbox
  • 1 command button
  • 1 label
  • microsoft common dialog control 6.0 (find it in project, components or CTRL - T) drag that in anywhere on the form
  • Setup a reference to Messenger API Type library (find it in project, reference)
The command button should have a caption like save. The textbox is where the contacts are going to be shown. It should have a scroll and be enough to see a whole contact with out scrolling side ways.

the form code:
'code writen by Darknighthunter500@gmail.com // http://dnh500.blogspot.com 2006
Private Sub Form_Load()
Set msn = New MessengerAPI.Messenger
' set msn as msnAPI
Dim msncontact As IMessengerContact 'contact stuff
Dim msncontacts As IMessengerContacts
Set msncontacts = msn.MyContacts

For Each msncontact In msncontacts 'start to add all the contacts to the list
'in a FOR NEXT loop
Text1.Text = Text1.Text + vbCrLf 'new line
Next


Label1.Caption = "Number of contacts" & " " & msncontacts.Count 'will show the number
'of contacts
End Sub


Now for saving the contacts using the CommonDialog1 control.
the command1 (the button) code:
Private Sub Command1_Click()
Dim filename As String

On Error GoTo SaveAsErr
'the txt file filter
If Me.CommonDialog1.filename =
"" Then
Me.CommonDialog1.DefaultExt = "txt"
Me.CommonDialog1.Filter = _
"Text Files (*.txt)|*.txt"
End If
' display the Save As dialog
CommonDialog1.ShowSave
' get the resulting filename
filename = CommonDialog1.filename
Open filename For Output As #1
Print #1, Label1.Caption + vbCrLf + Text1.Text 'save god dam it!
Close #1

SaveAsErr: 'abandon ship
Exit Sub
End Sub


Ok so I have not really commented much on the file saving part, but its really simple stuff.
You should having something like this


If your getting errors running it make sure you have selected Messenger API Type library in references or its just not going to work. If you dont like the CommonDialog method of saving then use more simple method like below to save the text file to C:\contacts.txt
Private Sub Command1_Click()
Dim hFile As Long
Dim sFilename As String
sFilename = "c:\contacts.txt"
hFile = FreeFile
Open sFilename For Output As #hFile
Print #1, Label1.Caption + vbCrLf + Text1.Text
Close #hFile
End Sub



You can write a lot of small programs in vb6 for msn. Have fun

No comments:

Post a Comment