Sign in to follow this  
Followers 0

Multiple conditions of IF?

7 posts in this topic

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



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

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

oapjr likes this

Share this post


Link to post
Share on other sites

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

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

Share this post


Link to post
Share on other sites

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

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

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