failedtocompile Posted July 9, 2009 Share Posted July 9, 2009 (edited) Hello Crew Could someone point me in the right direction of what the terminology is for detecting if cancel button or okay button is pressed and depending on which is pressed perform a function or do nothing? I have looked at @error = , msgbox() and various forum posts but nothing i could find explains how to do it when you have multiple If statements under one button. I also saw some mention read guibutton? My code I'm trying to get to work: Case $Btn_bkup If ProcessExists($ProcessName1) Then ; Checking for running process MsgBox(0, "", "" &" Is Running please close it down before using this utility.") ElseIf ProcessExists($ProcessName2) Then ; Checking for running process MsgBox(0, "", "" &" Is Running please close it down before using this utility.") ElseIf ProcessExists($ProcessName3) Then ; Checking for running process MsgBox(0, "", "" &" Is Running please close it down before using this utility.") ElseIf FileExists($File1) Then MsgBox(0x1, "Backup Exists", "An existing backup has been detected, Press cancel to abort or okay to override",13) ElseIf @error = 2 Then ; cancel pressed ElseIf @error = 1 Then ; Okay pressed RunWait('"' & $Proflwiz & '" /q /f /s "' & $file1 &'"') EndIf Thanks very much in advance Edited July 9, 2009 by failedtocompile Link to comment Share on other sites More sharing options...
darkmaster071 Posted July 9, 2009 Share Posted July 9, 2009 (edited) Everything is explained in the helpfile. For Ok it returns 1, for Cancel 2. $var=MsgBox(0x1, "Backup Exists", "An existing backup has been detected, Press cancel to abort or okay to override",13) If $var=1 Then MsgBox(0, "", "Ok has been pressed") ElseIf $var=2 Then MsgBox(0, "", "Cancel has been pressed") EndIf edit: it doesnt set an error like you are doing. The function itself returns specific number for button pressed. Edited July 9, 2009 by darkmaster071 Link to comment Share on other sites More sharing options...
failedtocompile Posted July 9, 2009 Author Share Posted July 9, 2009 (edited) Everything is explained in the helpfile. For Ok it returns 1, for Cancel 2. $var=MsgBox(0x1, "Backup Exists", "An existing backup has been detected, Press cancel to abort or okay to override",13) If $var=1 Then MsgBox(0, "", "Ok has been pressed") ElseIf $var=2 Then MsgBox(0, "", "Cancel has been pressed") EndIf edit: it doesnt set an error like you are doing. The function itself returns specific number for button pressed. Thanks darkmaster071 But it does not work with my script I have tried adding Endif after processexists section and adding EndIf, If cancel is pressed then i need it to sit there and do nothing if okay is pressed then i need it to perform RunWait('"' & $Proflwiz & '" /q /f /s "' & $file1 &'"') Is the problem due to me bunching up so much IF and ElseIF into one case? $Filemsgbox = MsgBox(0x1, "Backup Exists", "An existing backup has been detected, Press cancel to abort or okay to override",13) While 1 Sleep(30) Switch GUIGetMsg() Case $Btn_bkup If ProcessExists($ProcessName1) Then ; Checking for running process MsgBox(0, "", "" &" Is Running please close it down before using this utility.") ElseIf ProcessExists($ProcessName2) Then ; Checking for running process MsgBox(0, "", "" &" Is Running please close it down before using this utility.") ElseIf ProcessExists($ProcessName3) Then ; Checking for running process MsgBox(0, "", "" &" Is Running please close it down before using this utility.") EndIf ; Have tried with and without If FileExists($File1) Then $Filemsgbox If $Filemsgbox =1 Then ; Okay is pressed RunWait('"' & $Proflwiz & '" /q /f /s "' & $file1 &'"') ElseIf $Filemsgbox =2 Then ; cancel is pressed EndIf Cheers Edited July 9, 2009 by failedtocompile Link to comment Share on other sites More sharing options...
qazwsx Posted July 9, 2009 Share Posted July 9, 2009 Try indenting properly; it should make the code much clearer. Link to comment Share on other sites More sharing options...
failedtocompile Posted July 9, 2009 Author Share Posted July 9, 2009 (edited) Try indenting properly; it should make the code much clearer. When i past it in it ends up a bit off skew. The code below does not generate errors but when i click on the $btn_bkup it reports there file exists which is great, but when i click on okay to override it does nothing. While 1 Sleep(30) Switch GUIGetMsg() Case $Btn_bkup If ProcessExists($ProcessName1) Then ; Checking for running process MsgBox(0, "", "" &" Is Running please close it down before using this utility.") ElseIf ProcessExists($ProcessName2) Then ; Checking for running process MsgBox(0, "", "" &" Is Running please close it down before using this utility.") ElseIf ProcessExists($ProcessName3) Then ; Checking for running process MsgBox(0, "", "" &" Is Running please close it down before using this utility.") EndIf If FileExists("c:\test123.log") Then $Filemsgbox =MsgBox(0x1, "Backup Exists", "An existing backup has been detected, Press cancel to abort or okay to override",13) ElseIf $Filemsgbox =1 Then RunWait('"' & $Proflwiz & '" /q /f /s "' & $file1 &'"') ElseIf $Filemsgbox =2 Then EndIf Code Below without the FileExists: While 1 Sleep(30) Switch GUIGetMsg() Case $Btn_bkup If ProcessExists($ProcessName1) Then ; Checking for running process MsgBox(0, "", "" &" Is Running please close it down before using this utility.") ElseIf ProcessExists($ProcessName2) Then ; Checking for running process MsgBox(0, "", "" &" Is Running please close it down before using this utility.") ElseIf ProcessExists($ProcessName3) Then ; Checking for running process MsgBox(0, "", "" &" Is Running please close it down before using this utility.") Else RunWait('"' & $Proflwiz & '" /q /f /s "' & $file1 &'"') EndIf Edited July 9, 2009 by failedtocompile Link to comment Share on other sites More sharing options...
methodclass Posted July 9, 2009 Share Posted July 9, 2009 (edited) While 1 Sleep(30) Switch GUIGetMsg() Case $Btn_bkup If ProcessExists($ProcessName1) Then ; Checking for running process MsgBox(0, "", "" &" Is Running please close it down before using this utility.") ElseIf ProcessExists($ProcessName2) Then ; Checking for running process MsgBox(0, "", "" &" Is Running please close it down before using this utility.") ElseIf ProcessExists($ProcessName3) Then ; Checking for running process MsgBox(0, "", "" &" Is Running please close it down before using this utility.") EndIf If FileExists("c:\test123.log") Then $Filemsgbox =MsgBox(0x1, "Backup Exists", "An existing backup has been detected, Press cancel to abort or okay to override",13) ElseIf $Filemsgbox =1 Then RunWait('"' & $Proflwiz & '" /q /f /s "' & $file1 &'"') ElseIf $Filemsgbox =2 Then EndIf The problem you are having is due to the fact you have your if and endif nested incorrectly The way you've written it means that if the file exists, it will never get to 'ElseIf $Filemsgbox =1 Then' Try writing it as If FileExists("c:\test123.log") Then $Filemsgbox =MsgBox(0x1, "Backup Exists", "An existing backup has been detected, Press cancel to abort or okay to override",13) If $Filemsgbox =1 Then RunWait('"' & $Proflwiz & '" /q /f /s "' & $file1 &'"') Else RunWait('"' & $Proflwiz & '" /q /f /s "' & $file1 &'"') EndIf There is no need to define $Filemsgbox=2 if you dont intend on it doing anything. Edited July 9, 2009 by methodclass Link to comment Share on other sites More sharing options...
failedtocompile Posted July 9, 2009 Author Share Posted July 9, 2009 (edited) The problem you are having is due to the fact you have your if and endif nested incorrectly The way you've written it means that if the file exists, it will never get to 'ElseIf $Filemsgbox =1 Then' Try writing it as If FileExists("c:\test123.log") Then $Filemsgbox =MsgBox(0x1, "Backup Exists", "An existing backup has been detected, Press cancel to abort or okay to override",13) If $Filemsgbox =1 Then RunWait('"' & $Proflwiz & '" /q /f /s "' & $file1 &'"') Else RunWait('"' & $Proflwiz & '" /q /f /s "' & $file1 &'"') EndIf There is no need to define $Filemsgbox=2 if you dont intend on it doing anything. Awesome thanks very much methodclass. I am all ways impressed with the Great minds of Autoit users who provide help to newbies like myself Edited July 9, 2009 by failedtocompile 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