If()

<< Click to Display Table of Contents >>

Navigation:  Available Functions >

If()

Syntax

If( <ConditionExpression>, <TrueValue>, <FalseValue> )

 

Purpose

To evaluate a condition expression (which will evaluate to either TRUE or FALSE), and return one of two values based upon whether the condition was true or false.

 

Parameters

<ConditionExpression> must evaluate to TRUE or FALSE.

 

<TrueValue> is a value to return if <ConditionExpression> is true.

 

<FalseValue> is a value to return if <ConditionExpression> is false.

 

Returns

Either the <TrueValue>, or the <FalseValue>, depending on whether <ConditionExpression> is true or false.

 

Usage

This function is a very advanced function, and is provided for use in very special cases. It provides a way of performing IF-THEN-ELSE logic within the context of a single function call. IF-THEN-ELSE logic is a construct normally only found in programming languages, but it can be very useful in DonorQuest. You can think of it as providing a way for you to define your own functions. For example, the functionality of both the "Min()" and the "Max()" functions could be reproduced using the "If()" function. To replace the "Max()" function with a usage of the "If()" function, you would could make a call to "If()" which looks like this:

 

If( <Value1> > <Value2>, <Value1>, <Value2> )

 

The above "If()" expression says, "If <Value1> is greater than <Value2>, return <Value1>, otherwise return <Value2>." This accomplishes that same thing as:

 

Max( <Value1>, <Value2> )

 

In addition, the "If()" function is not limited to numeric and date values as the "Min()" and "Max()" functions are.

 

Example

The Mailing Label reports provide an excellent example of how the "If()" function may be used. When printing a mailing label, we wish to join together the First and Last names on a single line, with a single space between them. We could do this simply by entering:

 

.First_Name. + " " + .Last_Name.

 

for the Field/Name expression. If the first name is "John" and the last name is "Smith", this would print nicely as:

 

John Smith

 

with the " " providing a space between the two names. However, if the first name was Empty (such is the case when a company name is entered for the last name, and the first name field remains unused), the " " would cause a superfluous space to be printed before the last name like this:

 

Smith

 

To avoid this problem, the mailing label reports use a Field/Name expression like this:

 

.First_Name. + If( Empty( .First_Name. ), "", " " ) + .Last_Name. )

 

Here the "If()" expression will only place a space after the first name if there is a first name to print. Otherwise, it will place an empty character value ("") after the first name, which really amounts to nothing.