8 Replies Latest reply on Apr 9, 2007 4:43 AM by wgb14

    A case statement question

    wgb14 Level 1
      Hi all,

      I have this case statement

      ((member("Level_1").text=q1b OR member("Level_1").text=q2b OR member("Level_1").text=q3b OR member("Level_1").text=q4b)AND(member("Level_2").text=gphraseB1 OR member("Level_2").text=gphraseB2 OR member("Level_2").text=gphraseB3 OR member("Level_2").text=gphraseB4)AND(member("Level_3").text=gphraseB11 OR member("Level_3").text=gphraseB12 OR member("Level_3").text=gphraseB13 OR member("Level_3").text=gphraseB14) AND (member("Level_4").text=gphraseB16 OR member("Level_4").text=gphraseB17 OR member("Level_4").text=gphraseB18 OR member("Level_3").text=gphraseB19)):

      is there any way to rewrite it to save some space?

      Many thanks
        • 1. Re: A case statement question
          Level 7
          Fisrt off you can set the text to a local variable.

          txt = member ("Level_1").text


          --
          Craig Wollman
          Lingo Specialist
          Word of Mouth Productions
          212-928-9581

          www.wordofmouthpros.com
          "wgb14" <webforumsuser@macromedia.com> wrote in message
          news:ev2g10$oop$1@forums.macromedia.com...
          > Hi all,
          >
          > I have this case statement
          >
          > ((member("Level_1").text=q1b OR member("Level_1").text=q2b OR
          > member("Level_1").text=q3b OR
          > member("Level_1").text=q4b)AND(member("Level_2").text=gphraseB1 OR
          > member("Level_2").text=gphraseB2 OR member("Level_2").text=gphraseB3 OR
          > member("Level_2").text=gphraseB4)AND(member("Level_3").text=gphraseB11 OR
          > member("Level_3").text=gphraseB12 OR member("Level_3").text=gphraseB13 OR
          > member("Level_3").text=gphraseB14) AND (member("Level_4").text=gphraseB16
          > OR
          > member("Level_4").text=gphraseB17 OR member("Level_4").text=gphraseB18 OR
          > member("Level_3").text=gphraseB19)):
          >
          > is there any way to rewrite it to save some space?
          >
          > Many thanks
          >
          >


          • 2. Re: A case statement question
            Xtramania Level 1
            > is there any way to rewrite it to save some space?

            Yes, you may encode this condition in some way and write the parser for the condition statement that will calculate the result.

            You have a set of phrases. Place them into a linear list by their index:
            aPhrases = ["phraseB1","phraseB2",...]

            then you may encode the condition in a way like this:
            strCondition = "L1=p[1] OR L2 = p[2] OR L3 = p[3] OR ... "

            Then you should create a method that will calculate the result of this condition. It is quite simple. Method may search for "p[" and replace it to "aPhrases[", then replace "L1" to "member("&QUOTE&"Level_1"&QUOTE&").text", same things to "L2", etc.

            after you get expanded string jast evaluate it with
            put value(strCondition)

            Once you get it working you will be able to write such statements in much more shorter way.
            • 3. Re: A case statement question
              wgb14 Level 1
              Hi xtramania

              You approach looks interesting but i am not sure ho wto do what you are saying. Can you provide a more specific example?

              Thanks
              • 4. Re: A case statement question
                Level 7
                sorry, that would be
                txt1 = ...
                txt2 = ...
                etc.

                This would save a lot of space and it doesn't require any coding that you
                won't understand.


                --
                Craig Wollman
                Lingo Specialist
                Word of Mouth Productions
                212-928-9581

                www.wordofmouthpros.com
                "wgb14" <webforumsuser@macromedia.com> wrote in message
                news:ev2g10$oop$1@forums.macromedia.com...
                > Hi all,
                >
                > I have this case statement
                >
                > ((member("Level_1").text=q1b OR member("Level_1").text=q2b OR
                > member("Level_1").text=q3b OR
                > member("Level_1").text=q4b)AND(member("Level_2").text=gphraseB1 OR
                > member("Level_2").text=gphraseB2 OR member("Level_2").text=gphraseB3 OR
                > member("Level_2").text=gphraseB4)AND(member("Level_3").text=gphraseB11 OR
                > member("Level_3").text=gphraseB12 OR member("Level_3").text=gphraseB13 OR
                > member("Level_3").text=gphraseB14) AND (member("Level_4").text=gphraseB16
                > OR
                > member("Level_4").text=gphraseB17 OR member("Level_4").text=gphraseB18 OR
                > member("Level_3").text=gphraseB19)):
                >
                > is there any way to rewrite it to save some space?
                >
                > Many thanks
                >
                >


                • 5. Re: A case statement question
                  wgb14 Level 1
                  Hi

                  Yes the answer is that (the easiest one). However, i would like to explore further what xtramania is saying as i already have many variables in my script. So xtrmania anything more specific?

                  Many thanks
                  • 6. Re: A case statement question
                    Xtramania Level 1
                    The idea is based on Lingo value method, that can evaluate any Lingo in text string. Try in messages window:
                    lst = [1,2,3]
                    put value("1+2+4+lst[3]")
                    -- 10

                    Make sure you understand why the result is 10.

                    So, at first you can programmatically construct the Lingo statement and then evaluate it with value() method. It means that you can place your large statement into a text string and call value() on it.

                    To actually shorten the statement I suggest using "search and replace" approach.

                    So the idea is to build the Lingo statement programmatically and then execute it.

                    Anyway, using local variables like
                    txt = member ("Level_1").text
                    together with putting all "phrases" into a list with short name will also help you a lot.






                    • 7. Re: A case statement question
                      Production Monkey Level 3
                      First of all you should perhaps re-evaluate your overall design. It seems very unusual to need such a complicated condition.

                      That said, here's a clean readable way to write your code:

                      L1 = member("Level_1").text
                      Qs = [q1b,q2b,q3b,q4b]
                      L2 = member("Level_2").text
                      P2 = [gphraseB1,gphraseB2,gphraseB3,gphraseB4]
                      L3 = member("Level_3").text
                      P3 = [gphraseB11,gphraseB12,gphraseB13,gphraseB14]
                      L4 = member("Level_4").text
                      P4 = [gphraseB16,gphraseB17,gphraseB18,gphraseB19]

                      case true of
                      (Qs.getPos(L1) <> 0 AND P2.getPos(L2) <> 0 AND P3.getPos(L3) <> 0 AND P4.getPos(L4) <> 0):
                      end case
                      • 8. Re: A case statement question
                        wgb14 Level 1
                        Hi

                        I'll stay with the simply approach of newsgroup user. THANks for all your help