vb.net instant site search

I’m not really sure if there are other options in bringing instant search to sites like wikipedia, bing, yahoo, ask. Or any other sites which offers search functionality. But this is the thing that I know so here I am sharing it to you:


The screenshot above is a screenshot of an application made using visual studio 2008. Using the language vb.net.

As you can see there aren’t any buttons which the user can press in order to search on something.

The program is using the text change event in vb.net wherein every key press in the keyboard fires up an event which then executes the search.

I’m feeling good so I’m gonna show you the code, but not all of it.

This is the most important:

Private Sub refreshBrowser()
       Dim _search As String
           _search = Trim(TextBox2.Text)
           If RadioButton1.Checked = True Then
               WebBrowser1.Navigate(New System.Uri(" http://www.google.com/search?q=" + _search))
           ElseIf RadioButton2.Checked = True Then
               WebBrowser1.Navigate(New System.Uri(" http://en.wikipedia.org/wiki/" + _search))
           End If
       Catch ex As Exception
                End Try
End Sub

It’s the subroutine/method that is being called everytime a textchange event is fired up. As you can see I only added search functionality for google and wikipedia. But it is my bad, since google doesn’t need this functionality anymore because instant-search is already integrated on their site. So only the wikipedia is useful here. Since they don’t have instant-search yet.

If you’re wondering, what’s the meaning of this string:


Then try to paste it on your browsers address bar. And then add a random search query like ‘dog’:


Press enter and see what happens.

That specific string is called the query string. I won’t delve much further on what query string is, so be sure to search for it on google:

http://www.google.com/search?q=query string

You might already know what happens next, but I’m going to tell it anyway.

I added the text in the textbox to that query string to produce a result.

But as you notice, I wrap it in a built-in method called ‘trim’ which trims or remove leading and trailing whitespaces on the text, just to make sure its not searching a blank space.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s