Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q7009 How Do I Declare Variables?

irt.org | Knowledge Base | VBScript | Q7009 [ previous next ]

Q7009 How Do I Declare Variables?

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.


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 6th July 2009. Maintained by: Martin Webb
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2009 irt.org, All Rights Reserved.