Jump to content

IF statement usage


IvanCodin
 Share

Recommended Posts

Can you use an if statement this way:

If $var1 = "1" or '2" or "3" Then

msgbox(0,"info", "You used one, two or three")

EndIf

Or is a case statement like this required for more than three variables?

Case $var1 = "1"

msgbox(0,"info", "You used one, two or three")

Case $var1 = "2"

msgbox(0,"info", "You used one, two or three")

Case $var= "3"

msgbox(0,"info", "You used one, two or three")

EndSelect

Me

Edited by IvanCodin
Link to comment
Share on other sites

I had better luck with the case...

http://www.autoitscript.com/forum/index.php?app=forums&module=post&section=post&do=reply_post&f=2&t=103096&qpid=730789

Select
    Case $var1 = "1"
        msgbox(0,"info", "You used one")
    Case $var1 = "2"
        msgbox(0,"info", "You used two")
    Case $var1 = "3"
        msgbox(0,"info", "You used three")
EndSelect

But you should be able to do both

If $var1 = "1"
    msgbox(0,"info", "You used one")
  
ElseIf $var1 = "2" Then
    msgbox(0,"info", "You used two")
Else $var1 = "3"
    msgbox(0,"info", "You used three")

EndIf
Link to comment
Share on other sites

Hi,

$var1 = 2

If $var1 = 1 or $var1 = 2 or $var1 = 3 Then msgbox(0,"info", $var1)

;Or
Switch $var1
    Case 1,2,3
        msgbox(0,"info", $var1)
EndSwitch

;Or
Switch $var1
    Case 1 To 3
        msgbox(0,"info", $var1)
EndSwitch

;Or
Switch $var1
    Case 1
        msgbox(0,"info", $var1)
    Case 2
        msgbox(0,"info", $var1)
    Case 3
        msgbox(0,"info", $var1)
EndSwitch

;Or
Select
    Case $var1 = 1 Or $var1 = 2 Or $var1 = 3
        msgbox(0,"info", $var1)
EndSelect

;Or
Select
    Case $var1 > 0 And $var1 < 4
        msgbox(0,"info", $var1)
EndSelect

;Or
Select
    Case $var1 = 1
        msgbox(0,"info", $var1)
    Case $var1 = 2
        msgbox(0,"info", $var1)
    Case $var1 = 3
        msgbox(0,"info", $var1)
EndSelect


; All do the same thing
; there's quite a lot of ways more to do the same thing
; Just depends on your needs and preference.

Cheers

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...