Data Literal Examples

This section provides a tutorial example on how to write data literals for different subtypes of Integer, Long, Double, String, Boolean, Date, Empty and Null.

Now let's write a simple VBScript code inside a HTML document to run in the host environment provided by Internet Explorer.

Run a text editor and enter the following file, data_literal.html:

<html>
<body>
<!-- data_literal.html
 - Copyright (c) 2015, HerongYang.com, All Rights Reserved.
-->
<pre>
<script language="vbscript">
   document.writeln("7=" & (7) & " : " & TypeName(7))
   document.writeln("CByte(7)=" & (CByte(7)) & " : " _ 
      & TypeName(CByte(7)))
   document.writeln("777=" & (777) & " : " & TypeName(777))
   document.writeln("777777=" & (777777) & " : " & TypeName(777777))
   document.writeln("9.99=" & (9.99) & " : " & TypeName(9.99))
   document.writeln("CSng(9.99)=" & (CSng(9.99)) & " : " _ 
      & TypeName(CSng(9.99)))
   document.writeln("0.00314159e30=" & (0.00314159e30) & " : " _ 
      & TypeName(0.00314159e30))
   document.writeln("333.333e200=" & (333.333e200) & " : " _ 
      & TypeName(333.333e200))
   document.writeln("CCur(9.99)=" & (CCur(9.99)) & " : " _ 
      & TypeName(CCur(9.99)))
   document.writeln("""Hello""=" & ("Hello") & " : " _ 
      & TypeName("Hello"))
   document.writeln("TRUE=" & (TRUE) & " : " & TypeName(TRUE))
   document.writeln("#31-Dec-1999#=" & (#31-Dec-1999#) & " : " _ 
      & TypeName(#31-Dec-1999#))
   document.writeln("Empty=" & (Empty) & " : " & TypeName(Empty))
   document.writeln("Null=" & (Null) & " : " & TypeName(Null))
</script>
</pre>
</body>
</html>

Several notes about this VBScript example:

If you open this VBScript example in IE, you will get:

7=7 : Integer
CByte(7)=7 : Byte
777=777 : Integer
777777=777777 : Long
9.99=9.99 : Double
CSng(9.99)=9.99 : Single
0.00314159e30=3.14159E+27 : Double
333.333e200=3.33333E+202 : Double
CCur(9.99)=9.99 : Currency
"Hello"=Hello : String
TRUE=True : Boolean
#31-Dec-1999#=12/31/1999 : Date
Empty= : Empty
Null= : Null

The output conforms our understanding of data literal rules described in the previous section:

Table of Contents

 About This Book

 Introduction of VBScript - Visual Basic Scripting Edition

Variant Data Type, Subtypes, and Literals

 "Variant" - Data Type and Subtypes

 Data Literals

Data Literal Examples

 String Data Literals

 Date and Time Data Literals

 Arithmetic Operations

 Numeric Comparison Operations and Logical Operations

 String Operations - Concatenation and Comparison

 Variable Declaration and Assignment Statement

 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

 Built-in Functions

 Inspecting Variables Received in Procedures

 Error Handling Flag and the "Err" Object

 Regular Expression Pattern Match and Replacement

 scrrun.dll - Scripting Runtime DLL Library

 Creating Your Own Classes

 IE Web Browser Supporting VBScript

 IIS ASP Server Supporting VBScript

 WSH (Windows Script Host)

 References

 PDF Printing Version