Sign in to follow this  
Followers 0
bills

Need help with InputBox

27 posts in this topic

Im trying to make a script that gives me an option to choose which site to open in a IE window.

The problem is that when i choose for example $site1 IE tries to open the site http://$site1.

This is the code i got.

#include <IE.au3> 

$site1 = "http://www.google.com"
$site2 = "http://www.yahoo.com"
$site3 = "http://www.hotmail.com"



$valdsite = InputBox("choose site", "Choose from $site1, $site2, $site3","" , " M20")


If $valdsite = "$site1" Then
    $chosensite = $site1
EndIf
If $valdsite = "$site2" Then
    $chosensite = $site2
EndIf
If $valdsite = "$site3" Then
    $chosensite = $site3
EndIf


$chosensite = $valdsite

$oIE = _IECreate("about:blank")

_IENavigate ($oIE, $chosensite)

Can anyone help me?

//Bill

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

This should work out.

Alternative 1:

#Include<GUIConstants.au3>
Opt("GUIOnEventMode",1)
$mainfrm=GUICreate("Navigate Helper",120,100,-1,-1,-1)
$button1=GUICtrlCreateButton("Google",25,3,80,30)
$button2=GUICtrlCreateButton("Yahoo",25,33,80,30)
$button3=GUICtrlCreateButton("Hotmail",25,66,80,30)
GUICtrLSetOnEvent($button1,"Google")
GUICtrlSetOnEvent($button2,"Yahoo")
GUICtrlSetOnEvent($button3,"Hotmail")
GUISetOnEvent($GUI_EVENT_CLOSE,"Quit")
GUISetState()
While 1
    Sleep(1000)
WEnd
Func Google()
    ShellExecute("http://www.google.com")
EndFunc
Func Yahoo()
    ShellExecute("http://www.yahoo.com")
EndFunc
Func Hotmail()
    ShellExecute("http://www.hotmail.com")
EndFunc
Func Quit()
    Exit
EndFunc
oÝ÷ Ø    mz¹Ú¶+ÞÙ«­¢+Ø(%¹±Õ±ÐíU%
½¹ÍѹÑ̹ÔÌÐì(¥¹±Õ±Ðí%¹ÔÌÐì)=ÁÐ ÅÕ½ÐíU%=¹Ù¹Ñ5½ÅÕ½Ðì°Ä¤(ÀÌØíµ¥¹É´õU%
ÉÑ ÅÕ½Ðí9Ù¥Ñ!±ÁÈÅÕ½Ðì°ÈÀÀ°ÔÔ°´Ä°´Ä°´Ä¤(ÀÌØí½µ¼õU%
Ñɱ
ÉÑ
½µ¼ ÅÕ½ÐìÅÕ½Ðì°Ä°Ä°Ääà°ÄÀ°´Ä¤(ÀÌØíÕÑѽ¸õU%
ÑÉ1
ÉÑ    ÕÑѽ¸ ÅÕ½Ðí¼ÅÕ½Ðì°ÜÀ°ÈÈ°ØÀ°ÌÀ¤)U%
ÑÉ1MÑÑ ÀÌØí½µ¼°ÅÕ½Ðí¡ÑÑÀè¼½ÝÝܹ½½±¹½µñ¡ÑÑÀè¼½ÝÝܹ塽¼¹½µñ¡ÑÑÀè¼½ÝÝܹ¡½Ñµ¥°¹½´ÅÕ½Ðì°ÅÕ½Ðí¡ÑÑÀè¼½ÝÝܹ½½±¹½´ÅÕ½Ðì¤)U%
ÑɱMÑ=¹Ù¹Ð ÀÌØíÕÑѽ¸°ÅÕ½Ðí¼ÅÕ½Ðì¤)U%MÑ=¹Ù¹Ð ÀÌØíU%}Y9Q}
1=M°ÅÕ½ÐíEÕ¥ÐÅÕ½Ðì¤)U%MÑMÑÑ ¤)]¡¥±Ä(%M±À ÄÀÀÀ¤)]¹)Õ¹¼ ¤($ÀÌØí½%ô}%
ÉÑ ÅÕ½Ðí½ÕÐé±¹¬ÅÕ½Ðì¤(%}%9Ù¥Ñ ÀÌØí½%±U%
ÑɱI ÀÌØí½µ¼¤¤)¹Õ¹)Õ¹EեР¤(%á¥Ð)¹Õ¹
Edited by Generator

