IsNull PowerScript function
Description
Reports whether the value of a variable or expression is null.
Syntax
|
1 |
<span>IsNull</span> ( <span>any</span> <span></span>) |
|
Argument |
Description |
|---|---|
|
any |
A variable or expression that you want |
Return Values
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:
|
1 |
dataStore ds<br>boolean b<br> <br>b = IsNull(ds)<br>MessageBox("IsNull", string(b)) |
If the variable is explicitly set to null, IsNull returns true in
both standard and .NET applications:
|
1 |
SetNull(ds)<br>b = IsNull(ds)<br>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:
|
1 |
dataStore ds<br>boolean b<br> <br>b = IsValid(ds)<br>MessageBox("IsValid", string(b))<br> <br>SetNull(ds)<br>b = IsValidl(ds)<br>MessageBox("IsValid", string(b)) |
Examples
These statements set lb_test to true:
|
1 |
integer a, b<br>boolean lb_test<br> <br>SetNull(b)<br>lb_test = <span>IsNull</span>(a + b) |