baldbox Posted April 12, 2011 Share Posted April 12, 2011 I am very new to AutoIt and it is very cool; I copy and paste code and it works nice but I don't have a clue how to work with cases. Here is my situation: I am making a little login application that has 2 buttons; Login to web1 and Login to web2 using the same user and pass. but this is where I have trouble because I don't know much about the language. basically: Button 1 Case1 winexists web1 messagebox: sorry webpage exists. Case2 win not exists web1 and win not exists web2 _iecreate send user send pass case3 win not exists web1 and win exists web2 _iecreate Button2 Case1 winexists web2 messagebox: sorry webpage exists. Case2 win not exists web2 and win not exists web1 _iecreate send user send pass case3 win not exists web2 and win exists web1 _iecreate send pass This is good but I don't have an idea how it works. Can you help? Thanks Link to comment Share on other sites More sharing options...
wakillon Posted April 12, 2011 Share Posted April 12, 2011 Welcome to the Forums ! Something like this ?Switch $Ctrl Case $Button1 Select Case winexists web1 ; messagebox: sorry webpage exists. Case not ( winexists web1 and winexists web2 ) ; _iecreate ; send user ; send pass case not winexists web1 and winexists web2 ; _iecreate EndSelect Case $Button2 Select Case winexists web2 ; messagebox: sorry webpage exists. Case not ( winexists web1 and winexists web2 ) ; _iecreate ; send user ; send pass Case not winexists web2 and winexists web1 ; _iecreate ; send pass EndSelect EndSwitch AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
baldbox Posted April 12, 2011 Author Share Posted April 12, 2011 Wow... I'm going to try that. I really don't know a thing about this. Thanks for your help. Link to comment Share on other sites More sharing options...
baldbox Posted April 12, 2011 Author Share Posted April 12, 2011 Sorry... it looks like it works but I don't know how to declare the $Ctrl. Thanks. Link to comment Share on other sites More sharing options...
wakillon Posted April 12, 2011 Share Posted April 12, 2011 Sorry... it looks like it works but I don't know how to declare the $Ctrl. Thanks. like this : While 1 $msg = GUIGetMsg ( ) Switch $msg Case $Button1 Select Case winexists web1 ; messagebox: sorry webpage exists. Case not ( winexists web1 and winexists web2 ) ; _iecreate ; send user ; send pass Case not winexists web1 and winexists web2 ; _iecreate EndSelect Case $Button2 Select Case winexists web2 ; messagebox: sorry webpage exists. Case not ( winexists web1 and winexists web2 ) ; _iecreate ; send user ; send pass Case not winexists web2 and winexists web1 ; _iecreate ; send pass EndSelect EndSwitch WEnd AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
baldbox Posted April 12, 2011 Author Share Posted April 12, 2011 Here is what I'm trying to do but doesn't work. It doesn't open the websites. I don't know what I'm missing... Keep in mind that I'm a newbie #RequireAdmin #include <GUIConstants.au3> #include <IE.au3> #include <EditConstants.au3> Global $GUIWidth Global $GUIHeight HotKeySet("{ESC}", "Terminate") Func Terminate() Exit 0 EndFunc $GUIWidth = 200 $GUIHeight = 200 ;Create main/parent window $ParentWin = GUICreate("Login", $GUIWidth, $GUIHeight) ;Save the position of the parent window $filemenu = GuiCtrlCreateMenu ("File") $fileitem = GuiCtrlCreateMenuitem ("Website",$filemenu) $separator1 = GuiCtrlCreateMenuitem ("",$filemenu) $exititem = GuiCtrlCreateMenuitem ("Exit",$filemenu) $helpmenu = GuiCtrlCreateMenu ("About") $aboutitem = GuiCtrlCreateMenuitem ("Author",$helpmenu) $Button1 = GUICtrlCreateButton("Login to web1", 25, 100, 150) GUICtrlSetState(-1, $GUI_FOCUS) ; the focus is on this button GUICtrlSetColor(-1,0x00008b) ; Color font GuiCtrlSetCursor(-1,0); Make a cursor $Button2 = GUICtrlCreateButton("Login to web2", 25, 140, 150) GUICtrlSetState(-1, $GUI_FOCUS) ; the focus is on this button GUICtrlSetColor(-1,0x00008b) ; Color font GuiCtrlSetCursor(-1,0); Make a cursor GuiCtrlCreateLabel("ID:", 25, 15, 200); Creates Label GUICtrlSetColor(-1,0x00008b) ; Color font GuiCtrlCreateLabel("Password:", 25, 55, 200); Creates Label GUICtrlSetColor(-1,0x00008b) ; Color font $user = GuiCtrlCreateInput("", 25, 30, 145, 20) $pwuser = GuiCtrlCreateInput("", 25, 70, 145, 20, $ES_PASSWORD) $name = GUICtrlRead($user) $pass = GUICtrlRead($pwuser) $Ctrl = GUISetState () ; will display a dialog box Do $msg = GUIGetMsg() if $msg = $fileitem Then $file = _IECreate("http://www.",1,1,1,1) ;open Website EndIf if $msg = $exititem Then ExitLoop EndIf if $msg = $aboutitem Then Msgbox(64,"About","This application" & @CRLF & "was created by me" & @CRLF & "It temporarily stores" & @CRLF & "your ID and your password" & @CRLF & "to Login to .. or .."& @CRLF & "It discards all information on Exit.") EndIf Switch $Ctrl Case $Button1 Select Case WinExists ("web1") Msgbox(60,"Information","web1 is already open.") Case not WinExists ("web1") and WinExists ("web2") _IECreate("http://www.",1,1,1,1) ;open WinSetState("web1", "", @SW_MAXIMIZE) Send($name) Send("{TAB}") Send($pass) Send("{TAB}") Send("{ENTER}"); case not WinExists ("web1") and WinExists ("web2") _IECreate("http://www.",1,1,1,1) ;open WinSetState("web1", "", @SW_MAXIMIZE) EndSelect Case $Button2 Select Case WinExists ("web2") Msgbox(60,"Information","web2.") Case not WinExists ("web1") and winexists WinExists ("web2") _IECreate("http://www.",1,1,1,1) ;open WinSetState("web1", "", @SW_MAXIMIZE) Send($name) Send("{TAB}") Send($pass) Send("{TAB}") Send("{ENTER}"); Case not WinExists ("web2") and WinExists ("web1") _IECreate("http://www.",1,1,1,1) ;open WinSetState("web2", "", @SW_MAXIMIZE) Send($pass) Send("{TAB}") Send("{ENTER}"); EndSelect EndSwitch Until $msg = $GUI_EVENT_CLOSE Exit ; Finished! Link to comment Share on other sites More sharing options...
wakillon Posted April 12, 2011 Share Posted April 12, 2011 Please use AutoIt Tags when you post code ! You forgot $msg and some parenthesis, so try this :expandcollapse popup#RequireAdmin #include <GUIConstants.au3> #include <IE.au3> #include <EditConstants.au3> Global $GUIWidth Global $GUIHeight HotKeySet("{ESC}", "Terminate") $GUIWidth = 200 $GUIHeight = 200 ;Create main/parent window $ParentWin = GUICreate("Login", $GUIWidth, $GUIHeight) ;Save the position of the parent window $filemenu = GuiCtrlCreateMenu ("File") $fileitem = GuiCtrlCreateMenuitem ("Website",$filemenu) $separator1 = GuiCtrlCreateMenuitem ("",$filemenu) $exititem = GuiCtrlCreateMenuitem ("Exit",$filemenu) $helpmenu = GuiCtrlCreateMenu ("About") $aboutitem = GuiCtrlCreateMenuitem ("Author",$helpmenu) $Button1 = GUICtrlCreateButton("Login to web1", 25, 100, 150) GUICtrlSetState(-1, $GUI_FOCUS) ; the focus is on this button GUICtrlSetColor(-1,0x00008b) ; Color font GuiCtrlSetCursor(-1,0); Make a cursor $Button2 = GUICtrlCreateButton("Login to web2", 25, 140, 150) GUICtrlSetState(-1, $GUI_FOCUS) ; the focus is on this button GUICtrlSetColor(-1,0x00008b) ; Color font GuiCtrlSetCursor(-1,0); Make a cursor GuiCtrlCreateLabel("ID:", 25, 15, 200); Creates Label GUICtrlSetColor(-1,0x00008b) ; Color font GuiCtrlCreateLabel("Password:", 25, 55, 200); Creates Label GUICtrlSetColor(-1,0x00008b) ; Color font $user = GuiCtrlCreateInput("", 25, 30, 145, 20) $pwuser = GuiCtrlCreateInput("", 25, 70, 145, 20, $ES_PASSWORD) $name = GUICtrlRead($user) $pass = GUICtrlRead($pwuser) $Ctrl = GUISetState () ; will display a dialog box Do $msg = GUIGetMsg() Switch $msg Case $fileitem $file = _IECreate("http://www.",1,1,1,1) ;open Website Case $aboutitem Msgbox(64,"About","This application" & @CRLF & "was created by me" & @CRLF & "It temporarily stores" & @CRLF & "your ID and your password" & @CRLF & "to Login to .. or .."& @CRLF & "It discards all information on Exit.") Case $exititem ExitLoop Case $Button1 Select Case WinExists ("web1") Msgbox(60,"Information","web1 is already open.") Case not ( WinExists ("web1") and WinExists ("web2") ) _IECreate("http://www.",1,1,1,1) ;open WinSetState("web1", "", @SW_MAXIMIZE) Send($name) Send("{TAB}") Send($pass) Send("{TAB}") Send("{ENTER}"); Case not WinExists ("web1") and WinExists ("web2") _IECreate("http://www.",1,1,1,1) ;open WinSetState("web1", "", @SW_MAXIMIZE) EndSelect Case $Button2 Select Case WinExists ("web2") Msgbox(60,"Information","web2.") Case not ( WinExists ("web1") and WinExists ("web2") ) _IECreate("http://www.",1,1,1,1) ;open WinSetState("web1", "", @SW_MAXIMIZE) Send($name) Send("{TAB}") Send($pass) Send("{TAB}") Send("{ENTER}"); Case not WinExists ("web2") and WinExists ("web1") _IECreate("http://www.",1,1,1,1) ;open WinSetState("web2", "", @SW_MAXIMIZE) Send($pass) Send("{TAB}") Send("{ENTER}"); EndSelect EndSwitch Until $msg = $GUI_EVENT_CLOSE Exit Func Terminate() Exit 0 EndFunc AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
baldbox Posted April 12, 2011 Author Share Posted April 12, 2011 Thanks very much for your help. It looks like it will work. I'll try it. Thanks again Link to comment Share on other sites More sharing options...
baldbox Posted April 13, 2011 Author Share Posted April 13, 2011 It looks like that if (win exists web1) no message box pops up and I found that I have to setup local variables inside every case that needs to send the user name and password to the webpage. Local $name=GUICttlRead($user) Local $pass=GUICttlRead($pwuser) The case below actually sends the user name and not the password. Case not WinExists ("web2") and WinExists ("web1") _IECreate("http://www.",1,1,1,1) ;open WinSetState("web2", "", @SW_MAXIMIZE) Send($pass) Send("{TAB}") Send("{ENTER}"); This is fun but I'm still having a headache with it, particularly when I knew nothing before doing this. Link to comment Share on other sites More sharing options...
baldbox Posted April 13, 2011 Author Share Posted April 13, 2011 Thanks for your help. I made it work. It is a nice small interface for what I need. Thanks again. Link to comment Share on other sites More sharing options...
wakillon Posted April 13, 2011 Share Posted April 13, 2011 Thanks for your help.I made it work.It is a nice small interface for what I need.Thanks again.Glad to help you !Use forums search for find IE login examples. AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now