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
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
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