jackhammerbob Posted July 14, 2005 Share Posted July 14, 2005 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. Link to comment Share on other sites More sharing options...
/dev/null Posted July 14, 2005 Share Posted July 14, 2005 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 wendCheersKurt __________________________________________________________(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 * Link to comment Share on other sites More sharing options...
jackhammerbob Posted July 14, 2005 Author Share Posted July 14, 2005 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. Link to comment Share on other sites More sharing options...
Arrrghmatey Posted July 14, 2005 Share Posted July 14, 2005 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? Link to comment Share on other sites More sharing options...
/dev/null Posted July 14, 2005 Share Posted July 14, 2005 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.CheersKurt __________________________________________________________(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 * Link to comment Share on other sites More sharing options...
/dev/null Posted July 14, 2005 Share Posted July 14, 2005 (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...expandcollapse popupwhile 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") endfuncHowever, then you can't call each action separately. If you need that as well, then do this.expandcollapse popupwhile 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") endfuncEDIT: 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") endfuncCheersKurt Edited July 14, 2005 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 * Link to comment Share on other sites More sharing options...
Arrrghmatey Posted July 14, 2005 Share Posted July 14, 2005 actually, no. From the help file: If more than one of the Case statements are true, only the first one is executed.CheersKurt<{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. :"> Link to comment Share on other sites More sharing options...
LxP Posted July 15, 2005 Share Posted July 15, 2005 How about this? -- action1() if ($action > 1) then action2() if ($action > 2) then action3() ; etc. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now