Nested IF's in a Code Block

This forum is for eXpress++ general support.
Post Reply
Message
Author
User avatar
rdonnay
Site Admin
Posts: 4729
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Nested IF's in a Code Block

#1 Post by rdonnay »

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.

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
The eXpress train is coming - and it has more cars.

skiman
Posts: 1185
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

Re: Nested IF's in a Code Block

#2 Post by skiman »

Roger,

This looks great. 95% of my compile errors are concerning nested if's in a codeblock. This will make my life easier.
Best regards,

Chris.
www.aboservice.be

Post Reply