Let's create it, add 3 Buttons and two Textboxes by the way arrange to look like this :
The Buttons and their usages : 
- Button 1 - Create TinyURL
 - Button 2 - Copy To Clipboard
 - Button 3 - Refresh
 
Button 1 code :
    'checking the network availability
        If My.Computer.Network.IsAvailable Then
            'creating the webrequest point
            Dim Request As WebRequest = DirectCast(WebRequest.Create("http://tinyurl.com/api-create.php?url=" + TextBox1.Text), HttpWebRequest)
            'defining the response
            Dim Response As HttpWebResponse = DirectCast(Request.GetResponse, HttpWebResponse)
            'getting the response
            Dim Stream As New StreamReader(Response.GetResponseStream)
            'writing the response(shortened URL)
            Dim ShortURL As String = Stream.ReadToEnd
            TextBox2.Text = ShortURL
        Else
            MsgBox("Please Connect To The Internet And Try Again", MsgBoxStyle.Critical)
        End If
Button 2 code :
     'copying...
        Clipboard.SetText(TextBox2.Text)
        MsgBox("Sucessfully Copied To Clipboard")
Button 3 code :
TextBox1.Text = "http://"
        TextBox2.Text = " "
        TextBox2.Enabled = False
Full source code :
Imports System.Net
Imports System.IO
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'checking the network availability
        If My.Computer.Network.IsAvailable Then
            'creating the webrequest point
            Dim Request As WebRequest = DirectCast(WebRequest.Create("http://tinyurl.com/api-create.php?url=" + TextBox1.Text), HttpWebRequest)
            'defining the response
            Dim Response As HttpWebResponse = DirectCast(Request.GetResponse, HttpWebResponse)
            'getting the response
            Dim Stream As New StreamReader(Response.GetResponseStream)
            'writing the response(shortened URL)
            Dim ShortURL As String = Stream.ReadToEnd
            TextBox2.Text = ShortURL
        Else
            MsgBox("Please Connect To The Internet And Try Again", MsgBoxStyle.Critical)
        End If
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        'copying...
        Clipboard.SetText(TextBox2.Text)
        MsgBox("Successfully Copied To Clipboard")
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TextBox1.Text = "http://"
        TextBox2.Text = " "
        TextBox2.Enabled = False
    End Sub
End Class
Testing... :TextBox1 is for the original link and TextBox2 is for the shortened link.
I hope you liked this tutorial.


6 comments
thanks a lot brother.
Replyi love you
i got two error
Reply1. Error 1 Namespace declaration must start with 'xmlns'.
2. Error 3 'Private Sub Button1_Click(sender As Object, e As System.EventArgs)' has multiple definitions with identical signatures.
That is your errors. You have two / more subs named Button1_Click. Delete one. Don't put in namespace. You just copied and pasted. Don't.
ReplyHow can i generate shortner url in bulk?
ReplySqrt Function
ReplyTab Function
UBound Function
Val Function
Weekday Function
Year Function
Thank you
ReplyPost a Comment
Note: Only a member of this blog may post a comment.