Case Statement or Equivalent?

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
fightcancer
Macro Veteran
Posts: 260
Joined: Fri Apr 15, 2005 8:32 am

Case Statement or Equivalent?

Post by fightcancer » Sun Feb 18, 2007 4:50 am

Does MS have a Case function similar to the one in VB? If not, I guess I can use nested IFs. Thanks!

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

Post by JRL » Sun Feb 18, 2007 6:50 am

Macro Scheduler has only the If> function. However, Macro Scheduler can run Visual Basic Script, perhaps there is a way to do this in VBS. This Microsoft web page seems to be describing a VBS "Case" statement. I don't know Visual Basic so I'm not going to be much help, but if you can make this work and post your results, I'm sure others will be appreciative. :)

I used to be good with AutoLisp in AutoCad. They had the Cond (condition) function in AutoLisp. If I'm understanding you correctly it worked similarly. Basically a list of conditions and when one turns out to be true its associated function is performed. Something like:

(Cond
(A = 1 (Do this))
(B = 1 (Do something else))
(C = 14 (Do another process))
(etc A(etc process))
)

A function like this would be handy.

fightcancer
Macro Veteran
Posts: 260
Joined: Fri Apr 15, 2005 8:32 am

Post by fightcancer » Mon Feb 19, 2007 2:59 pm

Thanks for the info! I figured out a shortcut which avoids both the CASE statement and the nested IFs. It saves me several dozen lines of code for now. So I'll tackle this issue when I have more time.

Thanks again.

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 Feb 19, 2007 3:57 pm

A true case function would be nice, but since If> just drops to the next line if the condition isn't met it's not a lot of extra code to do the equivalent:

If>a=1,dothis
If>a=2,dothat
If>a=3,dotheother

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon Feb 19, 2007 4:04 pm

Or make subroutines for each "case" and simply jump to the subroutine based on the selector value:

Code: Select all

Let>Number=10
GoSub>Case_%Number%

SRT>Case_5
  MessageModal>5
End>Case_5

SRT>Case_10
  MessageModal>10
End>Case_10

SRT>Case_15
  MessageModal>15
End>Case_15

SRT>Case_20
  MessageModal>20
End>Case_20
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

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