Sign in to follow this  
Followers 0
neo van matix

Problem with InputBox()

4 posts in this topic

Hi guys,

i'm writing a little script, which opens a InputBox if you hit "F1". You insert a word, hit enter, and firefox opens which shows you the search-result page of google or wikipedia.

My Code:

#cs ------------------------------------------------------------

 AutoIt Version: 3.2.2.0
 Author:         Bastian Müller

 Script Function:
    search on wikipedia/google per hotkey

#ce ------------------------------------------------------------

; Script Start - Add your code below here

Opt("TrayOnEventMode",1)
Opt("TrayMenuMode", 1)

TraySetClick("9")

$search = TrayCreateMenu("Engine")
$MenuItem1 = TrayCreateItem("Google", $search, -1, 1)
$MenuItem2 = TrayCreateItem("Wikipedia", $search, -1, 1)
$close = TrayCreateItem("Beenden")

TrayItemSetState($MenuItem2, 1)

TrayItemSetOnEvent($close, "CLOSE")
HotKeySet("{F1}", "SEARCH")

while(1)
   sleep(1000)
WEnd

Func CLOSE()
   Exit
EndFunc

Func SEARCH() 
   IF TrayItemGetState($MenuItem2) = 65 Then
      $searchengine = "Wikipedia"
      $searchenginelink = "http://de.wikipedia.org/wiki/"
   Else
      $searchengine = "Google"
      $searchenginelink = "http://www.google.de/search?hl=de&q="
   EndIf
    
   $height = @DesktopHeight-200
   $width  = @DesktopWidth-200
    
   $box = InputBox("BaMu Search", "Text to search on " _
   & $searchengine, "", "", 119, 115, $width, $height)
   If $box Then
      Run("D:\Programme\Mozilla Firefox\firefox.exe " _
      & $searchenginelink & $box)
   EndIf
EndFunc

My problem:

If i insert more than one word into the input-box, firefox opens as much tabs as words were typed. If i search for "1 2 3 4 5", firefox opens 5 windows: In the first, i get the result page of google or wikipedia for "1", and 4 other tabs like "http://2/", "http://3/", and so on.

how would you solve this problem? dont know how...


Attention! English noob ^^

Share this post


Link to post
Share on other sites



Try StringReplace($box," ","%20") 'ing your search string...most browsers don't like spaces in the address bar, but accept a literal %20 string to mean space instead. Otherwise, trying enclosing the entire Run string in quotes so firefox only sees it as a single parameter, rather than 5 different parameters separated by spaces.

Give it a shot and post the results! :)


"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110

Share this post


Link to post
Share on other sites

Arg, damn,.. yeah, thats it!

firefox.exe handles strings, separated by whitespaces, each as own parameter... %1, %2, and so on... thats the cause, why i got many tabs...

Thanks :)


Attention! English noob ^^

Share this post


Link to post
Share on other sites

Run("D:\Programme\Mozilla Firefox\firefox.exe " _
      & $searchenginelink & $box)

This would be better internet launch

ShellExecute("firefox.exe",$searchenginelink & $box)

[font="Verdana"]Keith (Kogmedia)[/font]My ScriptQuick Search - Internet / Hard Drive Search

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0