IsBlank function

The IsBlank function below will return True if the variable or value passed to it is Empty or NULL or Zero.
It will return False if the variable contains any string or a value other than '0'.

Examples

Wscript.echo "testing 0..."
boolReturn = IsBlank(0)
if boolReturn = true then wscript.echo "It's Blank" else wscript.echo "not blank"

Wscript.echo "testing 123..."
boolReturn = IsBlank(123)
if boolReturn = true then wscript.echo "It's Blank" else wscript.echo "not blank"

Wscript.echo "testing 100-100..."
boolReturn = IsBlank(100-100)
if boolReturn = true then wscript.echo "It's Blank" else wscript.echo "not blank"

Wscript.echo "testing null..."
boolReturn = IsBlank(null)
if boolReturn = true then wscript.echo "It's Blank" else wscript.echo "not blank"

Wscript.echo "testing empty string..."
boolReturn = IsBlank("")
if boolReturn = true then wscript.echo "It's Blank" else wscript.echo "not blank"

Wscript.echo "testing string..."
boolReturn = IsBlank("The quick brown fox")
if boolReturn = true then wscript.echo "It's Blank" else wscript.echo "not blank"

Function IsBlank(Value)
'returns True if Empty or NULL or Zero
If IsEmpty(Value) or IsNull(Value) Then
 IsBlank = True
 Exit Function
ElseIf VarType(Value) = vbString Then
 If Value = "" Then
  IsBlank = True
  Exit Function
 End If
ElseIf IsObject(Value) Then
 If Value Is Nothing Then
  IsBlank = True
  Exit Function
 End If
ElseIf IsNumeric(Value) Then
 If Value = 0 Then
  wscript.echo " Zero value found"
  IsBlank = True
  Exit Function
 End If
Else
 IsBlank = False
End If
End Function

Arguably the numeric value '0' is as valid a value as any other number. The logic behind flagging this as blank is that you may have data like strSurname = 0 which most likely should be treated as being blank.

All vbscript variables are variants. A Variant is a special kind of data type that can contain different kinds of information, depending on how it is used.

“Let him that would move the world, first move himself” - Socrates

Related:

IsNull(expression) - Is expression NULL? True/False
IsNumeric(expression) - Is expression a Numeric? True/False
ArrayConvert (Microsoft Sample code) - Variant Conversion Functions



Back to the Top

© Copyright SS64.com 1999-2012
Some rights reserved