Nested IF's in a Code Block
Posted: Mon Jun 04, 2012 5:16 pm
This sample program shows how to use the IIF command as a more readable
and maintable replacement to the IIF() function in code blocks.
This command is contained in DCDIALOG.CH in build 257 or later.
It pre-processes IIF statements to using the IIF() function.
Compile with the /p switch and then look a TEST.PPO to see the pre-processed output.
and maintable replacement to the IIF() function in code blocks.
This command is contained in DCDIALOG.CH in build 257 or later.
It pre-processes IIF statements to using the IIF() function.
Compile with the /p switch and then look a TEST.PPO to see the pre-processed output.
Code: Select all
// Test.Prg
#xtranslate IIF <exp> <IFclauses,...> ELSE <ELSEclauses,...> ENDIF => ;
IIF( <exp>,(<IFclauses>),(<ELSEclauses>) )
#xtranslate IIF <exp> <IFclauses,...> ENDIF => IIF( <exp>,(<IFclauses>), nil )
#INCLUDE "dcdialog.CH"
FUNCTION Main()
LOCAL bBlock, lTestMode := .f., lTestMode2 := .t., lTestMode3 := .t., lTestMode4 := .t.
bBlock := {|| ;
IIF !lTestMode ;
DoSomething(1), ;
DoSomething(2), ;
IIF lTestMode2 ;
DoSomething(3), ;
DoSomething(4) ;
ENDIF ;
ELSE ;
DoSomething(5), ;
DoSomething(6), ;
IIF lTestMode3 ;
DoSomething(7) ;
ELSE ;
DoSomething(8), ;
IIF lTestMode4 ;
DoSomething(9) ;
ELSE ;
DoSomething(10) ;
ENDIF ;
ENDIF ;
ENDIF ;
}
Eval(bBlock)
DCMSGBOX 'Done'
RETURN nil
* ----------
FUNCTION DoSomething( nWhich )
WTF nWhich
RETURN nil
* ----------
PROC appsys ; return