HPlogo HP Data Entry and Forms Management System (VPLUS) Reference Manual: HP 3000 MPE/iX Computer Systems > Chapter 4 Advanced Forms Design

IF

» 

Technical documentation

Complete book in PDF
» Feedback

 » Table of Contents

 » Index

Used to execute any of the processing statements only under certain conditions.

Syntax

[IF condition THEN [statement]
[statement]
.
.
.
[statement]

[ELSE [statement]
[statement
].
.
.
[statement]]]

where condition is:

[{ constant
field

save field

expression

(indexretrieve)
}
editstatement
]

Parameters

condition

A condition specified in an IF statement can be any edit statement described below. The edit statement can be preceded by a constant, a field name, a save field name, an expression, or an index retrieve operand within parentheses. Refer to "Statement Syntax" earlier in this section for details. If an operand precedes the edit statement, that value is tested; otherwise, the value of the current field is tested.

If editing statement passes, then the condition is true. If it does not, then the condition is false. Note that this differs from interpretation of a standalone edit statement, which causes the field to return an error and stops field processing if the data fails the edit. Only edit statements can be used in conditions.

editstatement

A condition specified in an IF statement can be any edit statement MATCH and CDIGIT

statement

Any of the processing statements can be executed conditionally depending an the run-time interpretation of the specified condition. Refer to the syntax rules below.

Discussion

An IF statement consists of two groups of statements: the THEN part and the ELSE part. Either may have no statements associated with it. The THEN part may include statements on the same line as THEN, plus statements indented from the IF on immediately following lines. An ELSE statement at the same level of indentation as the IF corresponds to that IF. Like the THEN part, the ELSE part can have statements on the same line, plus statements on immediately following lines that are indented from it. Nested IF statements must be indented from each enclosing IF, but otherwise follow the same rules. Table 4-10 “Variations on the IF Statement” illustrates some variations on the IF statement according to the syntax rules, which are:

  • No more than one IF or ELSE statement may appear on the same line.

  • When non-IF statements follow either the THEN or the ELSE, they may be on the same line as the THEN or ELSE. Statements can be separated from each other by an optional semicolon (;).

  • The entire ELSE portion of the statement may be omitted. In such a case, no statement is executed if the condition is false. If ELSE is included, it must be the first statement following the THEN part that is at the same level of indentation as its corresponding IF.

  • Nested IF statements are allowed to a maximum of eight levels of nesting. They must maintain nested indenting.

  • When nested IF statements are specified, they must be indented. The indenting is essential for multiple statements to identify the scope of the THEN part, as well as the ELSE part.

  • An IF statement (including the THEN and ELSE part) must not cross phase boundaries. (Refer to "Phases" later in this section.)

Example

IF QUANTITY GT 100 THEN...

If the current value of the field QUANTITY is greater than 100, any statements in the THEN part at the same level are executed.

IF NE $EMPTY THEN...

If there is a value in the current field (it is not blank), then any statements in the THEN part are executed.

IF SAV1 IN 12:50,100:120 THEN...

If the value of the save field is within the range 12 through 50 or 100 through 120, then any statements associated with THEN are executed.

IF MINLEN 1 THEN...

If at least one character was entered in the current field, execute any statements associated with THEN.

Table 4-10 Variations on the IF Statement

Variation

Description

IF condition THEN statement

Simple IF statement. If condition is true, then statement is executed; if false, then statement is not executed.

IF condition THEN
statement
statement

statement

If condition is true, all three statements are executed in the order specified. If condition is false, none of the three statements is executed.

IF condition THEN statementA ELSE statementB

If condition is true, statementA is executed; otherwise, statementB is executed.

IF condition THEN statementA statementB statementC
ELSE
statementD

The statementA, statementB and statementC are executed if the condition is true; statementD is executed if the condition is false,

IF condition THEN statementA statementB
statementC

ELSE statementD

If condition is true, statementA, statementB, and statementC are executed; otherwise statementD is executed.

IF condition1 THEN
IF condition2 THEN statementA
statementB

ELSE

IF
condition3
statementC
statementD

ELSE

statementE

Only if condition1, condition2 are both true, statementA, statementB are executed.

Only if condition1, condition3 are true, but condition2 is false, is statementC executed.

Only if condition1 is true, regardless of whether condition2, condition3 are true, is statementD executed.

Only if condition1 is false, is statementE executed.

 

Feedback to webmaster