Monday, 21 August 2017

Scope Of Variables

Variables can be declared using the following statements which determines the scope of the variables.The scope of the variables plays vital role when they are used with classes,procedures.

Scope of variables

  • DIM
  • PUBLIC
  • PRIVATE

DIM:

Variables declared using “Dim” keyword at procedure level are available within same procedures,in the same way variables declared in using dim keyword at class level are available to all procedures within same script.

Eg: dim var1

PUBLIC:

  •  Variables declared using public keyword are available to all the procedures across all the associated scripts.
  • Variable type Public is declared by using keyword public in place of dim keyword.
Eg: public var2

PRIVATE:

  • Variables declared using public keyword are have the scope within that script in which they are declared.
  • Variable type private is declared by using keyword private in place of dim keyword.

Eg: private var3

Examples for these scope of variables will be discussed in further posts.

Life Time of Variables:


  • The lifetime of a variable depends on how long it exists. 
  • The lifetime of a script-level variable extends from the time it is declared until the time the script is finished running. 
  • At procedure level, a variable exists only as long as you are in the procedure. 


Click to know about Operators in Vb Script 

No comments:

Post a Comment