Share this post


Link to post
Share on other sites

Do not add quote directly around variables. :)

#include <IE.au3>

$site1 = "http://www.google.com"
$site2 = "http://www.yahoo.com"
$site3 = "http://www.hotmail.com"



$valdsite = InputBox("choose site", "Choose from $site1, $site2, $site3","" , " M20")


If $valdsite = $site1 Then
    $chosensite = $site1
EndIf
If $valdsite = $site2 Then
    $chosensite = $site2
EndIf
If $valdsite = $site3 Then
    $chosensite = $site3
EndIf


$chosensite = $valdsite

$oIE = _IECreate("about:blank")

_IENavigate ($oIE, $chosensite)

Share this post


Link to post
Share on other sites

#include <IE.au3>

$site1 = "http://www.google.com"
$site2 = "http://www.yahoo.com"
$site3 = "http://www.hotmail.com"

$valdsite = InputBox("choose site", "Choose from $site1, $site2, $site3")

If $valdsite = $site1 Then $chosensite = $site1
If $valdsite = $site2 Then $chosensite = $site2
If $valdsite = $site3 Then $chosensite = $site3

$chosensite = $valdsite

$oIE = _IECreate("about:blank")

_IENavigate($oIE, $chosensite)


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

Inputbox isn't as good because user can type something else, and if they type the whole website there is no point for it.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Inputbox isn't as good because user can type something else, and if they type the whole website there is no point for it.

Agreed...but you might want to show Bill his error... and then offer a better script. I did not see MHz's post or I would not have bothered. Mine just got rid of the error and the EndIf when it was not needed for a single line If. Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

Inputbox isn't as good because user can type something else, and if they type the whole website there is no point for it.

Maybe a bit of a shock, but we were showing the user what is wrong with their code rather then grinding up something totally different. Best to learn from your mistakes then taking someones else's code.

Share this post


Link to post
Share on other sites

Maybe a bit of a shock, but we were showing the user what is wrong with their code rather then grinding up something totally different. Best to learn from your mistakes then taking someones else's code.

I didn't even realize his mistake :)

Share this post


Link to post
Share on other sites

...and to beat a dead horse:

#include <IE.au3>

$site1 = "http://www.google.com"
$site2 = "http://www.yahoo.com"
$site3 = "http://www.hotmail.com"

$valdsite = InputBox("Choose site", "Choose from:" & @CR _
         & $site1 & @CR _
         & $site2 & @CR _
         & $site3)
If @Error = 1 Then Exit
 
If $valdsite = $site1 Then $chosensite = $site1
If $valdsite = $site2 Then $chosensite = $site2
If $valdsite = $site3 Then $chosensite = $site3

$chosensite = $valdsite

$oIE = _IECreate("about:blank")

_IENavigate($oIE, $chosensite)
I'm not sure if you wanted to show the site in your prompt and offer an Exit if cancel was selected.


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

I didn't even realize his mistake :)

Now big harm. You showed good alternative. But, remember, do not put down fellow helpers, OK. :)

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

...and to beat a dead horse:

#include <IE.au3>

$site1 = "http://www.google.com"
$site2 = "http://www.yahoo.com"
$site3 = "http://www.hotmail.com"

$valdsite = InputBox("Choose site", "Choose from:" & @CR _
         & $site1 & @CR _
         & $site2 & @CR _
         & $site3)
If @Error = 1 Then Exit
 
