Sign in to follow this  
Followers 0

Multiple conditions of IF?

7 posts in this topic

#1 ·  Posted (edited)

How can I set multiple conditions for IF?

Here's my problem: I need that only if a checkbox and a radio button are selected, a button can close the program.

Here's my incorrect code:

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
    Case $GUI_EVENT_CLOSE
        MsgBox (0, "TEST", "Message Text.")
    
    Case $STUPIDBUTTON
        If $Radio1 = 1 Then
        MsgBox(0, "ERRORE", "abc...")
        ElseIf $Checkbox1 = 1 Then MsgBox (0, "TEST", "TEST COMPLETED.") Then Exit
        
        EndIf
        
EndSwitch
WEnd
Edited by ned98

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

As the helpfile say:

The expression can contain the boolean operators of AND, OR, and NOT as well as the logical operators <, <=, >, >=, =, ==, and <> grouped with parentheses as needed.

If $something1 = 1 and $something2 = 2 then

exit

endif

Or something like that :idea:

Edit: Oh and Welcome to the forum!

Edited by AdmiralAlkex

Share this post


Link to post
Share on other sites

#3 ·  Posted

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
    Case $GUI_EVENT_CLOSE
        MsgBox (0, "TEST", "Message Text.")
    
    Case $STUPIDBUTTON
        If GUICtrlRead($Radio1) = 1 Then
        MsgBox(0, "ERRORE", "abc...")
        If GUICtrlRead($Checkbox1) = 1 Then MsgBox (0, "TEST", "TEST COMPLETED.") Then Exit
        Else
            ContinueLoop
        EndIf
        
EndSwitch
WEnd

1 person likes this

GeorgeQuestion about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else."Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

#4 ·  Posted

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
    Case $GUI_EVENT_CLOSE
        MsgBox (0, "TEST", "Message Text.")
    
    Case $STUPIDBUTTON
        If GUICtrlRead($Radio1) = 1 Then
        MsgBox(0, "ERRORE", "abc...")
        If GUICtrlRead($Checkbox1) = 1 Then MsgBox (0, "TEST", "TEST COMPLETED.") Then Exit
        Else
            ContinueLoop
        EndIf
        
EndSwitch
WEnd

thank you very much for your prompt reply!

But there's another little problem: when I select the radio button and the checkbox, then press the STUPIDBUTTON, Two windows pop-up: the first - MsgBox(0, "ERRORE", "abc...")- and the second - MsgBox (0, "TEST", "TEST COMPLETED." -. How can I solve this?

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Is this what you want?

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
    Case $GUI_EVENT_CLOSE
        MsgBox (0, "TEST", "Message Text.")
    
    Case $STUPIDBUTTON
        If GUICtrlRead($Radio1) = 1 AND GUICtrlRead($Checkbox1) = 1 Then
            MsgBox (0, "TEST", "TEST COMPLETED.") Then Exit
        Else
            MsgBox(0, "ERRORE", "abc...")
        EndIf
EndSwitch
WEnd

EDIT: Forgot the code tags

Edited by GEOSoft

GeorgeQuestion about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else."Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

#6 ·  Posted

Is this what you want?

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
    Case $GUI_EVENT_CLOSE
        MsgBox (0, "TEST", "Message Text.")
    
    Case $STUPIDBUTTON
        If GUICtrlRead($Radio1) = 1 AND GUICtrlRead($Checkbox1) = 1 Then
            MsgBox (0, "TEST", "TEST COMPLETED.") Then Exit
        Else
            MsgBox(0, "ERRORE", "abc...")
        EndIf
EndSwitch
WEnd

EDIT: Forgot the code tags

Thank you very much for the help! This code works perfectly.

Share this post


Link to post
Share on other sites

#7 ·  Posted

You're wlecome and you should read up on If/ElseIf/Else/EndIf statements in the help file. If there are more than 2 conditions then you use ElseIf (usually coupled with an Else)

If $Condition_1 Then
    ;; Perform some functions
ElseIf $Condition_2 Then
    ;; Perform a second set of functions
ElseIf $Condition_3
    ;; Perform a third set of functions
Else
    ;; Perform yet another set of functions
EndIf

GeorgeQuestion about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else."Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
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
Sign in to follow this  
Followers 0