Jump to content

help with okay and cancel function of msgbox button


Recommended Posts

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 by failedtocompile
Link to comment
Share on other sites

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 by darkmaster071
Link to comment
Share on other sites

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 by failedtocompile
Link to comment
Share on other sites

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 by failedtocompile
Link to comment
Share on other sites

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 by methodclass
Link to comment
Share on other sites

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 by failedtocompile
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...