If $valdsite = $site1 Then $chosensite = $site1
If $valdsite = $site2 Then $chosensite = $site2
If $valdsite = $site3 Then $chosensite = $site3

$chosensite = $valdsite

$oIE = _IECreate("about:blank")

_IENavigate($oIE, $chosensite)
I'm not sure if you wanted to show the site in your prompt and offer an Exit if cancel was selected.
If $valdsite = $site1 Then **** ElseIf next line... would save 2 further conditions which speeds up the script. :)

Edit:

Sorry, typo.

Edited by MHz

Share this post


Link to post
Share on other sites

Now big harm. You showed good alternative. But, remember, do not put down fellow helpers, OK. :)

Another alternative, his original idea i think.

#Include<GUIConstants.au3>
#include<IE.au3>
Opt("GUIOnEventMode",1)
$mainfrm=GUICreate("Navigate Helper",200,55,-1,-1,-1)
$combo=GUICtrlCreateCombo("",1,1,198,10,-1)
$button=GUICtrLCreateButton("Go",70,22,60,30)
GUICtrLSetData($combo,"http://www.google.com|http://www.yahoo.com|http://www.hotmail.com","http://www.google.com")
GUICtrlSetOnEvent($button,"Go")
GUISetOnEvent($GUI_EVENT_CLOSE,"Quit")
GUISetState()
While 1
    Sleep(1000)
WEnd
Func Go()
    $oIE = _IECreate("about:blank")
    _IENavigate($oIE,GUICtrlRead($combo))
EndFunc
Func Quit()
    Exit
EndFunc

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

If $valdsite = $site1 Then **** ElseIf next line... would save 2 further conditions which speeds up the script. :)

Edit:

Sorry, typo.

True, but I try to avoid ElseIf with those new to AutoIt.

And that might be a mistake on my part.

Perhaps I should not consider one line If statements as one notch above basic knowledge and ElseIfs one notch above that.

Also, a stack of one line Ifs is an easy read - at least for me.

...poor horse

Edit: Hey Bill - pardon us whilst we chat among ourselves in your thread :-)

Hope that some or all of this helps. Let us know if you need something explained like the ElseIf or GUI stuff.

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

Opt('ExpandVarStrings', 1)          ; 0 = Don't expand, 1 = Do expand (Use $autoit$ variables in strings).

#include <IE.au3>

$site1 = "http://www.google.com"
$site2 = "http://www.yahoo.com"
$site3 = "http://www.hotmail.com"



$valdsite = InputBox("choose site", "Choose from $site1$, $site2$, $site3$","" , " M20")


If $valdsite = "$site1$" Then
    $chosensite = $site1
ElseIf $valdsite = "$site2$" Then
    $chosensite = $site2
ElseIf $valdsite = "$site3$" Then
    $chosensite = $site3
EndIf


$chosensite = $valdsite

$oIE = _IECreate("about:blank")

_IENavigate ($oIE, $chosensite)

Sorry, alittle elseif :">

Share this post


Link to post
Share on other sites

This should work out.

Alternative 1:

#Include<GUIConstants.au3>
Opt("GUIOnEventMode",1)
$mainfrm=GUICreate("Navigate Helper",120,100,-1,-1,-1)
$button1=GUICtrlCreateButton("Google",25,3,80,30)
$button2=GUICtrlCreateButton("Yahoo",25,33,80,30)
$button3=GUICtrlCreateButton("Hotmail",25,66,80,30)
GUICtrLSetOnEvent($button1,"Google")
GUICtrlSetOnEvent($button2,"Yahoo")
GUICtrlSetOnEvent($button3,"Hotmail")
GUISetOnEvent($GUI_EVENT_CLOSE,"Quit")
GUISetState()
While 1
    Sleep(1000)
WEnd
Func Google()
    ShellExecute("http://www.google.com")
EndFunc
Func Yahoo()
    ShellExecute("http://www.yahoo.com")
