Assigning Values to Variables - "=" Statement

This section provides a quick introduction of the assignment statement, which allows you to assign a new value to a variable.

Variables can be assigned with new values with the assignment statement in the following syntax:

   variable_name = data_value

where "data_value" a data literal or an expression. We will look at expressions in details in other parts of this book.

When assigning a new value to a variable:

Here is a tutorial example on how to declare variables and assign values to them:

<html>
<body>
<!-- assignment.html
 - Copyright (c) 2015, HerongYang.com, All Rights Reserved.
-->
<pre>
<script language="vbscript">
   Dim author
   Dim price
'   Dim empty
   
   author = "Herong"
   price = 9.99 
'   empty = 0
   
   buffer = price   ' Implicit declaration of "buffer"
   price = author
   author = buffer
   
   document.writeln("author = " & author)
   document.writeln("price = " & price)
   document.writeln("empty = " & empty)
</script>
</pre>
</body>
</html>

Here is the output of this VBScript example:

author = 9.99
price = Herong
empty = 

Notes about this VBScript example:

Table of Contents

 About This Book

 Introduction of VBScript - Visual Basic Scripting Edition

 Variant Data Type, Subtypes, and Literals

 Arithmetic Operations

 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

 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