IsNull

Description

Reports whether the value of a variable or expression is null.

Syntax

IsNull ( any )

Argument

Description

any

A variable or expression that you want to test to determine whether its value is null

Returns

Boolean. Returns true if any is null and false if it is not.

Usage

Use IsNull to test whether a user-entered value or a value retrieved from the database is null.

If one or more columns in a DataWindow are required columns, that is, they must contain data, you do not want to update the database if the columns have null values. You can use FindRequired to find rows in which those columns have null values, instead of using IsNull to evaluate each row and column.


Setting a variable to null

To set a variable to null, use the SetNull function. In standard PowerBuilder applications, if a variable is not set to null explicitly by calling the SetNull function, calling the IsNull function against the variable returns false.

In general, the same applies in .NET applications. However, if the variable is of a reference type (a type derived from the PowerObject base class), IsNull returns true if the variable has not been initialized by assigning an instantiated object to it. In the following example, IsNull returns false in a standard PowerBuilder application, but it returns true in a .NET application:

dataStore ds
boolean b

b = IsNull(ds)
MessageBox("IsNull", string(b)) 

If the variable is explicitly set to null, IsNull returns true in both standard and .NET applications:

SetNull(ds)
b = IsNull(ds)
MessageBox("IsNull", string(b)) 

To ensure consistent behavior in standard and .NET applications, use the IsValid function to check whether an object has been instantiated instead of using the IsNull function. In the following example, each of the calls to IsValid returns false in both standard and .NET applications:

dataStore ds
boolean b

b = IsValid(ds)
MessageBox("IsValid", string(b))

SetNull(ds)
b = IsValidl(ds)
MessageBox("IsValid", string(b))

Examples

Example 1

These statements set lb_test to true:

integer a, b
boolean lb_test

SetNull(b)
lb_test = IsNull(a + b)

See also