Search code examples
crystal-reports

conditional color formatting based on string and number


I am trying to fix the logic in my report where any {nresult} > {flaglevel} =crred. This works except we initially didn't take into account the fact that {flaglevel} defaults to 0 unless a specific number is entered. so ALL {nresult} are red even if {flaglevel} is just the default.

{nresult} is a number and {flaglevel} is a string. The current code is

If {PRM_SxData.nResult} > tonumber({PRM_SxData.FlagLevel}) 
then crRed 
Else crBlack

I tried to make a separate formula for {flaglevel} except I have to have a number after else so it doesn't work.

if tonumber ({PRM_SxData.FlagLevel}) > 0
then tonumber({PRM_SxData.FlagLevel})
else " "

Essentially what I need is something like this:

If {PRM_SxData.nResult} > tonumber({PRM_SxData.FlagLevel}) //where flaglevel >0 
then crRed 
Else crBlack

Solution

  • I am kinda pessimist about user input and i think R.McMillan made a good question, so i would go with something like this:

    If (not isnull({PRM_SxData.FlagLevel))
    AND {PRM_SxData.FlagLevel} <> ""
    AND {PRM_SxData.nResult} > tonumber({PRM_SxData.FlagLevel})
    then crRed 
    Else crBlack
    

    Please, try this and let us know what happened.

    If it does not work, print {PRM_SxData.FlagLevel} somewhere to check its value.