(view source code of gconv.vbs as plain text)
Option ExplicitDim i, strQueryWith WScript.Arguments
If .Named.Count > 0 Then Syntax
If .Unnamed.Count < 4 Then Syntax
For i = 0 To .Unnamed.Count - 1
strQuery = strQuery & "+" & .Unnamed(i)
NextEnd With
strQuery = Mid( strQuery, 2 )
WScript.Echo GoogleUnitConversion( strQuery )
Function GoogleUnitConversion( myQuery )
' Name: GoogleUnitConversion' Function: Convert units using Google Calculater and Internet Explorer' Usage: WScript.Echo GoogleUnitConversion( "10+cm+in+inches" )' Returns: 10 centimeters = 3.93700787 inches'' Written by Rob van der Woude' http://www.robvanderwoude.com Dim blnTimedOut, i, j, objIE, objMatches, objRE, strAllText, strMatch, strPattern, strURL ' Open the appropriate URL in Internet ExplorerstrURL = "http://www.google.com/search?q=" & myQuery & "&pws=0&hl=en&num=1"
strPattern = "\)\s*" & Left( myQuery, InStr( myQuery, "+" ) -1 ) & "\s*[^=]+\s*=\s*[\d\., ]+(\s+[a-z]+)*\s*" _
& Right( myQuery, Len( myQuery ) - InStrRev( myQuery, "+" ) )
Set objIE = CreateObject( "InternetExplorer.Application" )
objIE.Visible = False
objIE.Navigate2 strURL
' Wait till IE is readyi = 0
blnTimedOut = False
Do While objIE.Busy
WScript.Sleep 100
i = i + 1
' Time out after 10 secondsIf i > 100 Then
blnTimedOut = True
Exit Do
End If
Loop ' Retrieve the URL's textIf Not blnTimedOut Then strAllText = objIE.Document.Body.InnerText
' Close the Internet Explorer sessionobjIE.Quit
Set objIE = Nothing
' Use a regular expression to extract the result from the web pageSet objRE = New RegExp
objRE.Global = True
objRE.IgnoreCase = True
objRE.Pattern = strPattern
Set objMatches = objRE.Execute( strAllText )
j = objMatches.Count - 1
If j < 0 Then
strMatch = ""
ElsestrMatch = Trim( Mid( objMatches.Item(j).Value, 2 ) )
End If
Set objMatches = Nothing
Set objRE = Nothing
GoogleUnitConversion = strMatchEnd Function
Sub Syntax( )
Dim strMsgstrMsg = "GConv.vbs, Version 1.10" & vbCrLf _
& "Convert units using Google Calculater and Internet Explorer" _
& vbCrLf & vbCrLf _
& "Usage: CSCRIPT //NoLogo GCONV.VBS number unit IN new_unit" _
& vbCrLf & vbCrLf _
& "E.g: 10 cm in inches" _
& vbCrLf & vbCrLf _
& "Returns: 10 centimeters = 3.93700787 inches" _
& vbCrLf & vbCrLf _
& "Written by Rob van der Woude" & vbCrLf _
& "http://www.robvanderwoude.com"
WScript.Echo strMsg
WScript.Quit 1
End Sub
page last modified: 2025-10-11; loaded in 0.0072 seconds