Navigation:  Reference > Functions >

ImmediateIf()

Print this Topic Previous pageReturn to chapter overviewNext page

 

IIF(1,2,3)

 

PURPOSE

This function can return many different values depending on whether the logical expression provided returns .T. or .F.

 

PARTS

 

1 lexprRequired - The expression to evaluate to determine what should be returned.

 

2 f/c/eIf the lexpr in part 1 evaluates to .T. the function will return this value.

 

3 f/c/eIf the lexpr evaluates to .F. the function will return this value.

 

 

RETURN TYPE - Variable

The return type depends entirely on the function.

 

COMMENTS

If you are only concerned about one type of return (i.e., only .T. or only .F.), the other part need not be included.

 

NOTE:  This is probably the most important function in TAS Professional and is very useful in many different situations.

 

EXAMPLE

 

define x type i

define a type a size 10

x = 1

a = iif(x=1,,'False')

// in this case a would be blank ("")

 

a = iif(x=1,'True')

// in this case a would contain the value: 'True'

 

NOTE:  You must be careful about what you put into the True/False options in this function.  Due to the way the expression compiler and executor work, if the values to be returned are expressions also (including UDFs), they will be resolved (executed) before the value of the IIF() is determined.  For example:

 

       x=5

       y=10

       a = iif(x>y,fill(x-y,' '),2)

 

If x>y was true then the routine above would use the difference to calculate how many space characters (' ') to print.  However, since the inner expressions are evaluated before the IIF() an unexpected result could occur, as in this case.  The program will return an error instead of what you expected.  The proper way to set this up would be:

 

       a = fill(iif(x>y,x-y,2), ' ')

 

This would work properly each time.

 

 


Page url: http://www.cassoftware.com/tas/manual/immediateif().htm