4 Replies Latest reply on Sep 20, 2012 1:09 PM by andretru2

    If condition based on text color?

    andretru2

      Title

      If condition based on text color?

      Post


           Is it possible to make an if condition based on the color of the text?

           I have about 47 calculation fields that become red (using the textcolor function) when they are innacurate. In order for a form to be 'finalized', all these fields must not be red (the textcolor).

           If more info is needed please let me know.

           Thanks

        • 1. Re: If condition based on text color?
          philmodjunk

               You can't test the text color, but you can certainly test the conditions that produced the text color in the first place.

          • 2. Re: If condition based on text color?
            andretru2

                 Hmmm each field has many rules and return different outputs. Any other suggestions?

            • 3. Re: If condition based on text color?
              philmodjunk

                   My suggestion will work. Your test can combine all those tests into a single calculation. Please note that if testing the color were possible, you'd still have to concoct a calcualtion that tests every layout object that might have turned red, so such a combined calculation--though simpler would be necessary even if you could check the color.

                   Another option that may or may not work, is to use a script trigger or calculation field to set a value in a field as a flag for each error condition that changes the color of a layout object to red. Then your test becomes simply  a test to see if all these flags are empty or zero:

                   If [ Sum ( flag1; flag2 ; flag3 ; /* and so forth */) > 0 ]

                   or:

                   If [ Flag1 + Flag2 + Flag3 /* and so forth */ > 0 ]

              • 4. Re: If condition based on text color?
                andretru2

                     Thank you. However, I found this custom function that does the job.  The script will go to each of the calculation fields and test whether they are red or not. If any of them is, the script will exit. 

                     /*
                     GetTextColor function

                     Small modification Michael Horak's GetRGB function-

                     Author
                     Michael Horak *COMMENT Visual Realisation
                     with a very small modification by Joe Gold of Angel City Data

                     Format
                     GetTextColor ( Text)

                     Parameters
                     text - any text expression or text field

                     Data type returned
                     number

                     Description
                     Returns an integer value representing the text color.
                     */

                     Let ( [

                     theText = Substitute ( text ; ¶ ; "" ) ;
                     style = GetAsCSS ( Substitute ( theText ; "#" ; "~" ) ) ;

                     // THE FIRST LINE OF CSS (contains portions of text. surrounded by style tags)
                     styleLine = Substitute ( LeftValues ( style ; 1 ) ; ¶ ; "" ) ;

                     // THE TEXT PORTION OF THE FIRST LINE OF CSS
                     styleLineText = Evaluate ( Substitute (
                     Quote ( styleLine ) ;
                     [ "<" ; Quote ( "& Left (" ) ] ;
                     [ ">" ; Quote ( " ; 0 ) & " ) ]
                     )
                     ) ;

                     // WHERE IS THE TEXT PORTION IN THE TEXT ITSELF?
                     pos = Position ( theText ; styleLineText ; 1 ; 1 ) ;

                     // FROM END OF THE CURRENT TEXT TO END OF TEXT
                     nextText = Middle ( theText ; pos + Length ( styleLineText ) ; Length ( theText ) - Length ( styleLineText ) + 1 ) ;

                     // IS THERE A COLOR TAG IN THE CURRENT STYLE LINE? AND WHERE IS IT?
                     colorStart = Position ( styleLine ; "#" ; 1 ; 1 ) ;

                     // GET CURRENT COLOR
                     hex = Middle ( styleLine ; colorStart + 1 ; 6 ) ;

                     hexR2 = Substitute ( Middle ( hex ; 1 ; 1 ) ;
                     [ "A" ; "10" ] ; [ "B" ; "11" ] ; [ "C" ; "12" ] ; [ "D" ; "13" ] ; [ "E" ; "14" ] ; [ "F" ; "15" ] ) ;

                     hexR1 = Substitute ( Middle ( hex ; 2 ; 1 ) ;
                     [ "A" ; "10" ] ; [ "B" ; "11" ] ; [ "C" ; "12" ] ; [ "D" ; "13" ] ; [ "E" ; "14" ] ; [ "F" ; "15" ] ) ;

                     hexG2 = Substitute ( Middle ( hex ; 3 ; 1 ) ;
                     [ "A" ; "10" ] ; [ "B" ; "11" ] ; [ "C" ; "12" ] ; [ "D" ; "13" ] ; [ "E" ; "14" ] ; [ "F" ; "15" ] ) ;

                     hexG1 = Substitute ( Middle ( hex ; 4 ; 1 ) ;
                     [ "A" ; "10" ] ; [ "B" ; "11" ] ; [ "C" ; "12" ] ; [ "D" ; "13" ] ; [ "E" ; "14" ] ; [ "F" ; "15" ] ) ;

                     hexB2 = Substitute ( Middle ( hex ; 5 ; 1 ) ;
                     [ "A" ; "10" ] ; [ "B" ; "11" ] ; [ "C" ; "12" ] ; [ "D" ; "13" ] ; [ "E" ; "14" ] ; [ "F" ; "15" ] ) ;

                     hexB1 = Substitute ( Middle ( hex ; 6 ; 1 ) ;
                     [ "A" ; "10" ] ; [ "B" ; "11" ] ; [ "C" ; "12" ] ; [ "D" ; "13" ] ; [ "E" ; "14" ] ; [ "F" ; "15" ] ) ;

                     R = 16 * hexR2 + hexR1 ;
                     G = 16 * hexG2 + hexG1 ;
                     B = 16 * hexB2 + hexB1

                     ] ;

                     Case (
                     // IF THERE IS A COLOR TAG IN THE CURRENT STYLE LINE
                     colorStart ;
                     // GET RGB VALUES IN THE CURRENT STYLE LINE
                     R *65536+ G *256+ B
                     )

                     )