VBScript Variables

VBScript Variables Questions

1) What is Variable?

Variable is a named memory location to store data

2) Where variables store, in Primary Memory (RAM) or in Secondary Memory (HDD /CD-Rom etc..)?

Variables store in Primary Memory (RAM)

3) How to assign values to variables

In two ways we can assign values to variables
a) Initialization
    Dim a
    A= 100
b) Reading
    Dim num
    Num=InputBox(“Enter a Value”)

4) How declare variables

We can declare Variables using Either Public or Private or Dim Statements

5) What is the difference between Implicit and explicit declaration of variables?

Declaring Variables before using is called Explicit declaration of Variables

Directly using variables Without declaration is called Implicit  declaration of Variables

6) What are the types of variables available in QTP?
There are 2 types of variables available in VBScript
a) Scalar Variables
b) Array Variables

7) Explain about scope of variables in VBScript?
Variables have 2 types of scope
    a) Script Level variables
    b) Procedure Level variables

8) What is Dynamic Array?
Who is size undefined, changes through the execution

9) How re-size dynamic arrays in VBScript?
Using ReDim statement we can resize dynamic arrays

10) How to assign series of values at a time into variables?
In 2 ways we can assign series of values
    i) Using Array Function

Dim a
Msgbox IsArray(a) 'False
a=Array("India", 100, 100.45, #10/10/2010#)
Msgbox IsArray(a) 'True
msgbox a(1) '100

ii) Using Split Function

Dim a, b
Msgbox IsArray(b) 'False
Msgbox IsArray(b) 'True
msgbox b(1) 'Script

a="VB Script Language"
msgbox b(0) 'VB

11) What is Dictionary Object?
It is used to define Key, Value Pairs.

12) What is the difference between general Array and Dictionary object?
In case of general Arrays user can define values only, Index system defined, but if it Dictionary object user can define Index and values.

13) What is Option Explicit Statement?

It forces declaration of variables in the Script, so that we can avoid misspell problems.

14) What is the purpose of 2-D Array?
Using 2D Array we can store the data in Table format

Dim a(4,5)
In 2D Array first value indicates Rows, second value indicates Columns.

15) What is the difference between Variables and constants in VBScript?

Variables Values may vary throughout the Script, but Constants never change

16) What are the naming restrictions to declare Variables in VBScript?
a) Should start with Alfa bytes

Dim abc

b) Should not use embedded periods

Dim abc
Dim ab c 'Incorrect
Dim ab.c 'Incorrect
Dim ab*c 'Incorrect
Dim ab-c 'Incorrect
Dim ab_c

c) Must not exceed 255 characters in legnth

d) Should be unique in the scope of declaration

Dim a, b, c
Dim d, e
Dim f, g, A 'Error

Reserved words

Dim Wait
Wait = 40
Msgbox Wait 'Not a standard

17) What is the lifetime of VBScript Variables?

18) What is Empty Variable?


Post a Comment