goss34 Posted July 23, 2010 Posted July 23, 2010 Hi Guys, This might be a bit of a basic question for you experts but here we go anyway. After looking all over google i havent come up with an answer yet. I am trying to get a response from a MsgBox to perform the next task in an IF statement so i have this as my MsgBox code: MsgBox(3, "Application Installed", $Found) So this gives me some text and i am asked to press Yes / No or Cancel - at the moment whichever i press makes zero difference it just carries on processing whatever is next. Below is a what i am after but i havent figured out how to intercept the button response: $HRW = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{5525400A-82E2-48B6-AC66-689D7CF7DF39}", "UninstallString") If $HRW = "MsiExec.exe /X{5525400A-82E2-48B6-AC66-689D7CF7DF39}" Then $installed = MsgBox(3, "Application Installed", $Found) If $installed = "Yes" Then Run("C:\Windows\System32\Notepad.exe") EndIf Else MsgBox(0, "Application Not Installed", $NotFound) EndIf Im not sure i can use multiple IF statements inside another statement? If anyone can point me in the right direction that would be appreciated (It may be i have to use something other than a MsgBox but so far i havent come up with anything). Thanks Dan
water Posted July 23, 2010 Posted July 23, 2010 Assign the return value of MsgBox to a variable and then do your processing based on the buttons clicked. $iResult = MsgBox(3, "Application Installed", $Found) If $iResult = 1 ... ; Yes Button pressed If $iResult = 2 ... ; No Button pressed If $iResult = 3 ... ; Cancel Button pressed MsgBox returns the ID of the pressed button. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Moderators Melba23 Posted July 23, 2010 Moderators Posted July 23, 2010 (edited) goss34,No need for Google - if you look at the Help file page for MsgBox, you will see that it "Returns the ID of the button pressed". Just below that is the list of return values:Button Pressed Return Value OK 1 CANCEL 2 ABORT 3 RETRY 4 IGNORE 5 YES 6 NO 7 TRY AGAIN 10 CONTINUE 11So you need to replaceIf $installed = "Yes" ThenwithIf $installed = 6 ThenSimple! And you can nest as many If statements as you want - but be careful to close them all or you might not get the result you want. M23Edit:water,You might like to check on those return values! Edited July 23, 2010 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
goss34 Posted July 26, 2010 Author Posted July 26, 2010 Hi Again, Thanks for the responses Melba that worked wonderful i now have it almost perfected :-) One final question is that i was intending to use the "goto" command but it has been removed. Im trying to check for a folder and if it exists i want to skip the next 2 lines which are a create and copy (these steps wouldnt be needed if the folder is already there). DirCreate("C:\SoftwareInstallation\Application\Office") DirCopy ("\\FileServer\Software\Licensed\Office", "C:\SoftwareInstallation\Application\Office" ,1) RunAsWait - This line installs the application I would like the statement above DirCreate to be something like: If FileExists ("C:\SoftwareInstallation\Application\Office") Goto, RunInstall DirCreate DirCopy :RunInstall EndIf RunAsWait Hopefully you can see what im trying to achieve and point me in the right direction (I dont think the "while" command does what i need from what i have understood so far). Thanks
water Posted July 26, 2010 Posted July 26, 2010 (edited) water,You might like to check on those return values! As always you are right Edited July 26, 2010 by water My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Moderators Melba23 Posted July 26, 2010 Moderators Posted July 26, 2010 goss34,GOTO !?!?!?! Go and wash your mouth out at once! You can do what you want very easily the "structured" way: If Not FileExists ("C:\SoftwareInstallation\Application\Office") Then DirCreate DirCopy EndIf RunAsWaitM23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
goss34 Posted July 26, 2010 Author Posted July 26, 2010 Thank you very much! I have never used the If Not!! before, "user error"! Thanks again... easy when you know how ;-) Cheers Dan
Moderators Melba23 Posted July 26, 2010 Moderators Posted July 26, 2010 goss34,Be very careful using Not in AutoIt - unlike most other languages, Not is the highest priority operator here. This means that you can very easily not Not what you think you are Noting - if you see what I mean. Other than very simple cases (such as the above) I ALWAYS I always put the expression I want to Not into parentheses. Here is why:Let us start with a simple If statement:; Declare a variable $var1 = 1 ; Should be True If $var1 = 1 Then MsgBox(0, "Easy", "True") Else MsgBox(0, "Easy", "False") EndIfWell, that worked!Now add a Not into the mix:; Declare a variable $var1 = 1 ; Now use Not - surely this must be True as $var1 = 1 and therefore $var1 <> 3 If Not $var1 = 3 Then MsgBox(0, "Oops", "True") Else MsgBox(0, "Oops", "False") EndIfThat did not work as we expected, did it. The reason why is because Not has the highest priority, so the AutoIt evaluates the expression as{ Not $var1 } = { 3 }The Not only affects $var1 and not the whole expression.Let us try again, but with parentheses:; Declare a variable $var1 = 1 ; Now use Not with parentheses - will this be True? If Not ($var1 = 3) Then MsgBox(0, "Aaah", "True") Else MsgBox(0, "Aaah", "False") EndIfAnd we get what logic tells us we should! All clear? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
ShawnW Posted July 26, 2010 Posted July 26, 2010 Be very careful using Not in AutoIt - unlike most other languages, Not is the highest priority operator here.In what languages is this not the case? I'm pretty sure Not is always higher than any logical comparison. It is a unary operation. Those come right after grouping operations such as (). After that come the multiplication, division, modulo, then the add, subtract. Then you get the bitwise ops, and FINALLY the comparison.As a side note, autoit does do 1 thing I noticed that does not follow normal order of operations. Logical AND is supposed to come before Logical OR, autoit treats them as equal and processes whatever it gets to 1st.
Moderators Melba23 Posted July 26, 2010 Moderators Posted July 26, 2010 ShawnW,In what languages is this not the case?No idea! I was quoting a long-lost thread (or at least I cannot find it ) which discussed Not and someone much more experienced than I was at the time came out with that remark. I am a trusting soul, so I took it at face value. Anyway, the basic advice is good - ALWAYS use parentheses with Not!M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
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