PunkoHead

IF condition and condition Then

7 posts in this topic

#1 ·  Posted (edited)

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



#2 ·  Posted

What's up with that '5' before the 'Then' in the last ElseIf?

 

5.PNG


I am not a lawyer.  (-_-) Xandy About  (^o^) Discord - Xandy Programmer

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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
1 person likes this

I am not a lawyer.  (-_-) Xandy About  (^o^) Discord - Xandy Programmer

Share this post


Link to post
Share on other sites

#4 ·  Posted

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

#5 ·  Posted (edited)

Refresh webpage to see my edited post (ABOVE for explanation)

Edited by Xandy

I am not a lawyer.  (-_-) Xandy About  (^o^) Discord - Xandy Programmer

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Your Elses would exit the condition block, but you Return as well :)

Edited by Xandy

I am not a lawyer.  (-_-) Xandy About  (^o^) Discord - Xandy Programmer

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

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
1 person likes this

I am not a lawyer.  (-_-) Xandy About  (^o^) Discord - Xandy Programmer

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