Sign in to follow this  
Followers 0
bouncingmolar

simplifying Case definitions

4 posts in this topic

#1 ·  Posted (edited)

I have a menu (GUICtrlCreateMenu) with a few options. Many of the options share similar functions except maybe a change of variable.

Is there an easier way to write this without the repitition. (ie in my example, write functiona b c d e f g h just once)

Thanks

Switch
  Case $menuoption1
      $function="function1"
      functiona
      functionb
      functionc
      functiond
      functione
      functionf
      functiong
      functionh
      Exitloop

  Case $menuoption2
      $function="function2"
      functiona
      functionb
      functionc
      functiond
      functione
      functionf
      functiong
      functionh
      Exitloop

  Case $menuoption3
      $function="function3"
      functiona
      functionb
      functionc
      functiond
      functione
      functionf
      functiong
      functionh
      Exitloop

  Case $menuoption4
      totally different set of commands
      totally different set of commands
      totally different set of commands
      totally different set of commands
Endswitch
Edited by bouncingmolar

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I have a menu (GUICtrlCreateMenu) with a few options. Many of the options share similar functions except maybe a change of variable.

Is there an easier way to write this without the repitition. (ie in my example, write functiona b c d e f g h just once)

Thanks

Switch
  Case $menuoption1
      $function="function1"
      functiona
      functionb
      functionc
      functiond
      functione
      functionf
      functiong
      functionh
      Exitloop

  Case $menuoption2
      $function="function2"
      functiona
      functionb
      functionc
      functiond
      functione
      functionf
      functiong
      functionh
      Exitloop

  Case $menuoption3
      $function="function3"
      functiona
      functionb
      functionc
      functiond
      functione
      functionf
      functiong
      functionh
      Exitloop

  Case $menuoption4
      totally different set of commands
      totally different set of commands
      totally different set of commands
      totally different set of commands
Endswitch
First off you can't use switch like that. What you have there is actually the proper structure for Select. Almost, at any rate.

Func _RunFuncs($iMsg)
   Switch $iMsg
      Case $menuoption1
          $function="function1"
      Case $menuoption2
          $function="function2"
      Case $menuoption3
          $function="function3"
      Case $menuoption4
   EndSwitch
   If $iMsg <>  $menuoption4 Then
      functiona
      functionb
      functionc
      functiond
      functione
      functionf
      functiong
      functionh
   Else
      totally different set of commands
      totally different set of commands
      totally different set of commands
      totally different set of commands
   EndIf
EndFunc
Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

I have a menu (GUICtrlCreateMenu) with a few options. Many of the options share similar functions except maybe a change of variable.

Is there an easier way to write this without the repitition. (ie in my example, write functiona b c d e f g h just once)

Thanks

Switch
  Case $menuoption1
      $function="function1"
      functiona
      functionb
      functionc
      functiond
      functione
      functionf
      functiong
      functionh
      Exitloop

  Case $menuoption2
      $function="function2"
      functiona
      functionb
      functionc
      functiond
      functione
      functionf
      functiong
      functionh
      Exitloop

  Case $menuoption3
      $function="function3"
      functiona
      functionb
      functionc
      functiond
      functione
      functionf
      functiong
      functionh
      Exitloop

  Case $menuoption4
      totally different set of commands
      totally different set of commands
      totally different set of commands
      totally different set of commands
Endswitch
Maybe replace the list with functionaTOh() and in that function have the list.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Maybe replace the list with functionaTOh() and in that function have the list.

That would work too.

It depends on what you are doing in the rest of your code.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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