/////////////////////////////////////////////////////////// // Function : f_If() // Author : PowerObject! [Shekar C. Reddy] // Date : 4/11/2002 /////////////////////////////////////////////////////////// // Desc : If() PowerScript expression-function!!! /////////////////////////////////////////////////////////// All, We've wanted the If() expression-function in PowerScript for a long time. Although Sybase included it as a dw-object/InfoMaker function, they do not seem to have understood its incredible power as a PowerScript function to use it in "in-line" assignments/expressions... We can find this function in even the legacy tools such as FoxBASE+, CA-Clipper... Well! Why wait for Sybase? Write your own If() function now and enjoy its power. Name it as f_If() instead of If() so it does not over-ride the one from Sybase - if they ever provide one in future: ///////////////////////////////////////////////////////////////////// GLOBAL FUNCTION any f_If( readOnly boolean ab_Expression, & readOnly any aa_TrueValue, readOnly any aa_FalseValue ) ///////////////////////////////////////////////////////////////////// // Retuns NULL if ab_Expression is NULL ///////////////////////////////////////////////////////////////////// // Do NOT "recurse" f_If() here!! :~) any la_Null ; // IF IsNull( ab_Expression ) THEN // Error SetNull( la_Null ) ; RETURN la_Null ; ELSEIF ab_Expression THEN RETURN aa_TrueValue ; END IF ; // RETURN aa_FalseValue ; ///////////////////////////////////////////////////////////////////// // USAGE of f_If() ///////////////////////////////////////////////////////////////////// date ld_Today ; string ls_Name ; boolean lb_Flag ; // ld_Today = f_If( SQLCA.of_IsConnected(), & gnv_Oracle.of_GetServerDate(), Today()) ; // ls_Name = Trim( f_If( IsNull( FirstName ), "", FirstName ) + " " + & f_If( IsNull( LastName ), "", LastName )) // // Switch the value of lb_Flag lb_Flag = f_If( lb_Flag, NOT lb_Flag, lb_Flag ) ; // // More examples showing the power of in-line assignments dw.DataObject = f_If( ib_ReportMode = "D", "d_Detailed", "d_Summary" ) ; // dw.of_SetTransObject( f_If( SQLCA.of_GetDBMS() = "ORACLE", & itr_Oracle, itr_Sybase )) ; ///////////////////////////////////////////////////////////////////// Now, any takers for writing the dw Case() function?! Regards, -- PowerObject! ----------------------------------------- http://Groups.Yahoo.com/group/PowerObject PowerBuilder / PFC Developers' Group