Name
IsNull Function
Syntax
IsNull(expression)expressionUse: Required
Data Type: Any
An expression containing string or numeric data.
Return Value
Boolean (True or False).
Description
Determines whether expression
contains is Null.
Rules at a Glance
If the expression passed to IsNull is
Null,Trueis returned; otherwise, IsNull returnsFalse.All variables in
expressionare checked for null values. If a null value is found in any one part of the expression,Trueis returned for the entire expression.In VBScript, Null is a separate data type that can take on a single value,
Null. It is used to indicate that data is missing. Because it represents missing data, all expressions that include aNullvalue also result in aNullvalue. This makes perfect sense. For instance, if we have an array containing two valid months of sales data and aNullrepresenting the third month’s sales data, the quarter’s sales data should also beNull, since accurate data for the quarter is not available.
Programming Tips and Gotchas
IsNull is useful when returning data from a database. You should check field values in columns that allow Nulls against IsNull before assigning the value to a collection or other variable. This stops the common “Invalid Use of Null” error from occurring.
IsNull is the only way to evaluate an expression containing a null. For example, the seemingly correct statement:
If varMyVar = Null Then
always evaluates to
False, even ifvarMyVaris null. This occurs because the value of an expression containing ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access