Another way to setup IF, ELSE statements

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
clickfast
Pro Scripter
Posts: 58
Joined: Wed May 23, 2007 12:04 am

Another way to setup IF, ELSE statements

Post by clickfast » Sun Jul 01, 2007 1:59 am

I want to do a complex conditional statement something like this example i've typed below. Basically, there is a variable called %variable1% that will be either 1,5 or 20.

Is this the proper way to structure the ElseIf branching?? Is there a better syntax for accomplishing this??

THANKS!

Code: Select all

If>variable1=1
copyfile>c:\text1,d:\text1
ElseIf variable1=5
copyfile>c:\text5,d:\text5
ElseIf variable1=20
copyfile>c:\text20,d:\text20
EndIf
Last edited by clickfast on Sun Jul 01, 2007 10:47 am, edited 1 time in total.

clickfast
Pro Scripter
Posts: 58
Joined: Wed May 23, 2007 12:04 am

Post by clickfast » Sun Jul 01, 2007 2:49 am

FOUND THIS REFERRENCE IN THE FORUM... HELPS ME OUT...

http://www.mjtnet.com/usergroup/viewtopic.php?t=3638

User avatar
pgriffin
Automation Wizard
Posts: 461
Joined: Wed Apr 06, 2005 5:56 pm
Location: US and Europe

Post by pgriffin » Sun Jul 01, 2007 4:49 am

Code: Select all

[code]
If>variable1=1
    copyfile>c:\text1,d:\text1
Else
    if>variable1=5
         copyfile>c:\text5,d:\text5
    Else
         If>variable1=20
             copyfile>c:\text20,d:\text20
         endif
     endif
EndIf
[/code]

clickfast
Pro Scripter
Posts: 58
Joined: Wed May 23, 2007 12:04 am

Post by clickfast » Sun Jul 01, 2007 10:40 am

I tried the IF Else conditional branching and couldn't get it to work. So I found some other examples of using in a Subroutine without the Else and EndIF statements, and decided to try it outside of a sub. So I basically setup lables.

For better or for worse heres what i ended up doing ... probably a little verbose.. BUT IT WORKS!!!! ;-)

assume user provides input, we'll call it %variable%

Code: Select all

//here's the generic version of what I came out with

label>start
if>%variable%=1,first
if>%variable%=2,second
if>%variable%=3,third
goto>exit

     //you could replace copyfile with whatever function you need to execute

     label>first
     copyfile>c:\first.txt,d:\first.txt
     goto>exit
 
     label>second
     copyfile>c:\second.txt,d:\second.txt
     goto>exit

     label>third
     copyfile>c:\third.txt,d:\third.txt
     goto>exit

label>exit

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Sun Jul 01, 2007 2:27 pm

Else is great if there are two outcomes determined by one If> condition but otherwise you can just keep it simple and use separate If>'s

if>%variable%=1
copyfile>c:\first.txt,d:\first.txt
endif
if>%variable%=2
copyfile>c:\second.txt,d:\second.txt
endif
if>%variable%=3
copyfile>c:\three.txt,d:\three.txt
endif

Hopefully macroscheduler will get a "case" function in a future version so we won't need to use stacked If's.

User avatar
jpuziano
Automation Wizard
Posts: 1086
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Sun Jul 01, 2007 8:51 pm

Me_again wrote:Hopefully macroscheduler will get a "case" function in a future version so we won't need to use stacked If's.
I agree, having a CASE command would simplify coding in some cases, a lot less lines would be required for some macros making them easier to understand and maintain.

I remember this being mentioned over the years so I checked the Enhancement Suggestions forum but found it has never actually been requested as an enhancement.

Marcus, is adding a CASE command on the Wish List somewhere? Just wondering...
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Mon Jul 02, 2007 12:16 am

I suspect it may not be possible, since it would be more or less the equivalent of:

If>black=white,red=green

and MS doesn't seem to be able to do things like that.

But since I just had to code a conversion from direction in degrees to 16 alpha compass points (N, NNE, etc.) I could sure use it sometimes :lol:

diamondrail
Newbie
Posts: 17
Joined: Wed Jul 31, 2019 9:38 am

Re: Another way to setup IF, ELSE statements

Post by diamondrail » Mon Sep 02, 2019 8:43 am

clickfast wrote:
Sun Jul 01, 2007 1:59 am
I want to do a complex conditional statement something like this example i've typed below. Basically, there is a variable called %variable1% that will be either 1,5 or 20.

Is this the proper way to structure the ElseIf branching?? Is there a better syntax for accomplishing this??

THANKS!

Code: Select all

If>variable1=1
copyfile>c:\text1,d:\text1
ElseIf variable1=5
copyfile>c:\text5,d:\text5
ElseIf variable1=20
copyfile>c:\text20,d:\text20
EndIf
That worked well - thanks. However, now my script is running a bunch of times within the interval that the current time is 935. I only need it to execute once during that "minute"....

Besides putting a delay ? .... for 60 seconds... right after it runs the script?
Attachments
time checker.jpg
time checker.jpg (57.67 KiB) Viewed 251 times

User avatar
Grovkillen
Automation Wizard
Posts: 360
Joined: Fri Aug 10, 2012 2:38 pm
Location: Hudiksvall, Sweden
Contact:

Re: Another way to setup IF, ELSE statements

Post by Grovkillen » Mon Sep 02, 2019 2:52 pm

Why not use a variable which is set to (as an example) 1 when the script run the first time and when it's NOT 945 it's set to 0. Have the loop only trigger when it's 945 AND the variable is 0.
Let>ME=%Script%

Running: MS14.5.4

Post Reply