VBScript Tutorials - Herong's Tutorial Examples - v6.02, by Herong Yang
Empty - The Default Value of a Variable
This section provides a tutorial example on how to find out the default value, Empty, of a variable before its first assignment.
What is the default, or initial, value of a variable after the declaration and before the first assignment? The answer is: Empty.
There are 3 ways to check if a variable has the Empty value:
Here is a tutorial example on how to check the default value of a variable:
<html> <body> <!-- default_value.html - Copyright (c) 1998 HerongYang.com. All Rights Reserved. --> <pre> <script language="vbscript"> ' Variable, author, is explicitly declared Dim author document.writeln() document.writeln("author = " & author) document.writeln("IsEmpty(author) = " & IsEmpty(author)) document.writeln("(VarType(author)=vbEmpty) = " _ & (VarType(author)=vbEmpty)) document.writeln("TypeName(author) = " & TypeName(author)) ' Variable, buffer, is implicitly declared document.writeln() document.writeln("buffer = " & buffer) document.writeln("IsEmpty(buffer) = " & IsEmpty(buffer)) document.writeln("(VarType(buffer)=vbEmpty) = " _ & (VarType(buffer)=vbEmpty)) document.writeln("TypeName(buffer) = " & TypeName(buffer)) </script> </pre> </body> </html>
Here is the output of this VBScript example:
author = IsEmpty(author) = True (VarType(author)=vbEmpty) = True TypeName(author) = Empty buffer = IsEmpty(buffer) = True (VarType(buffer)=vbEmpty) = True TypeName(buffer) = Empty
The output confirms that the initial value, or the default value, of a variable is Empty, regardless of how it is declared.
Table of Contents
Introduction of VBScript - Visual Basic Scripting Edition
Variant Data Type, Subtypes, and Literals
Numeric Comparison Operations and Logical Operations
String Operations - Concatenation and Comparison
►Variable Declaration and Assignment Statement
Variable Declaration and "Dim" Statement
Assigning Values to Variables - "=" Statement
►Empty - The Default Value of a Variable
Expression and Order of Operation Precedence
Statement Syntax and Statement Types
Array Data Type and Related Statements
Array References and Array Assignment Statements
Conditional Statements - "If ... Then" and "Select Case"
Loop Statements - "For", "While", and "Do"
"Function" and "Sub" Procedures
Inspecting Variables Received in Procedures
Error Handling Flag and the "Err" Object
Regular Expression Pattern Match and Replacement
scrrun.dll - Scripting Runtime DLL Library
IE Web Browser Supporting VBScript
IIS ASP Server Supporting VBScript