View contents of this chapter

The IIf() and Choose() Functions

The IIf function works well for short If...Else statements.

IIf(expr, truepart, falsepart)

Consider the following example:

If (val < 200) Then
  ans = 0
Else
  ans = 1
End If

The above can be written in a single line:

ans = IIf (val < 200, 0, 1)

The Choose() function provides a shortcut for some Select Case statements. Choose() can have many arguments. Depending on the value of its first argument, Choose() returns only one of the remaining arguments.

Choose(index, choice-1[, choice-2, ... [, choice-n]])

Play Sound The Choose() selects on an integer value only, not on a more complete comparision.

The index must be a variable or field that equates to a number from 1 to the number of choices in the function. The function returns a value from the list of choices based on the value of index. If index is 1, Choose returns the first choice in the list; if index is 2, it returns the second choice, and so on.



© Universal Teacher Publications        INDEX Previous Screen Next Screen