VBScript Tutorials - Herong's Tutorial Examples - Version 5.20, by Dr. Herong Yang

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:

  • The "writeln()" function of the "document" object is used to write text strings into the HTML document.
  • String concatenation operation, "&", is used to join strings together.
  • A special function, TypeName(), is used to show the subtype of the specified value.
  • The statement continuation character (_) is used to join multiple lines into a single statement.

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:

  • "7=7 : Integer" shows that small integer numbers are not recognized as Byte values.
  • "CByte(7)=7 : Byte" shows that CByte() returns a Byte value.
  • "777777=777777 : Long" shows that large integer numbers are recognized as Long values.
  • "9.99=9.99 : Double" shows that small real numbers are not recognized as Single values.
  • "CSng(9.99)=9.99 : Single" shows that CSng() returns a Single value.
  • "0.00314159e30=3.14159E+27 : Double" shows that real numbers are normalized into the standard floating-point format.
  • "CCur(9.99)=9.99 : Currency" shows that CCur() returns a Currency value.
  • "TRUE=True : Boolean" shows that keywords are not case sensitive. Key word "TRUE" is the same as "True".
  • "#31-Dec-1999#=12/31/1999 : Date" shows that more than one date formats are supported. Both dd-MMM-yyyy and mm/dd/yyyy are valid.
  • "Empty= : Empty" shows that the Empty value is converted into a blank string in a string concatenation operation.
  • "Null= : Null" shows that the Null value is converted into a blank string in a string concatenation operation.

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

 Printable Copy - PDF Version

Data Literal Examples - Updated in 2015, by Dr. Herong Yang