• We just launched and are currently in beta. Join us as we build and grow the community.

How to Create a Website URL Verifier in Visual Basic

timo02

Turn-Based Strategist
T Rep
0
0
0
Rep
0
T Vouches
0
0
0
Vouches
0
Posts
76
Likes
67
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 200 XP
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.

  1. Private

    Function

    doCheck(ByVal

    s As

    String

    )
  2. If

    (s.StartsWith("http://www."

    ) Or

    s.StartsWith("https://www."

    )) Then
  3. Return s
  4. ElseIf

    (s.StartsWith("http://"

    )) Then
  5. If

    (s.Contains("www."

    )) Then
  6. s = "http://www."

    & s.Substring(1, s.Count - 1)
  7. TextBox1.Text = s
  8. Return s
  9. Else
  10. s = "http://www."

    & s.Substring(7, s.Count - 7)
  11. TextBox1.Text = s
  12. Return s
  13. End

    If
  14. ElseIf

    (s.StartsWith("https://"

    )) Then
  15. If

    (s.Contains("www."

    )) Then
  16. s = "https://"

    & s.Substring(12, s.Count() - 12)
  17. TextBox1.Text = s
  18. Return s
  19. Else
  20. s = "https://www."

    & s.Substring(8, s.Count - 8)
  21. TextBox1.Text = s
  22. Return s
  23. End

    If
  24. Else
  25. If

    (s.StartsWith("www."

    )) Then
  26. s = "http://www."

    & s.Substring(4, s.Count() - 4)
  27. TextBox1.Text = s
  28. Return s
  29. Else
  30. s = "http://www."

    & s
  31. TextBox1.Text = s
  32. Return s
  33. End

    If
  34. End

    If
  35. End

    Function

Step 3:
Next lets run the function on button1 click...

  1. Private

    Sub

    Button1_Click(sender As

    Object

    , e As

    EventArgs) Handles Button1.Click
  2. Dim

    s As

    String

    = TextBox1.Text.ToLower()
  3. TextBox1.Text = doCheck(s)
  4. End

    Sub

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.

  1. Private

    Sub

    Button2_Click(sender As

    Object

    , e As

    EventArgs) Handles Button2.Click
  2. Try
  3. Dim

    r As

    httpwebrequest = httpwebrequest.create(TextBox1.Text)
  4. Dim

    re As

    httpwebresponse = r.getresponse()
  5. MsgBox("Website responsive."

    )
  6. Catch ex As

    Exception
  7. MsgBox("Website un-responsive."

    )
  8. End

    Try
  9. End

    Sub

Project Complete!
That's it! Below is the full source code and download to the project files.

  1. Imports System.Net
  2. Public

    Class Form1
  3. Private

    Function

    doCheck(ByVal

    s As

    String

    )
  4. If

    (s.StartsWith("http://www."

    ) Or

    s.StartsWith("https://www."

    )) Then
  5. Return s
  6. ElseIf

    (s.StartsWith("http://"

    )) Then
  7. If

    (s.Contains("www."

    )) Then
  8. s = "http://www."

    & s.Substring(1, s.Count - 1)
  9. TextBox1.Text = s
  10. Return s
  11. Else
  12. s = "http://www."

    & s.Substring(7, s.Count - 7)
  13. TextBox1.Text = s
  14. Return s
  15. End

    If
  16. ElseIf

    (s.StartsWith("https://"

    )) Then
  17. If

    (s.Contains("www."

    )) Then
  18. s = "https://"

    & s.Substring(12, s.Count() - 12)
  19. TextBox1.Text = s
  20. Return s
  21. Else
  22. s = "https://www."

    & s.Substring(8, s.Count - 8)
  23. TextBox1.Text = s
  24. Return s
  25. End

    If
  26. Else
  27. If

    (s.StartsWith("www."

    )) Then
  28. s = "http://www."

    & s.Substring(4, s.Count() - 4)
  29. TextBox1.Text = s
  30. Return s
  31. Else
  32. s = "http://www."

    & s
  33. TextBox1.Text = s
  34. Return s
  35. End

    If
  36. End

    If
  37. End

    Function
  38. Private

    Sub

    Button1_Click(sender As

    Object

    , e As

    EventArgs) Handles Button1.Click
  39. Dim

    s As

    String

    = TextBox1.Text.ToLower()
  40. TextBox1.Text = doCheck(s)
  41. End

    Sub

  42. Private

    Sub

    Button2_Click(sender As

    Object

    , e As

    EventArgs) Handles Button2.Click
  43. Try
  44. Dim

    r As

    httpwebrequest = httpwebrequest.create(TextBox1.Text)
  45. Dim

    re As

    httpwebresponse = r.getresponse()
  46. MsgBox("Website responsive."

    )
  47. Catch ex As

    Exception
  48. MsgBox("Website un-responsive."

    )
  49. End

    Try
  50. End

    Sub
  51. End

    Class


Download
You must upgrade your account or reply in the thread to view the hidden content.
 

452,496

327,345

327,353

Top