Sign in to follow this  
Followers 0
jackhammerbob

A Design Choice

8 posts in this topic

I have written the code for an automation. However, I want to give the user a choice in the tasks it performs. I am plan on making an input box asking for a number between 1 and x.

If the user enters 1 for instances, it'll perform task 1.

If the user enters 2, it'll perform task 1 and task 2.

If the user enters 3, it'll perform tasks 1 through 3.

A bunch of If statements would take up more room than I would like it to. Are there any elegant way of doing this? Ideally, the following should occur:

Required start automation segment

Task 1

Task 2 (if necessary)

Task 3 (if necessary)

Task 4 (if necessary)

Task...

...

Require ending automation segment

I thought about using a for loop but if I do, I will not be able to change it on the fly. Any suggestions? The current program does what I have described with a pause and a terminate button, no GUI. Any help would be much appreciated.

Share this post


Link to post
Share on other sites



A bunch of If statements would take up more room than I would like it to.  Are there any elegant way of doing this?  Ideally, the following should occur:

How about this?

while 1 

  $action = InputBox("Choose", "... your action: ")

  Select
    Case $action = "1"
        MsgBox(0, "", "Action #1")
    Case $action = "2"
        MsgBox(0, "", "Action #2")
    Case $action = "3"
        MsgBox(0, "", "Action #3")
    Case $action = "quit"
        exitloop
    Case Else
        MsgBox(0, "", "Wrong Action")
  EndSelect
wend

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

Something along those lines, but it needs to be task 1 and 2 for the #2 for exmaple. After looking at what you wrote, it gave me another idea. Thanks for input.

Share this post


Link to post
Share on other sites

Since I'm pretty sure select case "falls through" you could maybe do this?

while 1 

  $action = InputBox("Choose", "... your action: ")

  Select
    Case $action <= "3"
        MsgBox(0, "", "Action #1")
    Case $action <= "2"
        MsgBox(0, "", "Action #2")
    Case $action <= "1"
        MsgBox(0, "", "Action #3")
    Case $action = "quit"
        exitloop
    Case Else
        MsgBox(0, "", "Wrong Action")
  EndSelect
wend

I'm not entirely sure because I am braindead right now, but I think that would work?

Share this post


Link to post
Share on other sites

Since I'm pretty sure select case "falls through" you could maybe do this?

actually, no. From the help file: If more than one of the Case statements are true, only the first one is executed.

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Something along those lines, but it needs to be task 1 and 2 for the #2 for exmaple.  After looking at what you wrote, it gave me another idea.  Thanks for input.

<{POST_SNAPBACK}>

Ah. O.K. So something like this...

while 1
  $action = InputBox("Choose", "... your action: ")

  Select
    Case $action = "1"
         action1()
    Case $action = "2"
         action2()
    Case $action = "3"
         action3()
    Case $action = "4"
         action4()
    Case $action = "quit"
        exitloop
    Case Else
        MsgBox(0, "", "Wrong Action")
  EndSelect
wend

func action1()
  MsgBox(0, "", "Action #1")
endfunc

func action2()
  action1()
  MsgBox(0, "", "Action #2")
endfunc

func action3()
  action2()
  MsgBox(0, "", "Action #3")
endfunc

func action4()
  action3()
  MsgBox(0, "", "Action #4")
endfunc

However, then you can't call each action separately. If you need that as well, then do this.

while 1
  $action = InputBox("Choose", "... your action: ")

  Select
    Case $action = "1"
         action1()
    Case $action = "2"
         action1()
         action2()
    Case $action = "3"
         action1()
         action2()
         action3()
    Case $action = "4"
         action1()
         action2()
         action3()
         action4()
    Case $action = "quit"
        exitloop
    Case Else
        MsgBox(0, "", "Wrong Action")
  EndSelect
wend

func action1()
  MsgBox(0, "", "Action #1")
endfunc

func action2()
  MsgBox(0, "", "Action #2")
endfunc

func action3()
  MsgBox(0, "", "Action #3")
endfunc

func action4()
  MsgBox(0, "", "Action #4")
endfunc

EDIT: BUT, at this stage, some if statement are smarter :)

while 1
  $action = InputBox("Choose", "... your action: ")

  if $action = "quit" then exitloop
  if $action >= 1 then action1()
  if $action >= 2 then action2()
  if $action >= 3 then action3()
  if $action >= 4 then action4()

wend

func action1()
  MsgBox(0, "", "Action #1")
endfunc

func action2()
  MsgBox(0, "", "Action #2")
endfunc

func action3()
  MsgBox(0, "", "Action #3")
endfunc

func action4()
  MsgBox(0, "", "Action #4")
endfunc

Cheers

Kurt

Edited by /dev/null

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

actually, no. From the help file: If more than one of the Case statements are true, only the first one is executed.

Cheers

Kurt

<{POST_SNAPBACK}>

Darn. I didn't actually look in the doc, but just assumed it was the same as java. I guess that's why they say assumeing makes as ASS out of U and ME. :">

Share this post


Link to post
Share on other sites

How about this? --

action1()
if ($action > 1) then action2()
if ($action > 2) then action3()
; etc.

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