Empty()

This function tells you whether an item is empty—that is, devoid of content. It has two major uses: checking whether a string is totally blank without having to worry about SET EXACT, and checking whether a variable or field is uninitialized without worrying about its type. Both of these are important enough that EMPTY() appears frequently in our code.

Usage

lIsItEmpty = EMPTY( eExpr )

Parameter

Value

Meaning

eExpr

 

Character

Check whether eExpr is composed only of spaces, tabs (CHR(09)), line feeds (CHR(10)) and carriage returns (CHR(13)).

Any numeric type

Check whether eExpr is 0 or blank.

Logical

Check whether eExpr is .F.

Date

Check whether eExpr contains the empty date { / / }.

 

DateTime

Check whether eExpr contains the empty datetime { / / : : }.

 

Memo or General

Check whether eExpr is completely empty—that is, has no contents at all.

Screen

Gives a "Data Type Mismatch" error.

lIsItEmpty

 

.T.

eExpr is empty according to the definition for the type.

.F.

eExpr is not empty.


Until nulls were added, EMPTY() had only one confusing behavior—that a character variable or field containing only blanks (CHR(32)) is considered empty, while a memo field containing blanks is not. Nulls add to the confusion a little—EMPTY(.NULL.) returns .F. That's because nulls are special and indicate unknown data. Being null is not the same thing as being empty. Use ISNULL() to test for .NULL.

EMPTY() behaves strangely when presented with an object reference variable. If the variable actually contains an object reference, EMPTY() generates error 11, "Function argument value, type or count is invalid," which we disagree with—if it's an object reference, it's not empty. If the variable is .NULL., EMPTY() correctly returns .F. You have to test VARTYPE(var) or TYPE('var') before checking for EMPTY() to avoid this bug.


Example

? EMPTY(cLastName)
 
IF EMPTY(nUserInput)
   WAIT WINDOW "Enter a numeric value"
ENDIF

See Also

Chr(), IsBlank(), IsNull(), Set Exact, Type(), VarType()


Back to Table of Contents

Copyright © 2002-2018 by Tamar E. Granor, Ted Roche, Doug Hennig, and Della Martin. Click for license .