« Employ SQL-SELECTs "TO SCREEN" clause to determine if a record exists | Main | Debugging errors that occur only in production code »
August 16, 2008
Make use of methods for complex Dynamic... grid settings
In a grid's Init() event method:
*--------------------------------------------------------------------------
* Set the .DynamicBackColor property for this column.
*--------------------------------------------------------------------------
This.Column1.DynamicBackColor = [ThisForm.DynamicBackColorForThisColumn()]
In the form's custom DynamicBackColorForThisColumn() method:
*-----------------------------------------------------------------------------------
* Method: DynamicBackColorForThisColumn()
* Purpose: Handles the initialization of DynamicBackColor for the grid's Column
*
* Notes: It is *far* easier to put the logic into this method (and allows
* us to document it thoroughly) rather than trying to "stuff" text
* into the grid's .Column1.DynamicBackColor property.
*
* Plan Codes:
* 01 - Bill full cost
* 07 - Zero AtP (do not send bill)
* 08 - Zero AtP (do send bill)
*-----------------------------------------------------------------------------------
LOCAL lcColor
DO CASE
CASE AtP_PlanCd = '01'
lcColor = 'RGB(255, 255, 255)'
CASE AtP_PlanCd = '07'
lcColor = 'RGB(0, 0, 0)'
CASE AtP_PlanCd = '08'
lcColor = 'RGB(192, 192, 192)'
OTHERWISE
lcColor = '<some default color>'
ENDCASE
RETURN lcColor
The above could have been coded in the grid's Init() event method as follows:
*-----------------------------------------------------
* Set the .DynamicBackColor property for this column.
*-----------------------------------------------------
This.Column1.DynamicBackColor = [IIF(AtP_PlanCd = '01', 'RGB(255, 255, 255)', ;
IIF(AtP_PlanCd = '07', 'RGB(0, 0, 0)', IIF(AtP_PlanCd = '08', ;
'RGB(192, 192, 192)', '<some default color>')))]
Which implementation do you think is easier to read, debug and maintain?
Even with VFP 9's new ICASE() function, it's still challenging to read, debug and maintain:
This.Column1.DynamicBackColor = [ICASE(AtP_PlanCd = '01', 'RGB(255, 255, 255)', ;
AtP_PlanCd = '07', 'RGB(0, 0, 0)', AtP_PlanCd = '08', 'RGB(192, 192, 192)', ;
'<some default color>')]
(By the way, the form-level method could alternatively be implemented as a [class-level] method of a grid class.)
Posted by abergquist on August 16, 2008 | Permalink
TrackBack
TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00d8341fba8753ef00e553ebac9b8833
Listed below are links to weblogs that reference Make use of methods for complex Dynamic... grid settings:
» Zoo sex pictures animal porn movies beast trailers. from Zoo sex sex.
Zoo sex sex. Zoo sex. Free zoo sex. [Read More]
Tracked on Jun 23, 2009 2:48:47 PM




