locked
DynamicForecolor oddity RRS feed

  • Question

  • I am adding a DynamicForecolor statement in the Init of a form and it's not behaving the way I thought it would.

     

    A SetAll command works just fine in the grid...

     

    thisform.Grid2.SetAll("DynamicForeColor", ;

    "IIF(.not.empty(ddtapunch.approved), RGB(0,0,255), iif(.not.empty(ddtapunch.shiftvoid), RGB(255,0,0),RGB(0,0,0)))", "Column")

     

    However, if I try to execute a DynamicForecolor statement for just a single column, it's ignored...

     

    thisform.grid2.shiftbeg.dynamicforecolor="iif(2=2,rgb(255,0,0),rgb(0,0,0)"

     

    As you can see, my test logic of 2=2 even did not cause the column to turn red.

     

    Can anyone think of a setting or parameter that would stop the code from firing?

     

    VFP 9 SP2 running on Vista.

     

    Thanks!

     

    Dick

    Friday, March 7, 2008 4:46 PM

Answers

  • Dynamic* properties are all string containing an expression. VFP doesn't raise an error if the expression has a typo (like yours have) but simply ignores setting.

     

    thisform.grid2.shiftbeg.dynamicforecolor="iif(2=2,rgb(255,0,0),rgb(0,0,0))"

     

    Note the closing (was missing) parentheses.

     

    You better write expressions within an extra pair of parentheses:

     

    thisform.grid2.shiftbeg.dynamicforecolor="(iif(2=2,rgb(255,0,0),rgb(0,0,0)))"

     

    Better yet, as expressions are easy to miss for typing errors, use a simple expression that propagates the setting to a method. In method you could code better and catch typing errors. ie:

     

    thisform.myGrid.SetAll('DynamicForeColor','(thisform.GetForeColor())')

     

    And add your custom GetForeColor code to form:

     

    do case

    case !empty(ddtapunch.approved)

      return RGB(0,0,255)

    case!empty(ddtapunch.shiftvoid)

      return RGB(255,0,0)

    otherwise

     return RGB(0,0,0)

    endcase

     

    That way you could use much more complex expressions w/o cluttering it in a string.

    Friday, March 7, 2008 6:12 PM

All replies

  • Dynamic* properties are all string containing an expression. VFP doesn't raise an error if the expression has a typo (like yours have) but simply ignores setting.

     

    thisform.grid2.shiftbeg.dynamicforecolor="iif(2=2,rgb(255,0,0),rgb(0,0,0))"

     

    Note the closing (was missing) parentheses.

     

    You better write expressions within an extra pair of parentheses:

     

    thisform.grid2.shiftbeg.dynamicforecolor="(iif(2=2,rgb(255,0,0),rgb(0,0,0)))"

     

    Better yet, as expressions are easy to miss for typing errors, use a simple expression that propagates the setting to a method. In method you could code better and catch typing errors. ie:

     

    thisform.myGrid.SetAll('DynamicForeColor','(thisform.GetForeColor())')

     

    And add your custom GetForeColor code to form:

     

    do case

    case !empty(ddtapunch.approved)

      return RGB(0,0,255)

    case!empty(ddtapunch.shiftvoid)

      return RGB(255,0,0)

    otherwise

     return RGB(0,0,0)

    endcase

     

    That way you could use much more complex expressions w/o cluttering it in a string.

    Friday, March 7, 2008 6:12 PM
  • Thank you so much!  I would have thought VP would have errored on the bad syntax.

     

    Have a great day!

     

    Dick

     

    Friday, March 7, 2008 6:39 PM