EndFunc
Func Hotmail()
    ShellExecute("http://www.hotmail.com")
EndFunc
Func Quit()
    Exit
EndFunc
This one is great!

The only thing here which i need is to make it open the links in Internet Explorer.

How do i do that?

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

#Include<GUIConstants.au3>
#Include<IE.au3>
Opt("GUIOnEventMode",1)
$mainfrm=GUICreate("Navigate Helper",120,100,-1,-1,-1)
$button1=GUICtrlCreateButton("Google",25,3,80,30)
$button2=GUICtrlCreateButton("Yahoo",25,33,80,30)
$button3=GUICtrlCreateButton("Hotmail",25,66,80,30)
GUICtrLSetOnEvent($button1,"Google")
GUICtrlSetOnEvent($button2,"Yahoo")
GUICtrlSetOnEvent($button3,"Hotmail")
GUISetOnEvent($GUI_EVENT_CLOSE,"Quit")
GUISetState()
While 1
    Sleep(1000)
WEnd
Func Google()
    $oIE = _IECreate("about:blank")
    _IENavigate($oIE,"http://www.google.com")
EndFunc
Func Yahoo()
     $oIE = _IECreate("about:blank")
    _IENavigate($oIE,"http://www.yahoo.com")
EndFunc
Func Hotmail()
     $oIE = _IECreate("about:blank")
    _IENavigate($oIE,"http://www.hotmail.com")
EndFunc
Func Quit()
    Exit
EndFunc

This should do it

Edit: Forgot Include

Edited by Generator

Share this post


Link to post
Share on other sites

Im getting this error when i try to put the code inside my large script.

Ive tried adding a few WEnd but the error wont disappear.

>Running:(3.2.4.9):C:\Program Files\AutoIt3\autoit3.exe "C:\Documents and Settings\Bill\Desktop\2.au3"

C:\Documents and Settings\Bill\Desktop\2.au3 (87) : ==> "While" statement has no matching "Wend" statement.:

Func Knapp1()

The code is much to large to put here and i kinda get the feeling that theres some kind of need to close the functions?

Anyways if you got any more tips id be grateful.

Thanks for all your help!

//Bill

Share this post


Link to post
Share on other sites

Ive shortened the code a bit:

#include <IE.au3> 
#Include<GUIConstants.au3>

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Alla definitioner;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

$trafiksidan = "http://www.trafiksidan.com"
$meraporr = "http://www.meraporr.com"
$password = "lallare"
$pagetitle = "Elins Lilla Sida"
$pagedescription = "Se mig posera naken framför kameran"
$emailadress = "stevenzzzon@yahoo.com"
$email1 = "mobilekillen@hotmail.com"
$pass1 = "daddlos"
$pornstar = "http://www.trafiksidan.com/link/index.jsp?a=profile&s=links&siteId=31"
$porrfilm = "http://www.trafiksidan.com/link/index.jsp?a=profile&s=links&siteId=40"
$hittafitta = "http://www.trafiksidan.com/link/index.jsp?a=profile&s=links&siteId=41"
$gratisporr = "http://www.trafiksidan.com/link/index.jsp?a=profile&s=links&siteId=42"
$smsporr = "http://www.trafiksidan.com/link/index.jsp?a=profile&s=links&siteId=38"
$klassiskporr = "http://www.trafiksidan.com/link/index.jsp?a=profile&s=links&siteId=32"
$city = "Stockholm"
$Number = 0

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Här börjar scriptet;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Ställer in Värden;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Opt("WinTitleMatchMode", 2)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Öppnar IE och navigerar till Trafiksidan;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

$oIE = _IECreate($trafiksidan)

If Not WinActive("www.trafiksidan.com") Then
WinActivate("www.trafiksidan.com")
EndIf

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Trafiksidan uppe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

