Search

November 27, 2014

IIf - XpressDox

IIf stands for Inline If. This function takes its name from the IIf function in the Basic programming language, which operates in a similar fashion. It is a compact way to make a conditional decision without writing a full «If()»…«Else()»…«End()» block. The entire logic lives in one fillpoint.

 

Syntax

«IIf(condition,value_if_true,value_if_false)»
Parameter Description
condition The question being evaluated (e.g. VatApplicable = 'Yes')
value_if_true What to output when the condition is met
value_if_false What to output when the condition is not met

 

Basic example

Suppose you want to write something like:

The amount of VAT applicable is ….

Where the “….” above is either zero, if no VAT is applicable, or is (Amount * VatPercentage) div 100.

 

Using If.. Else.. End:

Using the If command that would be:

The amount of VAT applicable is «If(VatApplicable = 'Yes')»«FormatNumber((Amount * VatPercentage) div 100)»«Else()»0.00«End()».

 

Using IIf:

You could combine those all into one fillpoint like this:

The amount of VAT applicable is «IIf(VatApplicable = 'Yes',FormatNumber((Amount * VatPercentage) div 100),'0.00')».

Note: Notice that the entire calculation FormatNumber((Amount * VatPercentage) div 100) can be used directly as the true value. IIf can evaluate expressions, not just fixed text.

 

Using IIf inside command parameters

IIf becomes especially useful, and sometimes essential, when you need conditional logic inside a command parameter, such as Caption or OnExitSet. In these cases, an If…Else…End block cannot reliably achieve the same result. When passing IIf as a dynamic value inside a command, wrap it in angle brackets so XpressDox evaluates it as an expression rather than treating it as plain text:

«Caption(DebtorAddress,<IIf(DebtorType = 'Company','REGISTERED ADDRESS OF COMPANY','RESIDENTIAL ADDRESS OF INDIVIDUAL')>)»

Note: Without < >, XpressDox treats the IIf as a literal string and prints it instead of evaluating it. Angle brackets signal that the content is a dynamic expression.

 

 

Related articles:

Conditional processing

Learn more about conditional logic here.