VBScript Interview Questions on Variables

VBScript Interview Questions on Variables, What a variable, how to declare variables in VBScript?, assign values to variables, and check data type.

VBScript Variables Questions

1) What is a 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
Ex:
Dim a
A= 100

b) Reading
Ex:
Dim num
Num=InputBox(“Enter a Value”)

4) How to 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 the 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 the 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
a=”VB@Script@Language”
Msgbox IsArray(b) ‘False
b=Split(a,”@”)
Msgbox IsArray(b) ‘True
msgbox b(1) ‘Script

a=”VB Script Language”
b=Split(a)
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 the case of general Arrays user can define values only, the Index system is defined, but if it is a Dictionary object user can define Index and values.

13) What is the ‘Option Explicit’ Statement?

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

14) What is the purpose of a 2-D Array?

Using a 2D Array we can store the data in Table format

Ex:
Dim a(4,5)
In 2D Array first value indicates Rows, the 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 an Empty Variable?


VBScript Tutorial for Beginners
VBScript Videos
Follow me on social media:

Leave a Comment