Monday, August 04, 2003

Well, this is it. My idea was: If I search each word in google and then post the first link, it's dumb and easy, why not have some script doing it for me? Let's go. So I did it using word macros, quick and crap. It works. The thing is it's the 'Feeling lucky' links which is opened, no more human selection. That is bad. Maybe I'll code an editor in which you have a side-window doing google search on any selected word, and then you pick one and the link is built. Yeah, I'll think about that. Anyway, here is the code I've used here.


Sub googlethat()
While ActiveDocument.Words.Count > 1
searchtext = ActiveDocument.Words(1).Text
ActiveDocument.Words(1).Delete
searchstring = ""
For i = 1 To Len(searchtext)
myletter = Mid(searchtext, i, 1)
ascval = Asc(myletter)
If ((ascval > 64) And (ascval < 91)) Or _
((ascval > 96) And (ascval < 124)) Then
searchstring = searchstring & myletter
Else
searchstring = searchstring & "%" & Hex(ascval)
End If
Next i
outstring = outstring _
& "<a href=""http://www.google.com/search?hl=en&q=%22" _
& searchstring & "%22&btnI=I'm+Feeling+Lucky"">" _
& searchtext & "</a>"
Wend
Selection.TypeText Text:=outstring
End Sub

No comments: