Sign in to follow this  
Followers 0
IvanCodin

IF statement usage

5 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Thanks!! It didn't error when I used syntaxcheck but I didn't find anything in thr help file for the if $var1 = '1" or "2" bla bla

Me

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