The WIZIF tag controls conditional processing of WIZML statements
Together with WIZSET and WIZLOOP this completes the basic programming constructs of the WIZML language: assignment, sequence, conditional execution and repetition are all there.
The following subjects are covered in this document:
Related information about VTML and WIZML:
|
WIZIF plays a role in the following VTML-driven tools:
WIZSET can occur only within a TAGLAYOUT section or in a Wizard TEMPLATE.
Like the if statement in nearly every programming language, WIZIF enables you to "execute" code only when a condition is true. To test a different condition and act when that (instead of any of the previous ones) is true, there is an equivalent of elseif | elsif clause: WIZELSEIF. And of course there is an equivalent to the else clause as well: WIZELSE, which will let you execute code when none of the preceding conditions in the WIZIF statement are true.
<WIZIF Condition1> HTML and WIZML tags (1) [ <WIZELSEIF Condition2> HTML and WIZML tags (2) ]... [ <WIZELSE> HTML and WIZML tags (3) ] </WIZIF>
Both WIZELSEIF and WIZELSE are optional; the end tag </WIZIF> is required to delimit what is to be executed when the (last) condition is true. There can be any number of WIZELSEIF clauses but only a single WIZELSE clause as part of any WIZIF statement.
HTML and WIZML tags (1) will be executed when Condition1 is true; if Condition1 is not true but Condition2 is, HTML and WIZML tags (2) will be executed. If neither Condition1 nor Condition2 are true, HTML and WIZML tags (2) will be executed.
Condition1 and Condition2 can be any legal boolean expression.
A simple example with only WIZIF and WIZELSE:
<WIZIF OPTIONLinearLayout EQ 'true'> <WIZSET SpacingGap=' '> <WIZELSE> <WIZSET SpacingGap=Chr(13) & Chr(10) & RepeatString(' ',(Len(TagName)+2))> </WIZIF>
A more complicated example is the following where the condition for the WIZIF clause is rather more complicated and there is no WIZELSE clause: this means that the variable Align will not get any value when both conditions evaluate to 'false'. This fact is used later on to decide whether or not to produce code for the attribute ALIGN.
<WIZIF dropAlignMS EQ 'center' OR (dropAlignMS NEQ '' AND dropAlign EQ '')> <WIZSET Align = dropAlignMS> <WIZELSEIF dropAlign NEQ ''> <WIZSET Align = dropAlign> </WIZIF> (...) <WIZIF Align NEQ ''>$$SpacingGap$${DefaultCase('ALIGN')}=$$Align<WIZSET SpacingGap = VertSpacingGap></WIZIF>
As already mentioned above, a condition can be any boolean expression: an expression that yields 'true' or 'false'.
The boolean expression can be arbitrarily complicated or deceptively simple. Below are a number of commented examples to illustrate how conditions can be written and used. You can find more about (boolean) expressions and the operators that can be used in Expressions and Functions.
The following example shows a combination of comparison operators (EQ, NEQ) and boolean operators (OR, AND). Normally AND takes precedence over OR but just to make the condition more readable, brackets have been added. The WIZIF statement here is trying to decide whether to write the value of the browser-specific variant of Align or the HTML-standard variation.
<WIZIF dropAlignMS EQ 'center' OR (dropAlignMS NEQ '' AND dropAlign EQ '')> (...) </WIZIF>
Anything that is "text" and not between WIZML tags in the TAGLAYOUT section will be written. When any non-blank text is found, surrounding white space is written as well. In order to prevent white space being written and still have readable, nicely indented layout of the tags in the TAGLAYOUT section, you can enclose text or partial tags to be written always in a WIZIF statement with a condition that always evaluates to 'true'. This technique is often used in the HTML and VTML tag defintions for the start of a tag and sometimes the ending ">". The example below makes use of the fact that a positive (or non-zero) number is also regarded as 'true' when interpreted as a boolean value:
<WIZIF 1><$$TagName</WIZIF> (... other WIZML statements ..) <WIZIF 1>></WIZIF>
This shows the use of the boolean operator NOT. Since the variable dropVisibility might itself be a boolean,
it's best to enclose the whole expression (dropVisibility EQ 'inherit') in brackets here to avoid confusion or
unexpected results.
The WIZIF statement here decides whether or not to write the VISIBILITY attribute of the LAYER tag:
if the value in the DropDown is 'inherit' it does not need to be written since this is the default.
<WIZIF NOT (dropVisibility EQ 'inherit')> (...) </WIZIF>
Just as a non-zero (positive or negative!) number is interpreted as 'true' when interpreted as a boolean value, zero evaluates to 'false'. This can be used to include comments in the TAGLAYOUT section without having them written out: by enclosing such comments in a WIZIF statement that is always false, they will not be written (otherwise they would be seen as "text" and written). In this example the comment is written inside HTML comment tags; of course this is not strictly necessary; it only serves to indicate visually that it is indeed a comment.
<WIZIF 0><!-- This is a comment --></WIZIF>
The following example from Attrib.vtm shows how a commented-out statement in the TAGLAYOUT section will not be written:
<WIZIF 0><!-- <WIZIF txtDefault NEQ ''>$$Tab$${DefaultCase('DEFAULT')}="$$txtDefault"</WIZIF> --></WIZIF>
As the syntax for WIZIF suggests, the code to be executed when a tested condition is true can contain or consist of WIZML tags: so obviously this can include nested WIZIF (or WIZLOOP) statements, enabling quite sophisticated processing in the WIZML section.
The following example is from the WIZIF tag editor (Wizif.vtm), writing the result of the condition builder:
<WIZIF 1><$$TagName </WIZIF> <WIZIF Var11 NEQ ''> <WIZIF dropOperator1 NEQ '' AND Var12 NEQ ''> <WIZIF dropAndOr NEQ ''>($$Var11 $$dropOperator1 $$Var12)<WIZELSE>$$Var11 $$dropOperator1 $$Var12</WIZIF> <WIZIF dropAndOr NEQ '' AND Var21 NEQ ''> <WIZIF dropOperator2 NEQ '' AND Var22 NEQ ''> <WIZIF 1> $$dropAndOr ($$Var21 $$dropOperator2 $$Var22)</WIZIF> <WIZELSE> <WIZIF 1> $$dropAndOr $$Var21</WIZIF> </WIZIF> </WIZIF> <WIZELSE> <WIZIF 1>$$Var11</WIZIF> </WIZIF> </WIZIF> <WIZIF 1>></WIZIF>