Jump to content
  • 0

Calculaties formateren


Peter Wagemans

Question

Posted

Calculaties als deze (Uit Calendar Navigator - schitterend ding):

Case ( Month ( CalendarDates ) = Month ( Extend ( gDate ) ) ; 

Case ( CalendarDates = Get ( CurrentDate ) ; 

TextSize ( 
TextStyleAdd ( 
TextColor ( 
TextFont ( Day ( CalendarDates ) ;
    Extend ( gCalTodayFont ) )  ; 
    RGB ( Extend  ( gCalTodayRed ) ; Extend  ( gCalTodayGreen ) ; Extend  ( gCalTodayBlue ) ) ) ; 
    Evaluate ( Extend ( gCalTodayStyle ) ) ) ; 
    Extend ( gCalTodaySize ) ) ; 


TextSize ( 
TextStyleAdd ( 
TextColor ( 
TextFont ( Day ( CalendarDates ) ;
    Extend ( gCalTextFont ) ) ;
    RGB ( Extend  ( gCalTextRed ) ; Extend  ( gCalTextGreen ) ; Extend  ( gCalTextBlue ) ) ) ; 
    Evaluate ( Extend ( gCalTextStyle ) ) ) ; 
    Extend ( gCalTextSize ) ) ) ;


TextSize ( 
TextStyleAdd ( 
TextColor ( 
TextFont ( Day ( CalendarDates ) ;
    Extend ( gCalTextFont ) ) ;
    RGB ( 90 ; 90; 90 ) ) ; 
    Evaluate ( Extend ( gCalTextStyle ) ) ) ; 
    Extend ( gCalTextSize ) ) 

)

zijn weliswaar estetisch opgesteld, maar je wordt er echt niet wijs uit. Ik zeg niet dat je plotseling het licht zal zien met de formatering hieronder, maar ze is wel een stuk logischer.

 

Ik koos voor 3 spaties om een indent te simuleren, maar dat is een persoonlijke keuze die ook een beetje door de "screen real estate" bepaald wordt.

Case (
Month ( CalendarDates ) = Month ( Extend ( gDate ) ) ;
  // the month of the current repetition of CalendarDates the same as the navigational month
  Case ( 
     CalendarDates = Get ( CurrentDate ) ; 
        // display today
        TextSize ( 
           TextStyleAdd ( 
              TextColor ( 
                 TextFont ( Day ( CalendarDates ) ; Extend ( gCalTodayFont ) )  ; 
                 RGB ( Extend  ( gCalTodayRed ) ; Extend  ( gCalTodayGreen ) ; Extend ( gCalTodayBlue ) )
              ) ; 
           Evaluate ( Extend ( gCalTodayStyle ) )
           ) ; 
        Extend ( gCalTodaySize )
        ) ; 

     // display the other days of the "active" month
     TextSize ( 
        TextStyleAdd ( 
           TextColor ( 
              TextFont ( Day ( CalendarDates ) ; Extend ( gCalTextFont ) ) ; 
              RGB ( Extend  ( gCalTextRed ) ; Extend  ( gCalTextGreen ) ; Extend  ( gCalTextBlue ) )
              ) ; 
        Evaluate ( Extend ( gCalTextStyle ) ) 
        ) ; 
     Extend ( gCalTextSize ) 
     ) 
  ) ;

  // the days outside the current month get a different colour
  TextSize ( 
     TextStyleAdd ( 
        TextColor ( 
           TextFont ( Day ( CalendarDates ) ; Extend ( gCalTextFont ) ) ; 
           RGB ( 90 ; 90; 90 ) 
           ) ; 
        Evaluate ( Extend ( gCalTextStyle ) )
        ) ; 
     Extend ( gCalTextSize ) 
  ) 
)

Merk op dat je nu veel beter de uitsplitsing van de 2 geneste case functies ziet, en ook de combinatie van tekst opmaak functies . Ik probeer hier een logicia te hanteren die programmeurs al jaren gebruiken, vooral als je achteraf nog wil kunnen lezen wat je gemaakt hebt, is dit eigenlijk een absolute must.

 

Het is niet altijd mogelijk om de dingen netjes te formateren. Als je FileMaker Developer gebruikt, is het een goed idee om formules compacter te krijgen door custom functies te verzinnen.

 

Ten slotte is een goed geplaatse comment in een formule van onschatbare waarde.

 

En je kan het ook helemaal anders uitschrijven, deze manier van formules schrijven is nog iets duidelijker vind ik:

Let (
  theDay = Day ( CalendarDates ) ;   
  Case (
  Month ( CalendarDates ) = Month ( Extend ( gDate ) ) ;
     // the month of the current repetition of CalendarDates the same as the navigational month
     Case ( 
        CalendarDates = Get ( CurrentDate ) ; 
           // display today
           Let (
              [
              theFont = Extend ( gCalTodayFont ) ;
              theColour = RGB ( Extend  ( gCalTodayRed ) ; Extend  ( gCalTodayGreen ) ; Extend ( gCalTodayBlue ) ) ;
              theStyle = Evaluate ( Extend ( gCalTodayStyle ) ) ;
              theSize = Extend ( gCalTodaySize )
              ] ;
              TextSize ( TextStyleAdd ( TextColor ( TextFont ( theDay ; theFont ) ; theColour ) ; theStyle ) ; theSize ) 
           ); 

        // display the other days of the "active" month
        Let (
           [
           theFont = Extend ( gCalTextFont ) ;
           theColour = RGB ( Extend  ( gCalTextRed ) ; Extend  ( gCalTextGreen ) ; Extend  ( gCalTextBlue ) ) ;
           theStyle = Evaluate ( Extend ( gCalTextStyle ) ) ;
           theSize = Extend ( gCalTextSize ) 
           ] ;
           TextSize ( TextStyleAdd ( TextColor ( TextFont ( theDay ; theFont ) ; theColour ) ; theStyle ) ; theSize ) 
        ) 
     ) ;

     // the days outside the current month get a different colour
     Let (
        [
        theFont = Extend ( gCalTextFont ) ;
        theColour = RGB ( 90 ; 90; 90 ) ;
        theStyle = Evaluate ( Extend ( gCalTextStyle ) ) ;
        theSize = Extend ( gCalTextSize ) 
        ] ;
        TextSize ( TextStyleAdd ( TextColor ( TextFont ( theDay ; theFont ) ; theColour ) ; theStyle ) ; theSize ) 
     ) 
  )
)

Als je nu nog de

 TextSize ( TextStyleAdd ( TextColor ( TextFont ( theDay ; theFont ) ; theColour ) ; theStyle ) ; theSize )

vervangt door een custom functie CF_Format ( theDay ; theFont ; theColour ; theStyle ; theSize ) ben je er helemaal.

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...