Switch statements within Switch statements

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Switch statements within Switch statements

charles61
I have an option Menu that show various arrays of buttons depending on which menu item is selected. Is it possible to have switch statements for the buttons within switch statements for each menu item? I checked the Rev-User archives and could not find any examples of such an arrangement.
Reply | Threaded
Open this post in threaded view
|

Re: Switch statements within Switch statements

masmit
You can certainly nest switch statements without problem - you'll end  
up with some very long handlers!

Best,

Mark

On 10 Jul 2008, at 03:15, Charles Szasz wrote:

>
> I have an option Menu that show various arrays of buttons depending  
> on which
> menu item is selected. Is it possible to have switch statements for  
> the
> buttons within switch statements for each menu item? I checked the  
> Rev-User
> archives and could not find any examples of such an arrangement.
> --
> View this message in context: http://www.nabble.com/Switch- 
> statements-within-Switch-statements-tp18374624p18374624.html
> Sent from the Revolution - User mailing list archive at Nabble.com.
>
> _______________________________________________
> use-revolution mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your  
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: Switch statements within Switch statements

Kay C Lan
In reply to this post by charles61
On Thu, Jul 10, 2008 at 10:15 AM, Charles Szasz <[hidden email]> wrote:

>
> I have an option Menu that show various arrays of buttons depending on
> which
> menu item is selected. Is it possible to have switch statements for the
> buttons within switch statements for each menu item?


If I understand your situation it is like this:

If you select the 1st choice in your 'Master' option menu you show 'slave'
option menus 1, 2 and 3.
If you select the 2nd choice in your 'Master' option menu you show 'slave'
option menu a,b, and c.
if you select the 3rd choice in your 'Master' option menu you show 'slave'
option menu  1,b,3,d
...

For the scripts in your 'slave' option menus you want different actions
based on not only what selection is made, but what selection was made with
the 'Master' option menu.

If I've got that correct, and assuming that your 'slave' buttons have many
options so you want to keep the switch statement compact, then the script in
your 'slave' buttons could look something like this:

on menuPick pChosen
  switch pChosen
    case "1 Choice"
       --avoid statements here to keep switch statement compact
      handler1Choice
    break
     case "2 Choice"
       handler2Choice
    break
    ...
    ...
     case "987 Choice"
       handler987Choice
     break
    --always good to include in the development phase to hi-light omissions.
    default
      answer "A case I've not accounted for." titled "Case Omission"
      --check the variable watcher - pChosen
      breakpoint
  end switch
end menuPick

--the following will also be in the button script

on handler1Choice
  switch the label of btn "Master"
    case "Choice 1"
       --statements here
       --use a handler if too many statements
     break
    case "Choice 2"
        --statements or handler
     break
     ...
     ...
    case "Choice 99"
       --statements or handler
    break
    --always good to include in the development phase to hi-light omissions.
    default
      answer "A case I've not accounted for." titled "Case Omission"
      --check the label of btn 'Master'
      breakpoint
  end switch
end handler1Choice

on handler2Choice
  --switch structure again
end handler2Choice

as many as required.

Although nested switch statements are possible, and are easy enough to
follow if you only have a small matrix of options to cover, once the options
start to multiply it's very easy to created a very complex structure that is
hard to follow and easy to miss options - which is why I like to use the
default statement to catch omissions.

HTH
_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: Switch statements within Switch statements

charles61
Kay,

Thanks very much for your suggestions! I appreciate you taking time to answer my question.


Kay C Lan wrote
on menuPick pChosen
  switch pChosen
    case "1 Choice"
       --avoid statements here to keep switch statement compact
      handler1Choice
    break
     case "2 Choice"
       handler2Choice
    break
    ...
    ...
     case "987 Choice"
       handler987Choice
     break
    --always good to include in the development phase to hi-light omissions.
    default
      answer "A case I've not accounted for." titled "Case Omission"
      --check the variable watcher - pChosen
      breakpoint
  end switch
end menuPick

--the following will also be in the button script

on handler1Choice
  switch the label of btn "Master"
    case "Choice 1"
       --statements here
       --use a handler if too many statements
     break
    case "Choice 2"
        --statements or handler
     break
     ...
     ...
    case "Choice 99"
       --statements or handler
    break
    --always good to include in the development phase to hi-light omissions.
    default
      answer "A case I've not accounted for." titled "Case Omission"
      --check the label of btn 'Master'
      breakpoint
  end switch
end handler1Choice

on handler2Choice
  --switch structure again
end handler2Choice

as many as required.

Although nested switch statements are possible, and are easy enough to
follow if you only have a small matrix of options to cover, once the options
start to multiply it's very easy to created a very complex structure that is
hard to follow and easy to miss options - which is why I like to use the
default statement to catch omissions.

HTH
_______________________________________________
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution