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

Data Types and Literals

Part:   1  2  

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...)

To show you some examples of data literals, I wrote the following script, data_literal.html:

<html>
<body>
<!-- data_literal.html
   Copyright (c) 2006 by Dr. Herong Yang. http://www.herongyang.com/
-->
<pre>
<script language="vbscript">
   document.writeln(777)
   document.writeln(777777)
   document.writeln(0.00314159e30)
   document.writeln(333.333e200)
   document.writeln(999999.5555)
   document.writeln("Hello")
   document.writeln(TRUE)
   document.writeln(#31-Dec-1999#)
   document.writeln("No literals for variant data type.")
</script>
</pre>
</body>
</html>

If you open this script in IE, you will get:

777
777777
3.14159E+27
3.33333E+202
999999.5555
Hello
True
12/31/1999
No literals for variant data type.

Couple of interesting notes here:

  • The "writeln" procedure of the "document" object is used to write text into the HTML document.
  • Line 3 shows that VB normalized my value into the standard single-precision floating point format.
  • Line 4 shows that VB normalized my value into the standard double-precision floating point format.
  • Line 7 shows that VB keywords are not case sensitive. Key word TRUE is the same as True.
  • Line 8 shows that VB recognize more than one date format. Both dd-MMM-yyyy and mm/dd/yyyy are valid.

More on String Literals

String literals have one additional rule:

  • If a double quote (") is part of a string literal, the double quote needs to be prefixed with another double quote.

I have the following script, string_literal.html, to show you how to include double quotes in string literals:

<html>
<body>
<!-- string_literal.html
   Copyright (c) 2006 by Dr. Herong Yang. http://www.herongyang.com/
-->
<pre>
<script language="vbscript">
   document.writeln("Ding...")
   document.writeln("He said: ""Hello?""")
   document.writeln("She said: ""Hello, Who's calling?""")
</script>
</pre>
</body>
</html>

Here is the output:

Ding...
He said: "Hello?"
She said: "Hello, Who's calling?"

Conclusions

  • 9 basic data types supported in VB.
  • String literals are enclosed in (").
  • ("") represents (") in string literals.
  • Date literals are enclosed in (#).

Part:   1  2  

Dr. Herong Yang, updated in 2006
VBScript Tutorials - Herong's Tutorial Notes - Data Types and Literals