15,898,920 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
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