www.pickatutorial.com Computer Tutorials
Top eBooks: C/C++ | C# | Android | Mathematics | Database | Cloud | Graphics | Networking | Oracle | Hardware | AI
Top Tutorials: C/C++ | C#.NET | PHP MySQL | Java | Java Script | jQuery | HTML | xHTML | HTML5 | VB Script| CSS
Lessons VBScript Variables Bookmark and Share
Tutorial Home
Lesson 1
Lesson 2
Lesson 3
Lesson 4
Lesson 5
Lesson 6
Lesson 7
Lesson 8
Lesson 9
Lesson 10
Lesson 11
Lesson 12
Lesson 13
Lesson 14
Variables are named memory locations where we store our values that we use in our programs. A variable is a fundamental part of any programming language. The purpose of a variable is to hold some value.

Once we store or assign some value to a variable, we can, then, use or reference the same in our subsequent code.

Declareing a variable in VBScript is very simple. We use the Dim keyword to declare a variable in VBScript. The following example declares a variable named price:

<script type="text/vbscript">
Dim age
</script>

We can also declare multiple variable on a single line, seperating their names with a comma. Here is an example:

<script type="text/vbscript">
Dim age, age2, age3
</script>

Assign Values to Variables in VBScript
After declaring a variable, we need to assign it a value to make it useful. We assign values to variables in VBScript by using an equals operator (=). We write the variable name on the left followed by the equals operator and finally the value on the right.

Here is an example:

<script type="text/vbscript">
Dim age
age = 25
document.write(age)
</script>

The above example declares a variable named age, assigns it a value and then outputs the same. When we run the above code it generates the following output:


25

In VBScript, we have several operators available to manipulate our variables. For example we can add two variables, multiply them and divide them, etc.

The following table lists the common arithmetic operators available in VBScript:

Operator Description
+ Addition
- Subtraction
* Multiplication
/ Division
\ Integer Division (divides two numbers and returns an integer result)
Mod Modulus (divides two numbers and returns the remainder)
^ Exponentiation (raises the number to the power of an exponent)

Here is an example:

<script type="text/vbscript">
Dim a
Dim b
a = 4
b = 5
addition = a + b
'addition has the value 9

substract = b - a
'substract has the value 1

multiply = a * b
'multiply has the value 20
divide = b / a
'divide has the value 1.25

intDivision = b\a
'intDivision has the value 1

remainder = b mod a
'remainder has the value 1

raise = b ^ a
'raise now has the value 625

</script>

Next >>> Lesson No. 5: VBScript Data Types




Home - Advertise - Contact - Disclaimer - About Us
© Since 2006 pickatutorial.com -- All Rights Reserved.