Jump to content
PunkoHead

IF condition and condition Then

Recommended Posts

PunkoHead

Hi guys,

I have another question regarding AutoIT. I have the code below but it does not work. Could you please assist?

Func IsTheCheckboxChecked ($CB1, $CB2)
    If GUICtrlRead ($CB1) = 1 Then
        Return 1
    ElseIf GUICtrlRead ($CB2) = 1 Then
        Return 2
    ElseIf (GUICtrlRead ($CB1) = 1) And (GUICtrlRead ($CB2) = 1) Then
        Return 3
    EndIf
EndFunc
$Digital = GUICtrlCreateCheckbox("Digital", 480, 80, 73, 17)
$Physical = GUICtrlCreateCheckbox("Physical", 560, 80, 81, 17)

If IsTheCheckboxChecked($Digital, $Physical) = 1 Then
    $EnabledItemTypesText = "Enabled Item Types: Digital"
ElseIf IsTheCheckboxChecked($Digital, $Physical) = 2 Then
    $EnabledItemTypesText = "Enabled Item Types: Physical"
ElseIf IsTheCheckboxChecked($Digital, $Physical) = 3 Then
    $EnabledItemTypesText = "Enabled Item Types: Digital and Physical"
EndIf

However, when both are ticket the output is only Digital. If I select only the Physical, only Physical is displayed in the output...

Any ideas?

Thanks in advance!

Edited by PunkoHead

Share this post


Link to post
Share on other sites
Xandy

Put this first: ElseIf (GUICtrlRead ($CB1) = 1) And (GUICtrlRead ($CB2) = 1) Then

Put it before the single checks.  You need to evalute the doubles before the singles b/c you stop looking after you find a single.  How can it ever reach the doubles if it exits on a single?

Func IsTheCheckboxChecked ($CB1, $CB2)
    If (GUICtrlRead ($CB1) = 1) And (GUICtrlRead ($CB2) = 1) Then
        Return 3
    ElseIf GUICtrlRead ($CB1) = 1 Then
        Return 1
    ElseIf GUICtrlRead ($CB2) = 1 Then
        Return 2
    EndIf
EndFunc

 

Edited by Xandy
  • Like 1

Share this post


Link to post
Share on other sites
PunkoHead

Wow.. This worked, but I have no idea why... Is there any explanation?

Thanks, btw!

Share this post


Link to post
Share on other sites
Xandy

Doing either an Else, ElseIf, or Return on event would stop the condition block at that event.

Future more complicated events would never be reached if a event fragment was met first.

Edited by Xandy
  • Like 1

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

×