Use Google to find help fast. For example, search on "xpressdox choosefromlist".

The Select/Case/Default Commands

The Select/Case/Default Commands

The Select, Case and Default construct is especially helpful where otherwise a series of «Else()» commands nested inside «If()» commands would be necessary.

This construct is analogous to the Select/Case/Else commands in VBA ( and the switch/case/default construct in C# and similar constructs in other languages).

An example would be the analysis of marks received in a test and comments to be produced on a report card.  Suppose the data element Mark has the mark obtained:

Remarks:

«Select()»
«Case(Mark >= 85)»

Excellent!  Well done!
«End()»
«Case(Mark >= 70)»

Good effort.
«End()»
«Case(Mark >= 60)»

Satisfactory.
«End()»
«Case(Mark >= 50)»

Pass.
«End()»
«Default()»

You need to do better next semester.
«End()»
«End(Select)»

The mechanism employed is that, starting immediately after the Select, the condition in each of the Case commands is evaluated until the first condition that evaluates true is found, and the contents between that Case and its End is inserted into the merged document (this contents can contain further fillpoints, even a nested Select/Case/Default construct).  If no Case condition evaluates as true then the Default contents is used.

In the absence of the Select construct, the way to achieve the same effect would be:

«If(Mark >= 85)»
Excellent!  Well done!
«Else()»
«If(Mark >= 70)»

Good effort.
«Else()»
«If(Mark >= 60)»

Satisfactory.
«Else()»
«If(Mark >= 50)»

Pass.
«Else()»
You need to do better next semester.
«End()»
«End()»
«End()»
«End()»

Note that the mechanism of evaluating the condition of each Case one at a time means that otherwise unrelated conditions can be tested, if this makes sense, such as:

«Select()»
«Case(Mark >= 85)»

Excellent!  Well done!
«End()»
«Case(DateOfBirth > 20120101)»

Astounding!
«End()»
«Default()»

You need to do better next semester.
«End()»
«End()»

The content of Default() will be applied when the condition (Mark < 85) and not(DateOfBirth > 20120101) is true.

The Select, Case, Default and their End commands all need to be on separate paragraphs, as above, or else all need to be in the same paragraph, as in:

«ChooseFromRDBList(Phase,Full,Waxing Gibbous,First Quarter,Waxing Crescent,New,Waning Crescent,Last Quarter,Waning Gibbous)»
Tonight the moon will be «Select()»«Case(Phase = 'Full')»bright«End(full)»«Case(Phase = 'New')»invisible«End(new)»«Case(contains(Phase,'Crescent'))»just a sliver«End(crescent)»«Case(contains(Phase,'Gibbous'))»fairly bright«End()»«Default()»half visible«End(default)»«End(select)».

The above could be written with line-breaks after the Select and after each End – this will render it more legible without breaking the rule that the commands must be either each on their own paragraph or else all in one paragraph.

Leave a Reply