Neoborn Posted March 22, 2005 Posted March 22, 2005 (edited) I am determined to make a program for fun here but it's wanting to fight back. This fighting back is due to my lack of knowledge . I would like to: 1. If window exists 2. Then Activate the window 3. ElseIf window doesn't exist pop up MsgBox and ask if they want to launch proggie. My coding sucks so far but I am receiving much help from many good people here! If WinExists($title) Then WinActivate($title) ElseIf Not MsgBox(4, "Error!", " XRC is not running do you want to launch it?", 10) Else EndIf If someone can give me a clear example of how if then else elseif works that would be awesome. (yes I do honestly rtfm) Is this correct: If A) Then Else C) ------------ or ---------- If A) = false & = false ......sigh I dunno even know how to explain it... anyone have a link or something to very simple programming concepts like if then else? (other than the manual for Auto?) Edited March 22, 2005 by Neoborn ~Projects~1. iPod Ejector 1.0 - Tool Used To Eject iPod in Windows - Uses DevEject.exe :P2. SmartFTP Close Popup Tool - Closes reminders from freeware SmartFTP.~Helpful Links For New Users~1. LXP's Learning AutoIT PDF Guide - <<< Go here for a PDF Guide on learning AutoIT from the ground up!<<<2. AutoIt 1-2-3 <<<Want to learn more about AutoIT quickly? Go Here<<<3. How To Install The Beta And Production Versions Of AutoIT / SciteAutoIT
CyberSlug Posted March 22, 2005 Posted March 22, 2005 If WinExists($title) Then WinActivate($title) Else;otherwise window does not exist, so MsgBox(4, "Error!", " XRC is not running do you want to launch it?", 10) EndIf Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
MHz Posted March 22, 2005 Posted March 22, 2005 If WinExists($title) Then WinActivate($title) Else MsgBox(4, "Error!", " XRC is not running do you want to launch it?", 10) EndIf 1 condition else msgbox. (your request) If WinExists($title1) Then WinActivate($title1) ElseIf WinExists($title2) Then WinActivate($title2) Else MsgBox(4, "Error!", " XRC is not running do you want to launch it?", 10) EndIf 2 conditions else msgbox. (example using ElseIf)
Neoborn Posted March 22, 2005 Author Posted March 22, 2005 Thank you both vm. When does it exit out of this um statement and carry on with my other instructions? ~Projects~1. iPod Ejector 1.0 - Tool Used To Eject iPod in Windows - Uses DevEject.exe :P2. SmartFTP Close Popup Tool - Closes reminders from freeware SmartFTP.~Helpful Links For New Users~1. LXP's Learning AutoIT PDF Guide - <<< Go here for a PDF Guide on learning AutoIT from the ground up!<<<2. AutoIt 1-2-3 <<<Want to learn more about AutoIT quickly? Go Here<<<3. How To Install The Beta And Production Versions Of AutoIT / SciteAutoIT
MHz Posted March 22, 2005 Posted March 22, 2005 Only statement that pauses the script, is the messagebox. Read line by line, like a story.
Neoborn Posted March 22, 2005 Author Posted March 22, 2005 ~Projects~1. iPod Ejector 1.0 - Tool Used To Eject iPod in Windows - Uses DevEject.exe :P2. SmartFTP Close Popup Tool - Closes reminders from freeware SmartFTP.~Helpful Links For New Users~1. LXP's Learning AutoIT PDF Guide - <<< Go here for a PDF Guide on learning AutoIT from the ground up!<<<2. AutoIt 1-2-3 <<<Want to learn more about AutoIT quickly? Go Here<<<3. How To Install The Beta And Production Versions Of AutoIT / SciteAutoIT
Neoborn Posted March 22, 2005 Author Posted March 22, 2005 When executing a block If (second syntax), condition is tested. If condition is True, the statements following Then are executed. If condition is False, each ElseIf (if any) is evaluated in turn. When a True condition is found, the statements following the associated Then are executed. If none of the ElseIf statements are True (or there are no ElseIf clauses), the statements following Else are executed. After executing the statements following Then or Else, execution continues with the statement following End If.Found from here: http://www.csidata.com/custserv/onlinehelp...docs/VBSTOC.htm ~Projects~1. iPod Ejector 1.0 - Tool Used To Eject iPod in Windows - Uses DevEject.exe :P2. SmartFTP Close Popup Tool - Closes reminders from freeware SmartFTP.~Helpful Links For New Users~1. LXP's Learning AutoIT PDF Guide - <<< Go here for a PDF Guide on learning AutoIT from the ground up!<<<2. AutoIt 1-2-3 <<<Want to learn more about AutoIT quickly? Go Here<<<3. How To Install The Beta And Production Versions Of AutoIT / SciteAutoIT
MHz Posted March 22, 2005 Posted March 22, 2005 If...ElseIf...Else...EndIf --------------------------------------------------------------------------------Conditionally run statements.If <expression> Then statements ...[ElseIf expression-n Then [elseif statements ... ]] ...[Else [else statements] ...EndIf Parametersexpression If the expression is true, the first statement block is executed. If not, the first true ElseIf block is executed. Otherwise, the "Else" block is executed.Yeah, just like the Autoit helpfile, when I press F1?Unlike the example on that site, where you can have mulitiple commands on the one line.I think you should consider the Autoit Helpfile, as the first place to look, and the last to make a decision with correct syntax. Basic languages can vary between one and another.
Neoborn Posted March 23, 2005 Author Posted March 23, 2005 Yah I just like that blurb ( and your help more) because it really explains it fully. I found the wording in the help file a little challenging ~Projects~1. iPod Ejector 1.0 - Tool Used To Eject iPod in Windows - Uses DevEject.exe :P2. SmartFTP Close Popup Tool - Closes reminders from freeware SmartFTP.~Helpful Links For New Users~1. LXP's Learning AutoIT PDF Guide - <<< Go here for a PDF Guide on learning AutoIT from the ground up!<<<2. AutoIt 1-2-3 <<<Want to learn more about AutoIT quickly? Go Here<<<3. How To Install The Beta And Production Versions Of AutoIT / SciteAutoIT
Neoborn Posted March 23, 2005 Author Posted March 23, 2005 (edited) I am stuck again :If WinExists($title) Then WinActivate($title) Elseif MsgBox(4, "Error!", " XRC is not running do you want to launch it?", 10) Then GUICtrlRead ( 6 ) GUICtrlSetOnEvent ( 6, "y1" ) EndIf Func y1() RunWait('D:\Program Files\Xrc Connect\Xrc Connect 6a12\DCPlusPlus.exe') EndFuncAs you can see I am confused. What I would like to do is say:if window exists then activate it, if not then popup a message box that asks if I want to launch the program. On clicking the "yes" button the program then launches and if no, msgbox closes and program waits for further user event. I am having a real hard time with this if then else monster . As you can see I don't know how the syntax should be for the yes button or where to put the function etc etc.*Edit* I kinda of figured it out with some examples, Here's what I now have, feel free to mention on a better (basic way for newb) to code this:$title = 'Xreverse connect'; Window Name $answer = MsgBox(4, "Error!", " XRC is not running do you want to launch it?") If WinExists($title) Then;If the window that contains the value of the variable assigned to $title then activate it WinActivate($title) EndIf ;Start scanning window for dead hubs Scan() If $answer = 7 Then; If the user presses no message box exits GUISetOnEvent(7, "X") EndIf If $answer = 6 Then; If user presses yes then program is launched GUISetOnEvent(6, "Runprog()") EndIf ;Run the program Runprog() Func Runprog() RunWait('D:\Program Files\Xrc Connect\Xrc Connect 6a12\DCPlusPlus.exe') EndFunc Edited March 23, 2005 by Neoborn ~Projects~1. iPod Ejector 1.0 - Tool Used To Eject iPod in Windows - Uses DevEject.exe :P2. SmartFTP Close Popup Tool - Closes reminders from freeware SmartFTP.~Helpful Links For New Users~1. LXP's Learning AutoIT PDF Guide - <<< Go here for a PDF Guide on learning AutoIT from the ground up!<<<2. AutoIt 1-2-3 <<<Want to learn more about AutoIT quickly? Go Here<<<3. How To Install The Beta And Production Versions Of AutoIT / SciteAutoIT
phillip123adams Posted March 23, 2005 Posted March 23, 2005 I am stuck again :If WinExists($title) Then WinActivate($title) Elseif MsgBox(4, "Error!", " XRC is not running do you want to launch it?", 10) Then GUICtrlRead ( 6 ) GUICtrlSetOnEvent ( 6, "y1" ) EndIf Func y1() RunWait('D:\Program Files\Xrc Connect\Xrc Connect 6a12\DCPlusPlus.exe') EndFuncAs you can see I am confused. What I would like to do is say:if window exists then activate it, if not then popup a message box that asks if I want to launch the program. On clicking the "yes" button the program then launches and if no, msgbox closes and program waits for further user event. I am having a real hard time with this if then else monster . As you can see I don't know how the syntax should be for the yes button or where to put the function etc etc.<{POST_SNAPBACK}>Post #2 from CyberSlug actually shows you exactly what to do. That said, I will try to explain how the "If" statement functions.Here's an "If" with two "ElseIf" statements and one "Else" statement:If $this = $that Then $a = 1ElseIf $this = $those Then $a = 2ElseIf $this = $them Then $a = 3Else ; Do this as long as none of the comparisons above are true. $a = 4EndifBut, an "IF" does not have to have and "ElseIf" or an "Else". It could be:If $this = $that Then $a = 1Endif; or even simpler, it could be:If $this = $that Then $a = 1In your specific case, it would be like the following as you want something to happen, no matter what, when the first comparison is false. That's what "Else" means. There should be no "ElseIf". If there were one, it would have to actually compare something to something.If $this = $that Then $a = 1Else ; do this as long as $this is not equal to $that $a = 2EndifNotes:1. If there is an "Else" statement, it always comes last.2. There can be one or more "ElseIf" statements and no "Else" statement. Phillip
MHz Posted March 23, 2005 Posted March 23, 2005 @ Neoborn Unless you have created a Gui, leave the GUI* functions out of the script. GUICtrlRead () and GUICtrlSetOnEvent () are not used like that either anyway. I'll take a guess at what you are doing, with this: $title = 'Xreverse connect';;Window Name If WinExists($title) Then;;If the window that contains the value of the variable assigned to $title then activate it WinActivate($title) Scan () ;;Start scanning window for dead hubs Else $answer = MsgBox(4, "Error!", " XRC is not running do you want to launch it?") If $answer = 7 Then ;;If the user presses no message box exits Exit Else Runprog () ;;If user presses yes then program is launched EndIf EndIf Func Runprog () RunWait('D:\Program Files\Xrc Connect\Xrc Connect 6a12\DCPlusPlus.exe') WinWait($title) ;;Wait for window to appear Scan () ;;Start scanning window for dead hubs EndFunc
Neoborn Posted March 24, 2005 Author Posted March 24, 2005 (edited) I have created a gui yah. I am new to this so don't always get the syntax but am learning slowly btw thanks for your help. 1. Why you did you add double semi colons? 2. What is the best way (standard) for layout when coding to make it easy to read? I was doing it like HTML Command ------->Tab once & sub command Closing Command & Command --->Tab once sub command --->sub sub command --->Close of sub sub command ---> Close sub command Close Command Any good feedback? Edited March 24, 2005 by Neoborn ~Projects~1. iPod Ejector 1.0 - Tool Used To Eject iPod in Windows - Uses DevEject.exe :P2. SmartFTP Close Popup Tool - Closes reminders from freeware SmartFTP.~Helpful Links For New Users~1. LXP's Learning AutoIT PDF Guide - <<< Go here for a PDF Guide on learning AutoIT from the ground up!<<<2. AutoIt 1-2-3 <<<Want to learn more about AutoIT quickly? Go Here<<<3. How To Install The Beta And Production Versions Of AutoIT / SciteAutoIT
MHz Posted March 24, 2005 Posted March 24, 2005 I have created a gui yah. I am new to this so don't always get the syntax but am learning slowly btw thanks for your help.1. Why you did you add double semi colons?I just added 2 semi colons, to make the comments, more noticable. No color in code tags, so, can be hard to interpret, which is which.2. What is the best way (standard) for layout when coding to make it easy to read?I was doing it like HTMLCommand ------->Tab once & sub commandClosing Command& Command --->Tab once sub command --->sub sub command --->Close of sub sub command ---> Close sub commandClose CommandI use the Scite4Autoit3 editor, which automatically indents the code nicely. Basically operates the same as you are mentioning, Sub commands, indent out, and the close of a command indents in. So blocks of code, should be recognizable.
Neoborn Posted March 25, 2005 Author Posted March 25, 2005 I use Scite as well does it automatically indent? I haven't noticed that. ~Projects~1. iPod Ejector 1.0 - Tool Used To Eject iPod in Windows - Uses DevEject.exe :P2. SmartFTP Close Popup Tool - Closes reminders from freeware SmartFTP.~Helpful Links For New Users~1. LXP's Learning AutoIT PDF Guide - <<< Go here for a PDF Guide on learning AutoIT from the ground up!<<<2. AutoIt 1-2-3 <<<Want to learn more about AutoIT quickly? Go Here<<<3. How To Install The Beta And Production Versions Of AutoIT / SciteAutoIT
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