Sign in to follow this  
Followers 0
NvdM

Conditional statements using AND & OR

10 posts in this topic

Hi,

I have been looking at the posts in the forums, but unfortunately I can not find a solution (nor even a hint) to my problem.

I hope you can help me out.

Here's the situation:

There are 2 variables. The conditional statement I am trying to create, should check the following:

Both variables forfill the condition set.

Both variables do not forfill the condition.

Only one variable forfills the condition.

The code (not working):

;###BoC###
dim $a = "2"
dim $b = "2"

if $a And $b = "2" Or "3" Then
    MsgBox(0,"Both","Both are valid")
ElseIf $a And $b <> "2" Or "3" Then
    MsgBox(0,"Both not","Both are not valid")
ElseIf $a Or $b <> "2" Or "3" Then
    MsgBox(0,"One of them","One of these is not valid")
Else
    ;;; 
EndIf

;###EoC###

For my example this wouldn't be too much to ask for, but in my actual code the statements are a bit more complex.

Therefore I'd like to keep the code as short as possible. Unlike this post ;-)

Thanks in advance for looking at this!!!

Cheers,

NvdM

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

If $b = "2" Or $b = "3" Then

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

If $b = "2" Or $b = "3" Then

Hi SmOke_N,

Thanks for replying.

Do you mean that in the first line I should write something like:

if $a ="2" or $a="3" or $b = "2" Or $b="3" Then
oÝ÷ Øì¢Ø^¦ºé¬,ºè®Ø^²Ö­zg§·^­ê'*'zíëp¢+/jX:·hʦy©í«H².×+^Â+a¶¯jXjبôߦ¢YhÁç[É«.nËZµé×è¯Múm*&zØb  b殶­s`¦bb33c¶ÒgV÷C³"gV÷C²÷"b33c¶ÒgV÷C³2gV÷C²FVà¢bb33c¶"ÒgV÷C³"gV÷C²÷"b33c¶"ÒgV÷C³2gV÷C²FVà¦WF2ââà

Cheers,

Nico.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Try:

if ($a ="2" or $a="3") And ($b = "2" Or $b="3") Then

Hi Jos,

Thanks to you too.

Unfortunately your proposal doesn't do the trick for me.

See the code as changed based upon your hint.

dim $a = "24"
dim $b = "3"

if ($a = "2" Or $a = "3") And ($b = "2" or $b = "3") Then
    MsgBox(0,"Both","Both are valid")
elseif ($a <> "2" Or $a <> "3") And ($b <> "2" or $b <> "3") Then
    MsgBox(0,"Both not","Both are not valid")
elseif ($a <> "2" Or $a <> "3") And ($b = "2" or $b = "3") Then
    MsgBox(0,"One of them","One of these is not valid: a")
Elseif ($a = "2" Or $a = "3") And ($b <> "2" or $b <> "3") Then
    MsgBox(0,"One of them","One of these is not valid: b")
EndIf

Maybe I wasn't clear about this, but the values of the variables are not constant. But only the values 2 and 3 are accepted.

Cheers,

Nico

Edited by NvdM

Share this post


Link to post
Share on other sites

Hi Jos,

Thanks to you too.

Unfortunately your proposal doesn't do the trick for me.

See the code as changed based upon your hint.

Hi Nico,

has everything to do with the logic you use ... NQ tests should be done with And ... like this:

dim $a = "2"
dim $b = "3"

if ($a = "2" Or $a = "3") And ($b = "2" or $b = "3") Then
    MsgBox(0,"Both","Both are valid")
elseif ($a <> "2" And $a <> "3") And ($b <> "2" And $b <> "3") Then
    MsgBox(0,"Both not","Both are not valid")
elseif ($a <> "2" And $a <> "3") And ($b = "2" or $b = "3") Then
    MsgBox(0,"One of them","One of these is not valid: a")
Elseif ($a = "2" Or $a = "3") And ($b <> "2" And $b <> "3") Then
    MsgBox(0,"One of them","One of these is not valid: b")
EndIf

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

This should work

dim $a = "2"
dim $b = "30"

if ($a = "2" Or $a = "3") And ($b = "2" or $b = "3") Then
    MsgBox(0,"Both","Both are valid")
elseif $a <> "2" And $a <> "3" And $b <> "2" And $b <> "3" Then
    MsgBox(0,"Both not","Both are not valid")
elseif $b = "2" Or $b = "3" Then
    MsgBox(0,"One of them","One of these is not valid: a")
Elseif $a = "2" Or $a = "3" Then
    MsgBox(0,"One of them","One of these is not valid: b")
EndIf

Start here if you are new Valuater's AutoIT 1-2-3Looking for an UDF - Look hereDo you need to do it twice - Autoit

Share this post


Link to post
Share on other sites

Or you could do this for the easier view

dim $a = "24"
dim $b = "3"

$atest = ($a = "2" Or $a = "3")
$btest = ($b = "2" or $b = "3")

If $atest And $btest Then
    MsgBox(0,"Both","Both are valid")
ElseIf NOT($atest OR $btest) Then
    MsgBox(0,"Both","Both are not valid")
ElseIf NOT($atest) Then
    MsgBox(0,"One of them","One of these is not valid: a")
ElseIf NOT($btest) Then
    MsgBox(0,"One of them","One of these is not valid: b")
EndIf

Start here if you are new Valuater's AutoIT 1-2-3Looking for an UDF - Look hereDo you need to do it twice - Autoit

Share this post


Link to post
Share on other sites

Or you could do this for the easier view

dim $a = "24"
dim $b = "3"

$atest = ($a = "2" Or $a = "3")
$btest = ($b = "2" or $b = "3")

If $atest And $btest Then
    MsgBox(0,"Both","Both are valid")
ElseIf NOT($atest OR $btest) Then
    MsgBox(0,"Both","Both are not valid")
ElseIf NOT($atest) Then
    MsgBox(0,"One of them","One of these is not valid: a")
ElseIf NOT($btest) Then
    MsgBox(0,"One of them","One of these is not valid: b")
EndIf
I like.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

OK Guys,

Got it working! Thanks to you for the solutions.

I needed to change the way of thinkin'.

These multiple conditional statement cases are more difficult than expected.

Again: Thanks to all of you!!!

Cheers,

Nico.

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