MXL Magazine Online
HOMELATEST ISSUEARTICLESBINARY BINGEJAVA JNUKYGUI LABLINKSSHOPABOUT CONTACT  
Home > Issue 008 > Coding Showdown > Adding web search to your app

Adding web search to your app

Requirements: Microsoft Visual Basic Studio 6.0 or similar

If you want to add something extra to your application then try adding in a web search capability to your application. A good example of this is TheGurkin news ticker which allows you to run a variety of web searches from the application along side the archives search. All you need it a button users hit to search, a text box for users to type in their search term and a web browser component. Web browsers are not in the insert panel as standard but can be added by selected the Microsoft Internet Components group.

Variables
Lets give our three elements some names
Button - gobutton
Text box - searchterm
Web browser - web1

The text box
We are off to a good start as we do not need to add any code into the text box. Although you may want to add a caption such as "Search..." If not then just clear the default text and leave the box blank.

Web Browser
This is the browser that the users results will appear in. When the application first loads up you may not want this to appear so go into the application and go into the load information. If you want it the be hidden at the start then add the following code:

web1.Visible = False

If you want it to load up with some web address in then add the following code instead:

web1.Navigate2 ("http://www.mworld.us")

The Button
Stangly enough the most important part of the script is the code in the button. When a user clicks it we want the search to begin using the text from the text box "searchterm" which you will change if you named the text box something else.

Web1.Visible = "true"
Web1.Navigate2 ("http://www.google.com/search?q=" + searchterm.Text)

The first command here makes sure that the results box is visible. The second line tells the results box to navigate to Google's results page and adds the search term into the URL. This can be changed to for any search engine. Here are a few more examples:

Web1.Navigate2 ("http://www.alltheweb.com/search?cat=web&cs=utf-8&l=any&q=" + searchterm.Text)

Web1.Navigate2 ("http://www.amazon.com/exec/obidos/external-search/103-7508255-9028656?mode=blended&tag=lexico&keyword=" + search1.Text)

Web1.Navigate2 ("http://www.yellowpages.com/asp/search/SearchResult.asp?page=home&searchtips=&moresearchoptions=&searchform=homesearch&typeorname=name&search=" + search1.Text + "&city=&state=NATIONWIDE")