$o_form1 = _IEFormGetObjByName ($oIE, "login")
$o_email1 = _IEFormElementGetObjByName ($o_form1, "email")
$o_pass1 = _IEFormElementGetObjByName ($o_form1, "password")
$o_submit1 = _IEFormElementGetObjByName ($o_form1, "submit")

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Loggar in på trafiksidan;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

_IEFormElementSetValue ($o_email1, $email1)
_IEFormElementSetValue ($o_pass1, $pass1)
_IEFormSubmit ($o_form1)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Öppnar nytt IE fönster med porrlänkar;;;;;;;;;;;;;;;;;;;;;;;;;;;

$oIE2 = _IECreate($meraporr)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Flippar tillbaka till trafiksidan;;;;;;;;;;;;;;;;;;;;;;;;;;;;

If Not WinActive("www.trafiksidan.com") Then
WinActivate("www.trafiksidan.com")
EndIf

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Påbörjar WHILE loop;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

While 1

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Väljer SITE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Opt("GUIOnEventMode",1)

$mainfrm=GUICreate("Välj Site",150,200,5,5,-1)
$button1=GUICtrlCreateButton("Pornstar",25,3,110,30)
$button2=GUICtrlCreateButton("Porrfilm",25,33,110,30)
$button3=GUICtrlCreateButton("HittaFitta",25,66,110,30)
$button4=GUICtrlCreateButton("GratisPorr",25,99,110,30)
$button5=GUICtrlCreateButton("SMSPorr",25,132,110,30)
$button6=GUICtrlCreateButton("KlassiskPorr",25,165,110,30)
GUICtrLSetOnEvent($button1,"Knapp1")
GUICtrlSetOnEvent($button2,"Knapp2")
GUICtrlSetOnEvent($button3,"Knapp3")
GUICtrlSetOnEvent($button4,"Knapp4")
GUICtrlSetOnEvent($button5,"Knapp5")
GUICtrlSetOnEvent($button6,"Knapp6")
GUISetOnEvent($GUI_EVENT_CLOSE,"Quit")
GUISetState()
;While 1
    Sleep(10000)
;WEnd

Func Knapp1()
    _IENavigate($oIE,"http://www.trafiksidan.com/link/index.jsp?a=profile&s=links&siteId=31")
EndFunc

Func Knapp2()
    _IENavigate($oIE,"http://www.trafiksidan.com/link/index.jsp?a=profile&s=links&siteId=40")
EndFunc

Func Knapp3()
    _IENavigate($oIE,"http://www.trafiksidan.com/link/index.jsp?a=profile&s=links&siteId=41")
EndFunc

Func Knapp4()
    _IENavigate($oIE,"http://www.trafiksidan.com/link/index.jsp?a=profile&s=links&siteId=42")
EndFunc

Func Knapp5()
    _IENavigate($oIE,"http://www.trafiksidan.com/link/index.jsp?a=profile&s=links&siteId=38")
EndFunc

Func Knapp6()
    _IENavigate($oIE,"http://www.trafiksidan.com/link/index.jsp?a=profile&s=links&siteId=32")
EndFunc

Func Quit()
    Exit
EndFunc

WEnd

Share this post


Link to post
Share on other sites

I solved the problem.

Moved the code to before the while loop.

Although i dont understand why it wouldnt work otherwise?

Maybe someone can explain that for me?

Thank you all for your help!

//Bill

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

...Although i dont understand why it wouldnt work otherwise?

Maybe someone can explain that for me?...

If you have the full (free) version of SciTE installed, then make an au3 file with the exact code from your post here: http://www.autoitscript.com/forum/index.ph...st&p=351836 and press Ctrl-t to "Tidy" the code. You should see some text in red that states something like:

"while" Not closed before "Func" statement

and

"func" cannot be inside any IF/Do/While/For/Case/Func statement

Like you mentioned, once you move all of your Func/EndFunc outside of the loop, your code should work. As to why you cannot have a Func inside a loop... you should only define a Func one time, not over and over. There is also a more technical explanation that I think I understand - but I could not do justice to.

hope this helps

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

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