How to Create a Website URL Verifier in Visual Basic
Submitted by GeePee on Thursday, April 23, 2015 - 23:01.
Introduction:
Welcome to a tutorial on how to create a website/url verifier and checker in Visual Basic.
Steps of Creation:
Step 1:
First we want to create a form with a textbox to contain the website url, button1 to verify the url format and button2 to check the website response.
Step 2:
First lets make a function to check the url and return the correctly formatted url.
Step 3:
Next lets run the function on button1 click...
Step 4:
Now for the response checker. We simply try to get a response, if it fails it will also fail the try statement and output that the website is un-responsive.
Project Complete!
That's it! Below is the full source code and download to the project files.
- Private Function doCheck(ByVal s As String)
- If (s.StartsWith("http://www.") Or s.StartsWith("https://www.")) Then
- Return s
- ElseIf (s.StartsWith("http://")) Then
- If (s.Contains("www.")) Then
- s = "http://www." & s.Substring(1, s.Count - 1)
- TextBox1.Text = s
- Return s
- Else
- s = "http://www." & s.Substring(7, s.Count - 7)
- TextBox1.Text = s
- Return s
- End If
- ElseIf (s.StartsWith("https://")) Then
- If (s.Contains("www.")) Then
- s = "https://" & s.Substring(12, s.Count() - 12)
- TextBox1.Text = s
- Return s
- Else
- s = "https://www." & s.Substring(8, s.Count - 8)
- TextBox1.Text = s
- Return s
- End If
- Else
- If (s.StartsWith("www.")) Then
- s = "http://www." & s.Substring(4, s.Count() - 4)
- TextBox1.Text = s
- Return s
- Else
- s = "http://www." & s
- TextBox1.Text = s
- Return s
- End If
- End If
- End Function
- Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
- Dim s As String = TextBox1.Text.ToLower()
- TextBox1.Text = doCheck(s)
- End Sub
- Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
- Try
- Dim r As httpwebrequest = httpwebrequest.create(TextBox1.Text)
- Dim re As httpwebresponse = r.getresponse()
- MsgBox("Website responsive.")
- Catch ex As Exception
- MsgBox("Website un-responsive.")
- End Try
- End Sub
- Imports System.Net
- Public Class Form1
- Private Function doCheck(ByVal s As String)
- If (s.StartsWith("http://www.") Or s.StartsWith("https://www.")) Then
- Return s
- ElseIf (s.StartsWith("http://")) Then
- If (s.Contains("www.")) Then
- s = "http://www." & s.Substring(1, s.Count - 1)
- TextBox1.Text = s
- Return s
- Else
- s = "http://www." & s.Substring(7, s.Count - 7)
- TextBox1.Text = s
- Return s
- End If
- ElseIf (s.StartsWith("https://")) Then
- If (s.Contains("www.")) Then
- s = "https://" & s.Substring(12, s.Count() - 12)
- TextBox1.Text = s
- Return s
- Else
- s = "https://www." & s.Substring(8, s.Count - 8)
- TextBox1.Text = s
- Return s
- End If
- Else
- If (s.StartsWith("www.")) Then
- s = "http://www." & s.Substring(4, s.Count() - 4)
- TextBox1.Text = s
- Return s
- Else
- s = "http://www." & s
- TextBox1.Text = s
- Return s
- End If
- End If
- End Function
- Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
- Dim s As String = TextBox1.Text.ToLower()
- TextBox1.Text = doCheck(s)
- End Sub
- Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
- Try
- Dim r As httpwebrequest = httpwebrequest.create(TextBox1.Text)
- Dim re As httpwebresponse = r.getresponse()
- MsgBox("Website responsive.")
- Catch ex As Exception
- MsgBox("Website un-responsive.")
- End Try
- End Sub
- End Class
Add new comment
- 28 views