Sign in to follow this  
Followers 0
Hellfire

If $var=1 or $var=2 then

8 posts in this topic

How can I create a or in an if then else function.

If $var=1 or $var=2 then

...

else

...

endif

It always goes to the then even when it doesnt equal 1 or 2.

Share this post


Link to post
Share on other sites



How can I create a or in an if then else function.

If $var=1 or $var=2 then

...

else

...

endif

It always goes to the then even when it doesnt equal 1 or 2.

The should be easy.

;$var = 1
$var = 3

If $var=1 or $var=2 then
MsgBox(0, "Hit", "$var = 1 or 2")
else
MsgBox(0, "Hit", "$var <> 1 or 2")
endif

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

maybe this

$var = 5

If $var = 1 Or $var = 2 Then
    MsgBox(0, "IS", " the var is 1 or 2   ")
Else
    MsgBox(0, "NOT", " the var is not 1 or 2   ")
EndIf

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Hihi, I was faster :lmao:


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

How can I create a or in an if then else function.

If $var=1 or $var=2 then

...

else

...

endif

It always goes to the then even when it doesnt equal 1 or 2.

That should work. Maybe you could flesh out your example with some more code?

For $var = 0 To 3
     If $var=1 Or $var=2 Then
          MsgBox(64, "Match", "Match!  $var = " & $var)
     Else
          MsgBox(64, "No Match", "Did not match!  $var = " & $var)
     EndIf
Next

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

That should work. Maybe you could flesh out your example with some more code?

For $var = 0 To 3
     If $var=1 Or $var=2 Then
          MsgBox(64, "Match", "Match!  $var = " & $var)
     Else
          MsgBox(64, "No Match", "Did not match!  $var = " & $var)
     EndIf
Next
For a twist:

For $var = 0 To 3
     If $var<1 Or $var>2 Then
           MsgBox(64, "No Match", "Did not match!  $var = " & $var)
     Else
         MsgBox(64, "Match", "Match!  $var = " & $var)
     EndIf
Next

Share this post


Link to post
Share on other sites

I'm so confused... Why wouldn't "If $var = 1 or $var = 2 Then..." work right?

I've used a ton of statements like that with no problems.

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