Click here to Skip to main content
15,898,920 members

Comments by newmodel (Top 1 by date)

newmodel 13-Feb-11 9:54am View    
Deleted
Here's a quick hack to make it also work when the cursor is at the beginning of the search phrase as is often the case for me:

Sub GoogleSearchMSDN_FeelingLucky()
GoogleSearchMSDN(True)
End Sub
Sub GoogleSearchMSDN(Optional ByVal feelingLucky As Boolean = False)
Dim url As String
Dim text As String
Dim searchFor As TextSelection = DTE.ActiveDocument.Selection()

If Not searchFor.IsEmpty Then
'Search value is selected. Get the selected text.
text = searchFor.Text
Else
'Text cursor is on the search value.
'Store the current cursor location
Dim currentColumn As Integer = searchFor.ActivePoint.DisplayColumn
' Check whether the character before the cursor is whitespace
searchFor.CharLeft()
searchFor.CharRight(True)
If searchFor.Text.Trim = "" Then
' Start selection from the current cursor position
searchFor.CharRight()
Else
'Move to the beginning of the word
searchFor.WordLeft()
End If
'Select to the end of the word
searchFor.WordRight(True)
text = Trim(searchFor.Text)
'Move the cursor back to the original position
searchFor.MoveToDisplayColumn(0, currentColumn)
End If

url = "http://www.google.com/search?q=MSDN+" + text
If feelingLucky Then
url += "&btnI=745"
End If

'Launch search in default browser
System.Diagnostics.Process.Start(url)
End Sub