VBScript Tutorials - Herong's Tutorial Notes
Dr. Herong Yang, Version 4.01

Variable Inspection and Numeric Conversion

Part:   1  2   3 

VB Script Tutorials - Herong's Tutorial Notes © Dr. Herong Yang

Data Types and Literals

Variables

Logic Operations

String Operations

Conditional Statements

Arrays

Loop Statements

Functions and Subroutines

Built-in Functions

Variable Inspection

... Table of Contents

(Continued from previous part...)

   document.writeln(" ")
   document.writeln("Checking arrays:")
   Dim aFixed(5)
   document.writeln("A1 " & GetVarInfo(aFixed) & " (Fixed)")
   aFixed(5) = 555
   document.writeln("A2 " & GetVarInfo(aFixed) & " (Fixed/Val.)")

   Dim aDynamic()
   document.writeln("A3 " & GetVarInfo(aDynamic) & " (Dyn.)")
   ReDim aDynamic(3)
   document.writeln("A4 " & GetVarInfo(aDynamic) & " (Dyn./Set)")
   aDynamic(3) = "Dog"
   document.writeln("A5 " & GetVarInfo(aDynamic) & " (Dyn./Set/Val.)")

   document.writeln(" ")
   document.writeln("Checking emptiness:")
   vNull = Null
   document.writeln("E1 " & GetVarInfo(vNull) & " (Null)")
   vEmpty = Empty
   document.writeln("E2 " & GetVarInfo(vEmpty) & " (Empty)")

   document.writeln(" ")
   document.writeln("Checking objects:")
   document.writeln("O1 " & GetVarInfo(Document) & " (Document)")

Function GetVarInfo(vAnyThing)
   If IsObject(vAnyThing) Then
      sObject = "Obj=Y"
   Else
      sObject = "Obj=N"
   End If

   If IsArray(vAnyThing) Then
      sArray = "Array=Y"
   Else
      sArray = "Array=N"
   End If

   If IsDate(vAnyThing) Then
      sDate = "Date=Y"
   Else
      sDate = "Date=N"
   End If

   If IsNumeric(vAnyThing) Then
      sNumeric = "Num=Y"
   Else
      sNumeric = "Num=N"
   End If

   If IsNull(vAnyThing) Then
      sNull = "Null=Y"
   Else
      sNull = "Null=N"
   End If

   If IsEmpty(vAnyThing) Then
      sEmpty = "Empty=Y"
   Else
      sEmpty = "Empty=N"
   End If

   sType = TypeName(vAnyThing)
   GetVarInfo = sObject & " " & sArray & " " & sDate _
      & " " & sNumeric & " " & sNull & " " & sEmpty & " " & sType
End Function
</script>
</pre>
</body>
</html>

Here is the output:

 
Checking variants with value:
V1 Obj=N Array=N Date=N Num=Y Null=N Empty=N Integer (777)
V2 Obj=N Array=N Date=N Num=Y Null=N Empty=N Long (777777)
V3 Obj=N Array=N Date=N Num=Y Null=N Empty=N Double (3.14)
V4 Obj=N Array=N Date=N Num=Y Null=N Empty=N Double (3.3e200)
V5 Obj=N Array=N Date=N Num=N Null=N Empty=N String ("Hello")
V6 Obj=N Array=N Date=N Num=Y Null=N Empty=N Boolean (TRUE)
V7 Obj=N Array=N Date=Y Num=N Null=N Empty=N Date (#31-Dec-1999#)
 
Checking strings with value:
S1 Obj=N Array=N Date=N Num=Y Null=N Empty=N String ("777")
S2 Obj=N Array=N Date=Y Num=Y Null=N Empty=N String ("3.14")
S3 Obj=N Array=N Date=N Num=N Null=N Empty=N String ("True")
S4 Obj=N Array=N Date=N Num=N Null=N Empty=N String ("#31-Dec-1999#")
 
Checking arrays:
A1 Obj=N Array=Y Date=N Num=N Null=N Empty=N Variant() (Fixed)
A2 Obj=N Array=Y Date=N Num=N Null=N Empty=N Variant() (Fixed/Val.)
A3 Obj=N Array=Y Date=N Num=N Null=N Empty=N Variant() (Dyn.)
A4 Obj=N Array=Y Date=N Num=N Null=N Empty=N Variant() (Dyn./Set)
A5 Obj=N Array=Y Date=N Num=N Null=N Empty=N Variant() (Dyn./Set/Val.)
 
Checking emptiness:
E1 Obj=N Array=N Date=N Num=N Null=Y Empty=N Null (Null)
E2 Obj=N Array=N Date=N Num=Y Null=N Empty=Y Empty (Empty)
 
Checking objects:
O1 Obj=Y Array=N Date=N Num=N Null=N Empty=N HTMLDocument (Document)

(Continued on next part...)

Part:   1  2   3 

Dr. Herong Yang, updated in 2006
VBScript Tutorials - Herong's Tutorial Notes - Variable Inspection and Numeric Conversion