Switch...Case - multiple expressions

Feature requests for future versions of Hollywood can be voiced here

Switch...Case - multiple expressions

Postby djrikki » Sun Mar 18, 2018 1:31 pm

I wish this DRY code was possible with the Switch-Case statement:

Code: Select all
Switch msg.id
   Case "listtree-draganddrop"                       
   Case "listtree-sorthook"                                                                              
   Case "pageview-pagemode"                                                       
   Case "group-orientation"
      layout:SaveUserData( MidStr(msg.id,0, FindStr(msg.id,"-")))
EndSwitch


Instead of the verbose:

Code: Select all
Switch msg.id
   Case "listtree-draganddrop"
      Layout:SaveUserData("listtree")
                          
   Case "listtree-sorthook"
      Layout:SaveUserData("listtree")
                                                                              
   Case "pageview-pagemode"
      Layout:SaveUserData("pageview")
                                                       
   Case "group-orientation"
      layout:SaveUserData("group")
EndSwitch
Evolve - Rapid GUI Development tool for MUI Royale and RapaGUI
http://myevolve.wordpress.com
djrikki
 
Posts: 682
Joined: Wed Apr 06, 2011 12:26 am

Re: Switch...Case - multiple expressions

Postby bitRocky » Sun Mar 18, 2018 2:10 pm

You have to use the new FallThrough()
bitRocky
 
Posts: 70
Joined: Fri Nov 14, 2014 7:01 pm

Re: Switch...Case - multiple expressions

Postby djrikki » Sun Mar 18, 2018 2:37 pm

The new FallThrough() statement enables fall through it doesn't exhibit the same behaviour I am discussing. I am looking for "OR' logic.

msg.id would not contain a matching expression, just the last one it finds.

Code: Select all
      layout:SaveUserData( MidStr(msg.id,0, FindStr(msg.id,"-")))
Evolve - Rapid GUI Development tool for MUI Royale and RapaGUI
http://myevolve.wordpress.com
djrikki
 
Posts: 682
Joined: Wed Apr 06, 2011 12:26 am

Re: Switch...Case - multiple expressions

Postby jPV » Sun Mar 18, 2018 3:09 pm

Why wouldn't FallThrough work, like this?

Code: Select all
Switch msg.id
   Case "listtree-draganddrop"
      FallThrough                 
   Case "listtree-sorthook"
      FallThrough                                                                              
   Case "pageview-pagemode"                                                       
      FallThrough
   Case "group-orientation"
      layout:SaveUserData( MidStr(msg.id,0, FindStr(msg.id,"-")))
EndSwitch
User avatar
jPV
 
Posts: 120
Joined: Sat Mar 26, 2016 11:44 am
Location: RNO

Re: Switch...Case - multiple expressions

Postby djrikki » Sun Mar 18, 2018 3:16 pm

@JPV, the contains of the msg object will contain the properties of the final expression.

Code: Select all
   layout:SaveUserData( MidStr(msg.id,0, FindStr(msg.id,"-")))
Evolve - Rapid GUI Development tool for MUI Royale and RapaGUI
http://myevolve.wordpress.com
djrikki
 
Posts: 682
Joined: Wed Apr 06, 2011 12:26 am

Re: Switch...Case - multiple expressions

Postby jPV » Sun Mar 18, 2018 3:21 pm

djrikki wrote:@JPV, the contains of the msg object will contain the properties of the final expression.

Really? I'm pretty sure it doesn't. Why would it change there in the middle of the Switch?
User avatar
jPV
 
Posts: 120
Joined: Sat Mar 26, 2016 11:44 am
Location: RNO

Re: Switch...Case - multiple expressions

Postby djrikki » Sun Mar 18, 2018 3:36 pm

I will have to give it a try for real, but Fallthrough by it's name suggests inheritance is lost.
Evolve - Rapid GUI Development tool for MUI Royale and RapaGUI
http://myevolve.wordpress.com
djrikki
 
Posts: 682
Joined: Wed Apr 06, 2011 12:26 am

Re: Switch...Case - multiple expressions

Postby bitRocky » Sun Mar 18, 2018 3:40 pm

Code: Select all
Function p_Test(id)
   Switch id
      Case 1:
         FallThrough
      Case 2:
         FallThrough
      Case 3:
         FallThrough
      Case 4:
         DebugPrint("id = "..id)
   EndSwitch
EndFunction

p_Test(1)
p_Test(3)
p_Test(4)


Gives:
id = 1
id = 3
id = 4
bitRocky
 
Posts: 70
Joined: Fri Nov 14, 2014 7:01 pm

Re: Switch...Case - multiple expressions

Postby djrikki » Sun Mar 18, 2018 4:06 pm

@JPV @bitRocky it appears I misunderstood the Fallthrough statement it certainly does what I want it to.

Thank you.
Evolve - Rapid GUI Development tool for MUI Royale and RapaGUI
http://myevolve.wordpress.com
djrikki
 
Posts: 682
Joined: Wed Apr 06, 2011 12:26 am


Return to Wishlist

Who is online

Users browsing this forum: No registered users and 4 guests