Tuesday, May 17, 2016

Learn VB Script Part 2

Variables


What is a variable?


A variable is a convenient placeholder that refers to a computer memory location where you can store program information that may change during the time your script is running. 


Declaring a Variable

Declare variables explicitly in your script using the Dim statement, the Public statement, and the Private statement.

Examples:

Dim length
Dim height

Declare multiple variables by separating each variable name with a comma

Dim radius,area,side


Option Explicit 

We can also declare a variable implicitly by simply using its name in your script. That's not generally a good practice because you could misspell the variable name in one or more places, causing unexpected results when your script is run. For that reason, the Option Explicit statement is available to require explicit declaration of all variables. The Option Explicit statement should be the first statement in your script.




Rules for variable declaration


Variable names follow the standard rules for naming anything in VBScript.
A variable name:
  • Must begin with an alphabetic character.
  • Cannot contain an embedded period.
  • Must not exceed 255 characters.
  • Must be unique in the scope in which it is declared.


Assign values to variables

The variable is on the left side of the expression and the value you want to assign to the variable is on the right

Example

height = 10
length = 20







No comments:

Post a Comment