Friday, 18 August 2017

Variable Declaration in VB Script

In Vb Script we have two types of declarations

  1. Implicit
  2. Explicit
  • Implicit: In this variables are used without declaration.
  • Explicit: In Explicit variables are declared first before using it. In Explicit ,if variables are not declared first then error will be thrown.In explicit declaration we use “Option Explicit “in the first line of  the script.
In large programs it is good practice to use explicit declaration,as it will prevent duplication of variables. 

Declaring Variables:

  • Declaring variables is same as creating variables because you are instructing the computer to reserve memory space.
  • We can name the variable the way you want. 
  • It can be any name  as your wish . 
  • Providing clear and meaningful names to variables is considered as a good programming practice. 
  • We can declare variables in vb script using Dim,public,private statements.
  • We can declare multiple variables by separating each variable name with a comma
Ex : Dim name ;
public name
private name

Assigning Values to the Variables

Values are assigned similar to an algebraic expression. The variable name on the left hand side followed by an equal to (=) symbol and then its value on the right hand side.

Rules:

·         The numeric values should be declared without double quotes. Ex: a=10
·         The String values should be enclosed within doublequotes(") Ex: name="vbscript"

·         Date and Time variables should be enclosed within hash symbol(#) Ex: date=#08/22/2017#  time=#01.11.33 PM#

There will be different scope for variables declared using dim,public,private.That we will discuss further.

No comments:

Post a Comment