A61a
SEO Keyword Architect
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
200 XP
Introduction:
In this tutorial we are going to be making a simple program in Visual Basic to download someones Skype profile picture.
How It Works:
We are going to use the Skype API to act as a link to get the profile picture, from that we can use a simple download function within Visual Basic .NET to download the returned image through the link.
Design:
This program will take two components;
Button, named 'skypeButton', text set as 'Download Profile Image'
Textbox, named 'skypeText', where the user will enter the skype profile username.
Verifying:
Once the button has been clicked, we first want to check that the text falls within the Skype username requirements (greater than 5 characters but less than 33) and only contains letters/numbers.
First we check the character length...
Then we iterate through each character and ensure that it is allowed (contained within our allowed characters list), if any of them is not there, we set the boolean value of our earlier defined 'runDownload' variable to false...
Then if the 'runDownload' variable is True/y/yes/ok/1 then no error occured, the username is ok, and we try to download the image...
We let the user choose a save location, file name and file type out of .jpg or .png.
In this tutorial we are going to be making a simple program in Visual Basic to download someones Skype profile picture.
How It Works:
We are going to use the Skype API to act as a link to get the profile picture, from that we can use a simple download function within Visual Basic .NET to download the returned image through the link.
Design:
This program will take two components;
Button, named 'skypeButton', text set as 'Download Profile Image'
Textbox, named 'skypeText', where the user will enter the skype profile username.
Verifying:
Once the button has been clicked, we first want to check that the text falls within the Skype username requirements (greater than 5 characters but less than 33) and only contains letters/numbers.
First we check the character length...
- Private
Sub
skypeButton_Click(sender As
Object
, e As
EventArgs) Handles skypeButton.Click
- Dim
username As
String
= skypeText.Text
- Dim
runDownload As
Boolean
= True
- If
(username.Length >= 6 And
username.Length <= 32) Then
- 'Next code goes in here.
- Else
: MsgBox("Username is not the right length!"
)
- End
If
- End
Sub
Then we iterate through each character and ensure that it is allowed (contained within our allowed characters list), if any of them is not there, we set the boolean value of our earlier defined 'runDownload' variable to false...
- Dim
allowed As
Char() = "abcdefghijklmnopqrstuvwxyz0123456789"
- username = username.ToLower() 'Easier to check against the allowed characters, case insensitive.
- For
Each
character As
String
In
username
- Dim
isFound As
Boolean
= False
- For
Each
c As
Char In
allowed
- If
c = character Then
isFound = True
- Next
- If
Not
(isFound) Then
- MsgBox(character)
- runDownload = False
- End
If
- Next
Then if the 'runDownload' variable is True/y/yes/ok/1 then no error occured, the username is ok, and we try to download the image...
- If
(runDownload) Then
- Dim
link As
String
= "http://api.skype.com/users/"
+ username + "/profile/avatar"
- Dim
fs As
New
SaveFileDialog
- fs.Filter = "JPEG Files | .jpg | PNG Files | *.png"
- fs.FilterIndex = 1
- fs.ShowDialog()
- If
(My.Computer.FileSystem.FileExists(fs.FileName)) Then
- Dim
result As
MsgBoxResult = MsgBox("File already exists, overwrite it?"
, MsgBoxStyle.YesNo, "File Exists"
)
- If
(result = MsgBoxResult.Yes) Then
- Dim
wc As
New
WebClient
- wc.DownloadFile(link, fs.FileName)
- End
If
- Else
- Dim
wc As
New
WebClient
- wc.DownloadFile(link, fs.FileName)
- End
If
- Else
: MsgBox("Not all the characters meet the Skype requirements for a username. Please try again with a different username"
)
- End
If
We let the user choose a save location, file name and file type out of .jpg or .png.