hyperlink valid test

hassanintern

New member
Joined
Jun 4, 2013
Messages
4
Programming Experience
Beginner
i want to see if the hyperlink ie entereted in textbox1: is valid or not. i developed this code but this code only gives hyperlink not working. any thoughts what is wrong with it?


Public Class Form1

    Dim req As System.Net.WebRequest
    Dim resp As System.Net.WebResponse

    Public Sub IsURLValid()
        Dim url As New System.Uri("TextBox1.Text")
        req = System.Net.WebRequest.Create(url)
        resp = req.GetResponse()
    End Sub

    Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If req Is Nothing Then
            MessageBox.Show("Hyperlink not working")
        Else
            MsgBox("hyperlink is good")
        End If
    End Sub

End Class
 
Last edited by a moderator:
First of all, there's no use getting the Text of the TextBox when the form is first created because you haven't entered anything into it at that stage. You need to get the current Text at the time of the text, i.e. in the Click event handler of the Button.

Secondly, you're not getting the Text of the TextBox anyway. What do double quotes signify? A String literal. If you do this:
VB.NET:
MessageBox.Show("TextBox1.Text")
what do you see? Do you see the Text from TextBox1? No, you don't. You see the literal text "TextBox1.Text". Get rid of the double quotes because you don't want a String literal.
 
Back
Top