Program Google in VB.NET

Create GUI and console Google search applications with Visual Basic and the .NET framework.

Along with the functionally identical C# version [Hack #99] , the Google Web APIs Developer’s Kit (dotnet/Visual Basic folder) includes a sample Google search in Visual Basic. While you can probably glean just about all you need from the Google Demo Form.vb code, this hack provides basic code for a simple console Google search application without the possible opacity of a full-blown Visual Studio .NET project.

Tip

Compiling and running this hack requires that you have the .NET Framework (http://msdn.microsoft.com/netframework/downloads/updates/default.aspx) installed.

The Code

Save the following code to a text file called googly.vb:

' googly.vb
' A Google Web API VB.NET console application.
' Usage: googly.exe <query>
' Copyright (c) 2002, Chris Sells.
' No warranties extended. Use at your own risk.
Imports System
Module Googly
  Sub Main(ByVal args As String( ))
    ' Your Google API developer's key.
    Dim googleKey As String = "insert key here" ' Take the query from the command line. If args.Length <> 1 Then Console.WriteLine("Usage: google.exe <query>") Return End If Dim query As String = args(0) ' Create a Google SOAP client proxy, generated by: ' c:\> wsdl.exe /l:vb http://api.google.com/GoogleSearch.wsdl Dim googleSearch As GoogleSearchService = New GoogleSearchService( ) ' Query Google. Dim results As GoogleSearchResult = googleSearch. doGoogleSearch(googleKey, query, ...

Get Google Hacks, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.