Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q7009 How Do I Declare Variables?

You are here: irt.org | FAQ | VBScript | Q7009 [ previous next ]

You may declare variables implicitly, meaning that you don't need to declare variables prior to their use and can just type something like: myVar = 9. However, this is very bad practice that can result in a number of inexplicable errors. To explicitly declare a variable use either the Dim, Public, or Private statements. Providing better security, all variables are of the Visual Basic Variant datatype, meaning that the variable can contain a wide array of datatypes. To define a variable named myVar and assign it a value of 10 go:

Dim myVar
myVar = 10

Note that you may not go:
Dim myVar = 10

To avoid implicit variables from occuring accidentally you may use the Option Explicit statement as your first line of code in your script. This means that all variables must be explicitly declared using either the Dim, Public, or Private statements. An error will be generated by any implicit variables come across.

©2018 Martin Webb