0

Switch Case Statement: combine multiple cases with same code

I have a switch/case statement where I would like to combine "case 1:" and "case 4:" since both use the same if/then code (rather than duplicate the code in a separate "case 4:" statement --which works), but I can't figure out the syntax.

switch Source do
case 1: and case 4:
        if TaxReqd = false and ResvDept = true then
            '01Hdr1pymtDep'
        else ...

Thanks in advance.

Bob

9 replies

null
    • John_Halls
    • 10 mths ago
    • Reported - view

    Hi bflack, I've not tried this so just off the top of my head could you put the code in a user-defined function and call that for the two cases.

    Also, maybe try swapping case 1 and case 4 for case 1 or case 4

    Regards John

    • Kruna
    • 10 mths ago
    • Reported - view

    Hi Bob,

    if I understood right, according to this link it seems to be not possible:

    https://forum.ninox.com/t/q6hdmzw/switch-case-statement-in-ninox

    regards Kruna

      • John_Halls
      • 10 mths ago
      • Reported - view

       Following this thread, the conversation in the next link between Fred and Jacques means you can use the switch true structure thus

      switch true do
      case Source = 1 or Source = 4:
              if TaxReqd = false and ResvDept = true then
                  '01Hdr1pymtDep'
              else ...
      

      Regards John

      • Kruna
      • 10 mths ago
      • Reported - view

      John Hallsyes I followed the other link and saw that also something like

      case [1, 3]
      
      

      I tried this before posting and it didnt work, so I assumed it may not work or maybe related to another issue.

      Honestly its also far beyond my knowledge in Ninox😆 hoping you/Bob would read the other link and understand more than me😀

      • John_Halls
      • 10 mths ago
      • Reported - view

       No need to look at the rest of that thread, just the use of switch true do. My code above will give you what you want. You will also have to use Source = 2 etc for the other case statements. 

      • bflack
      • 10 mths ago
      • Reported - view

      John Halls This approach [switch true do] works like a charm. And yes, other cases for Source must be then addressed ... case Source = 2: 

      I'm guessing it's impossible for Ninox to fully document these variations, so thanks to the forum for responses.

      • John_Halls
      • 10 mths ago
      • Reported - view

       I don't think it was developed with this in mind, it's just those clever chaps on the forum that are able to leverage additional functionality (you know who you are!).

      • Fred
      • 10 mths ago
      • Reported - view

      KrunaIf you want to use Jacques' sample then it would look something like:

      let n := number(Source)
      switch true do
      case [1,4][=n]>0:
              if TaxReqd = false and ResvDept = true then
                  '01Hdr1pymtDep'
              else ...
      
      • Kruna
      • 10 mths ago
      • Reported - view

      thank you, I will try it out. :-)

Content aside

  • Status Answered
  • 10 mths agoLast active
  • 9Replies
  • 335Views
  • 4 Following