Navigation: Language Reference > 11 - Assignments > Assignment Statements >====== CLEAR (clear a variable) ====== | ![]() ![]() ![]() |
CLEAR(label [,n])
CLEAR | Clears the value from a variable. |
label | The label of a variable (except BLOB types), GROUP, RECORD, QUEUE, CLASS, or FILE structure. If the variable has a DIM attribute, the entire array is cleared. |
N | A numeric constant; either 1 or -1. If omitted or zero, numeric variables are cleared to zero, STRING variables are cleared to spaces, and PSTRING and CSTRING variables are set to zero length. |
The CLEAR statement clears the value from the label variable.
The presence of the n parameter indicates a cleared value other than zero or blank. If n is 1, the label variable is set to the highest possible value for that data type. For the STRING, PSTRING and CSTRING data types, that is all ASCII 255. If n is -1, the label variable is set to the lowest possible value for that data type. For the STRING data type, that is all ASCII zeroes (0). For the PSTRING and CSTRING data types, that is a zero length string.
If the label parameter names a GROUP, RECORD, or QUEUE structure, all variables in the structure are cleared and all reference variables in the structure are set to NULL. If the label parameter names a FILE structure and the n parameter is omitted, all variables in the FILE structure (including any MEMO and/or BLOB fields) are cleared. If the label parameter names a CLASS structure or an object derived from a CLASS, all variables in the object are cleared and all reference variables are set to NULL.
If the variable has a DIM attribute, a single element can be cleared (i.e., CLEAR(MyName[n])), or the entire array is cleared if just the array name is specified (i.e., CLEAR(MyName)). For a STRING, it is possible to clear a range of elements by using string slicing (i.e., CLEAR(MyString[n:m)).
If for any reason you plan to use DISPOSE on an object in a queue that was created with NEW, you must issue the DISPOSE prior to any CLEAR (or DELETE) is executed.
Example:
MyQue QUEUE
F1 LONG
F2 STRING(20)
F3 &CSTRING !Reference to a CSTRING
F4 ANY !ANY can be a reference variable to any simple data type
END
CODE
CLEAR(MyQue) !Equivalent to:
! MyQue.F1 = 0
! MyQue.F2 = ''
! MyQue.F3 &= NULL
! MyQue.F4 &= NULL
CLEAR(Count) !Clear a variable
CLEAR(Cus:Record)!Clear the record structure
CLEAR(Customer) !Clear the record structure and any memos and blobs
CLEAR(Amount,1) !Clear variable to highest possible value
CLEAR(Amount,-1) !Clear variable to lowest possible value
See Also: