Function Empty() Foundation
Tests whether an expression returns an empty value.
Empty( <Expression> ) --> lEmpty
The return value of Empty() is .T. (true) when the value of <Expression> is empty, otherwise it is .F. (false). An empty value depends on the data type of the value. The following table lists the empty values for each data type:
Valtype() | Data type | Value |
---|---|---|
A | array | {} (array with length 0) |
B | code block | no empty value |
C | character | blank spaces, tabs, CRLF or null strings ("") |
D | date | CtoD("") or CtoD(" / / ") (empty date) |
L | logical | .F. (False) |
N | numeric | 0 |
O | object | no empty value |
U | undefined | NIL |
The logical function Empty() is frequently used for validation of data input. For example, it can be used to test whether a user has entered data in an input field. The function is also used for parameter testing within functions and procedures when a value for a passed parameter is required.
// The example demonstrates "empty" values and the result
// of Empty()
PROCEDURE Main
? Empty( Space(20) ) // result: .T.
? Empty( "" ) // result: .T.
? Empty( Chr(13)+Chr(10) ) // result: .T.
? Empty( Chr(9) ) // result: .T.
? Empty( 0 ) // result: .T.
? Empty( CtoD("") ) // result: .T.
? Empty( CtoD(" / / ") ) // result: .T.
? Empty( .F. ) // result: .T.
? Empty( NIL ) // result: .T.
? Empty( {||NIL} ) // result: .F.
? Empty( GetNew() ) // result: .F.
RETURN
// In this example the name of a customer in a customer file
// must have a value before it is stored in the DBF file:
PROCEDURE Main
LOCAL cName := Space(20)
USE Customer NEW
@ 5, 10 GET cName VALID {|c| ! Empty( cName ) }
READ
IF Updated()
REPLACE Customer->Name WITH cName
ENDIF
RETURN
If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.