Select-case

General Macro Scheduler discussion

Moderators: JRL, Dorian (MJT support)

Post Reply
Dimmak
Junior Coder
Posts: 25
Joined: Tue Jan 24, 2012 4:57 pm

Select-case

Post by Dimmak » Thu Jan 26, 2012 8:56 pm

Select var
case 1 .....
case 3

How do this in macroSheduler??
Multi If??

Jerry Thomas
Macro Veteran
Posts: 267
Joined: Mon Sep 27, 2010 8:57 pm
Location: Seattle, WA

Post by Jerry Thomas » Thu Jan 26, 2012 10:27 pm

This is an often requested feature.
Here is a generic way to do the same thing.

I include the comment at the beginning so other people wont be so quick to rush in and rip it out as BAD CODE.

Code: Select all

{Using a GoTo is bad programming. 
 This is intended to simulate a Case / Switch Statement. 
 This is only situation where GoTo will be used
}

If>Test=1
  //Do stuff
  Goto>DONE
Endif

If>Test=2
  //Do stuff
  Goto>DONE
Endif

If>Test=3
  //Do stuff
  Goto>DONE
Endif
   
//If we reach this, no match
 //Do stuff

Label>DONE
Thanks,
Jerry

[email protected]

Dimmak
Junior Coder
Posts: 25
Joined: Tue Jan 24, 2012 4:57 pm

Post by Dimmak » Fri Jan 27, 2012 8:16 am

Thanks,
Jerry :)

User avatar
PepsiHog
Automation Wizard
Posts: 517
Joined: Wed Apr 08, 2009 4:19 pm
Location: Florida

Hello

Post by PepsiHog » Fri Jan 27, 2012 2:44 pm

@Jerry

I understand using goto is a less desirable function. That is, if you don't need to use it, or can avoid it, then don't.

But curious what your solution might be. Two things.

Would you agree an IF statement is a GOTO? Difficult, at best, to not use an IF statement in a program.

I write srts all the time that have an IF statement. Such as:

.......
if>result=0,Bottom
......
Label>Bottom
End>Srt

This because jumping out of a srt is not allowed and it can cause problems.
So is there a better way?

PepsiHog

BTW - side note : It's not that GOTO is really bad. But it is considered to slow the production of your program down. Increases the time for it to execute. So it's more of a choice of not wanting to increase program time. If possible at all. And even still, were only talking increases in MICRONS.
Windows 7

PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2024) AND enjoy programming. (That's my little piece of heaven!)

The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!

User avatar
PepsiHog
Automation Wizard
Posts: 517
Joined: Wed Apr 08, 2009 4:19 pm
Location: Florida

Hello

Post by PepsiHog » Fri Jan 27, 2012 2:54 pm

I'm curious (again) if there would be any advantage of having a command in MS that would abort a srt.

srt>Name
.....
IF>result=0
Abort>Name
endif
.....
end>Name

One advantage I see, is it would make scripts neater, easier to follow. Another would be less Labels. (But this likely doesn't matter.)
Windows 7

PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2024) AND enjoy programming. (That's my little piece of heaven!)

The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!

Jerry Thomas
Macro Veteran
Posts: 267
Joined: Mon Sep 27, 2010 8:57 pm
Location: Seattle, WA

Post by Jerry Thomas » Fri Jan 27, 2012 4:42 pm

I believe the primary aversion to GoTo, is that you end up with a much less structured code where you go anywhere from anywhere, rather than performance implications.

If there is only one way out of an If Statement then that is easier to read and maintain.

Consider these:

Code: Select all

If>A=B
  GoSub>DoStuff
Endif

If>A=B
  GoTo>DoStuff
Endif
In the 1st instance, you know that you will come back to the Endif statement. In the 2nd example, you have no idea where you will end up.
Thanks,
Jerry

[email protected]

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts