'Switch' or 'Case' would clean up some real ugly If loops

Ideas for new features & functions

Moderators: Dorian (MJT support), JRL

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

'Switch' or 'Case' would clean up some real ugly If loops

Post by Jerry Thomas » Fri Oct 08, 2010 2:46 pm

I am sure there are lots of these in use:

If>a
Else
If>b
Else
If>c
etc.

Any chance of adding a Switch (or Case) command?

Switch>some_str
SwitchIf>a
(if some_str = a, do this, then skip to EndSwitch)
SwitchIf>b
(if some_str = b, do this, then skip to EndSwitch)
SwitchIf>c
(if some_str = c, do this, then skip to EndSwitch)
EndSwitch
Thanks,
Jerry

[email protected]

User avatar
Grovkillen
Automation Wizard
Posts: 1009
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Post by Grovkillen » Tue Sep 18, 2012 9:36 pm

+1 on that.
Let>ME=%Script%

Running: 15.0.24
version history

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1348
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Post by Dorian (MJT support) » Mon Oct 08, 2012 7:33 am

I'm sure this is something Grovkillen and Jerry already know about, but just in case anyone else is searching the forums for an easy way to make a string entirely upper or lower case, this is how I do it :

Code: Select all

VBSTART
VBEND

let>sampletext=AbcdefGhIJKLmnOPQ

// change all to lower case
VBEval>LCase("%sampletext%"),sampletext
messagemodal>%sampletext%

// change all to upper case
VBEval>UCase("%sampletext%"),sampletext
messagemodal>%sampletext%


Yes, we have a Custom Scripting Service. Message me or go here

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Mon Oct 08, 2012 2:17 pm

There is also this

Code: Select all

let>sampletext=AbcdefGhIJKLmnOPQ

// change all to lower case
UpperCase>sampletext,sampletext
MDL>sampletext

// change all to upper case
LowerCase>sampletext,sampletext
MDL>sampletext

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

Post by Jerry Thomas » Mon Oct 08, 2012 2:49 pm

We are mixing Cases here (bad pun intended...)

Parsnipnose3000 and Rain are refering to UPPERCASE and lowercase.

The original bug/request was dealing with the Switch statement that is sometimes called a Case statement

Code: Select all

evaluate (something)
If a
  do this
If b 
  do this
...
else
  do this
Thanks,
Jerry

[email protected]

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Mon Oct 08, 2012 4:22 pm

Why not do this?

Code: Select all

Label>Start

Let>some_str=a

IF>some_str=a,DoThis,EndSwitch

Label>EndSwitch
  MDL>some_str = False
  //Do Something
Goto>Start

Label>DoThis
  MDL>some_str = True
  //Do Something
Goto>Start
OR

Code: Select all

Let>some_str=a

IF>some_str=a,DoThis,EndSwitch

SRT>EndSwitch
  MDL>some_str = False
END>EndSwitch

SRT>DoThis
  MDL>some_str = True
END>DoThis

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

Post by Jerry Thomas » Mon Oct 08, 2012 5:18 pm

Yes, that would work.

But it would be cleaner if we had a real Switch or Case statement!

Besdies, if we don't keep asking for new stuff, what is Marcus going to do in all his free time?
Thanks,
Jerry

[email protected]

User avatar
JRL
Automation Wizard
Posts: 3497
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Mon Oct 08, 2012 6:25 pm

I think this is what I was asking for in THIS enhancement suggestion. Because of the way Macro Scheduler works I don't see any other way to do it. Create an OnEvent function that jumps to a subroutine the moment a variable acquires a particular value. I think that would accomplish this request. Don't know what kind of load multiple OnEvents constantly checking variable values would place on the system.

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

Post by Me_again » Wed Oct 10, 2012 4:58 pm

Jerry Thomas wrote:But it would be cleaner if we had a real Switch or Case statement!
I agree, it would be very nice. This topic does make me wonder (again) why the If>expression,true_label_name,false_label_name form is deprecated :?

VBScript has Select Case, maybe that has possibilities?

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