60+ Top VBScript Interview Questions and Answers [2024 LIST]

By Vijay

By Vijay

I'm Vijay, and I've been working on this blog for the past 20+ years! I’ve been in the IT industry for more than 20 years now. I completed my graduation in B.E. Computer Science from a reputed Pune university and then started my career in…

Learn about our editorial policies.
Updated March 7, 2024

List of Most Frequently Asked VBScript testing Interview Questions with detailed Answers to Help You in Interview Preparation: 

In the previous tutorial, we have discussed ‘Error Handling’ which was the last topic of the series of VBScript tutorial.

In order to sum up, in this tutorial, we will cover VBScript interview questions to make you familiar with the type of questions that can be asked during a job interview.

A set of most popular and commonly asked VBScript questions are included in this tutorial for your easy reference. This tutorial would be a guide for anyone who wishes to clear the interview quickly.

Click for complete VBScript series here.

VBScript Interview Questions

In my personal experience, there is no specific way or formula to get through an interview process and it totally depends on you and the type of Interviewer but still, it’s good to be prepared on your profile for your own confidence and knowledge, so that you don’t feel hesitant to answer the questions asked during an Interview.

VBScript Interview Questions And Answers

Following is the list of basic but most important interview questions in VBScript that can be asked in an Interview:

Q #1) What is VBScript language used for and which earlier language is it modeled upon?

Answer: VBScript is a lightweight primary scripting language which is used for automation of the Scripts in QTP (Quick Test Professional) tool. This is modeled upon Visual Basic language.

Q #2) What are the environments supported by VBScript language?

Answer: VBScript can run in the following 3 environments:

  • IIS (Internet Information Server) This is Microsoft’s Web Server.
  • WSH (Windows Script Host) – This is the hosting environment of the Windows Operating System.
  • IE (Internet Explorer) – This is the most frequently used environment to run scripts and this is the simple hosting environment.

Q #3) Which data type/types are supported by VBScript language and what are their specialties?

Answer: There is only one data type that is supported by VBScript language and it is called as the ‘Variant’. If we use this data type in the String context then this will behave like a String and if we use this in Numeric context then this will behave like a Number. This is the specialty of the Variant data type.

Q #4) What is the extension of the VBScript file?

Answer: VBScript file is saved with an extension of .vbs.

Q #5) How are Comments handled in the VBScript language?

Answer: Any Statement that starts with a single quote (‘) or with the keyword ‘REM’ is treated as a Comment.

Q #6) Which respective symbols are used to separate a line and to break the lengthy statement into multiple statements in the VBScript language?

Answer: Colons (:) act as a line separator and Underscore (_) is used to break the lengthy statement into multiple statements in the VBScript language.

Q #7) What are the keywords in the VBScript language?

Answer: There are some words that work as Reserved Words and they cannot be used as Variables names, Constant names or any other Identifier names, these are known as keywords. Some of the keywords in the VBScript language are Not, Nothing, Preserve, Optional, etc.

Q #8) Is VBScript language a Case-Sensitive language and what does it mean?

Answer: No. This actually means that variable names, keywords, constants, and other identifiers are not required to be typed with a consistent capitalization of letters i.e. if you type ‘Optional’ keyword as OPTIONAL, optional or Optional then these all mean the same in the VBScript language.

Q #9) What are the naming conventions while declaring a variable in the VBScript language?

Answer: Following are the rules for declaring a Variable name:

  • It must always start with a letter. For Example, output, name, etc. Variable Name should not start with a number or any special character like _va123, 12non, etc.
  • It cannot exceed the limit of 255 characters.
  • It should never contain a period (.).

Q #10) Which keyword is used to declare a variable in the VBScript language?

Answer: The Dim keyword is used to declare a variable in the VBScript language. However, depending upon the scope of the variable, public or private keywords can also be used.

Q #11) What are the 2 ways in which a variable can be declared in the VBScript language?

Answer: Two ways to declare a variable are:

  • Implicit Declaration: When variables are used directly without declaration, it is termed as Implicit Declaration. However, it’s not a good practice because at any point if the variable name is not spelled correctly in the script then it can produce wrong results while running and at times, it will not even be easy to be detected by the user.
  • Explicit Declaration: Declaring the variables before using them is known as the Explicit Declaration of variables.

Q #12) What is the use of Option Explicit Statement?

Answer: This provides a mechanism where the user has to declare all the variables using Dim, Public or Private Statements before using them in the Script.

If the user tries to use the variables which are not declared in case of Option Explicit then an error occurs. It is always recommended to use ‘Option Explicit’ at the top of the code so that even if you use the wrong name of the variable unintentionally, you can then correct it immediately without any confusion.

Q #13) How are values assigned to the variables in the VBScript language?

Answer: Values are assigned with the help of Equal (=) Operator. The name of the variable comes on the left and the value which is assigned to the variable is on the right-hand side of the ‘=’ Operator.

Q #14) How are values assigned to String type and Numeric type variables?

Answer: If the variable to which value is to be assigned is of String type then it can be assigned using double quotes (“ ”) and if the variable to which value is to be assigned is of the Numeric type then it can be assigned without using double-quotes.

Q #15) Explain the scope of the variables using Dim, Public, and Private keywords respectively.

Answer: If the variable is declared using Dim keyword inside the function then its scope will be limited to the function level only i.e. this variable cannot be accessed once the function ends.

If the variable is declared using a Private keyword inside the function then its scope will not be limited till function level only but it can be accessed everywhere in that particular script.

If the variable is declared using Public keyword inside the function then its scope will not be limited till function level alone, but it can be accessed everywhere in that particular script and also in the other scripts.

Q #16) How can constants be declared in the VBScript language?

Answer: Constants are named memory locations within a program that never change their values during the execution of the script. ‘Const’ keyword is used to declare Constants in the VBScript language.

Q #17) Which constant is used for print and display functions and works as same as pressing Enter key?

Answer: vbCrLf is used for print and display functions representing a carriage return with line feed character having values as Chr(13) & Chr(10). This works in the same manner as in the case of pressing an Enter key. This is a pre-defined constant of the VBScript language.

Q #18) How many types of Operators are available in the VBScript language?

Answer: There are 4 types of Operators that are supported by the VBScript language.

They are:

  • Arithmetic Operators
  • Comparison Operators
  • Logical Operators
  • Concatenation Operators

Q #19) Which Operator is used for fetching the modulus of the 2 numbers in the VBScript language?

Answer: MOD Operator is used for fetching the modulus of the 2 numbers in the VBScript language.

Q #20) Which Operator is used to perform the comparison among 2 operands in the VBScript language?

Answer: ‘==’ Equal Operator is used for performing the comparison among 2 operands in the VBScript language i.e. if we check 1 == 2 then it will give False.

Q #21) Which Operator is used to concatenate the 2 values in the VBScript language?

Answer: ‘&’ operator is used to concatenate the 2 values in the VBScript language.

Q #22) If we take 2 strings as “Good” and “Bad” then what will ‘+’ and ‘&’ operators return?

Answer: ‘&’ and ‘+’ both work as a Concatenation Operator in case of the String values. Hence these both will return the same result as GoodBad.

Q #23) Which Operator can be used to change the value of the operand or change the state of the condition?

Answer: ‘NOT’ Operator is used as a logical operator and can be used to change the value of the operand or change the state of the condition i.e. if the condition is True then this will change it to False and vice versa.

Q #24) Out of the different types of Operators, which are evaluated first and last in the VBScript language?

Answer: ‘Arithmetic’ Operators are evaluated first and ‘Logical’ Operators are evaluated at last in the VBScript language.

Q #25) Which conditional statement is the most convenient one to use in the case of multiple conditions in the VBScript language?

Answer: ‘Select Case’ is the most convenient one to use in case of multiple conditions in the VBScript language as in case of SELECT Statement, you can directly move to the exact case without wasting time to go into each condition one by one.

Q #26) What are the different types of loops available in the VBScript language?

Answer: The loops which are available in the VBScript language are broadly categorized into 3 types and they are – For Loops, Do Loops and While Loops.

Q #27) Which loop is used in the case of arrays in the VBScript language?

Answer: For Each Loop is used in the case of Arrays. This is an extension of For Loop only. In case of repeating the code for each index value of an array then you can use ‘For Each Loop’.

Q #28) What is the difference between For Loop and While Loop?

Answer: This is a very important Interview Question which is asked multiple times.

For Loop is used when we exactly know the number of times loop (i.e. for i = start to end) has to be executed unlike in case of While Loop.

In ‘For Loop’ in the VBScript, the counter is incremented automatically if not mention step keyword by 1 when loops go to the next keyword whereas in ‘While Loop’, the counter condition has to be mentioned explicitly inside the brackets.

Q #29) What is the difference between Do Until Loop and Do While Loop?

Answer: Do While Loop first checks the condition and if it is true only after that the statements are executed and in case of Do Until, the loop will be executed until the condition becomes false.

Q #30) How many types of Procedures are available in the VBScript language?

Answer: There are 2 types of Procedures in the VBScript language – Sub Procedures and Function Procedures.

Sub is a type of procedure that includes a set of statements inside the block of the code and after execution, it does not return any value.

The Function is a type of procedure that includes a set of statements inside the block of the code and after execution, it may return value also. This can take input if required, depending on the situation.

Q #31) What are the differences between Sub Procedures and Function Procedures?

Answer: Differences are as follows:

  • Sub Procedure never takes an input while the Function Procedure may take an input if required.
  • Sub Procedure starts and ends with using Sub and End Sub respectively while Function Procedure starts and ends with Function and End Function respectively.
  • The most important difference is Sub Procedure never returns a value while Function Procedure may return a value.

Q #32) What are the 2 ways to pass a value to the Function?

Answer: The 2 ways to pass a value to the function are:

  • Pass by Value: When arguments are passed and any changes that take place in the Called procedure in the value of a variable does not persist then it means it is passing by value. The keyword used in this case is ByVal.
  • Pass by Reference: When arguments are passed and any changes that take place in the Called procedure in the value of a variable persist then it means it is passing by reference. The keyword used in this case is ByRef.

Q #33) Which In-Built function is used to format the number in the VBScript language?

Answer: FormatNumber Conversion function is used to convert the specified expression in the form of a Number.

Q #34) Which In-Built functions are used to convert the specified expression in the form of Date and String in the VBScript language?

Answer: cDate is one of the frequently used conversion functions for converting the expression which includes Date or Time parameter into Date subtype.

cStr is the conversion function which is used for converting the expression into the String subtype.

Q #35) How are Arrays declared in the VBScript language?

Answer: Declaration of Array can be done in the same manner in which variables are declared but with a difference that array variable is declared by using parenthesis ‘()’.

The Dim keyword is used to declare an Array.

Ways to declare an Array: There are 3 ways in which an Array can be declared.

They are as follows:

Way 1: Dim array1()

Here, array1 is the name of an array and since parenthesis is empty it means that the size of an array is not defined here.

If you want to declare an array by mentioning its size then it can be done in the following way.

Way 2: Dim array1(5)

Here, array1 is declared with the size as 5 which states it holds 6 values considering the index of an array always starts from 0. These 5 values can be of integer type, string or character types.

Way 3: array1 = Array(1,2,3,4,5,6)

Here, Array Function is used to declare an array with a list of the arguments inside the parenthesis and all integer values are passed directly inside the parenthesis without any need of mentioning the size of an array.

Note: Index value of an Array can never be a negative value.

Q #36) What are lbound and ubound in the VBScript language?

Answer: lbound indicates the smallest subscript or index of an Array in the  VBScript language and this always returns 0, as the index value of an Array always starts from 0.

ubound returns the largest subscript of a defined array or can say it indicates the size of an Array. If the size of an array is 5 then the value of the ubound is 5.

Q #37) Which In-Built function related to an Array joins substrings into one string in the VBScript language?

Answer: Join function combines multiple substrings into a String. Here, the string returned value includes various substrings in an array and thus joins all the substrings into one string.

Syntax: Join(array,[delimiter]. Using delimiter is an optional condition.

Q #38) How many types of Arrays are available in the VBScript language?

Answer: There are basically 2 types of Arrays that are used in the VBScript:

  • Single Dimensional Array: This is a simple type of array which is used more often in the scripts.
  • Multi-Dimensional Array: When an Array is having more than 1 dimension then it is known as a multi-dimensional array. Normally, a 2-dimensional array is the one which is used most of the times i.e. there will be rows and columns in an array. The maximum dimension of an array can reach to 60

Q #39) When are REDIM statement and PRESERVE keyword used in the VBScript language?

Answer: This is a very important Interview Question that has been asked many times.

REDIM statement is used to re-define the size of an array. When the array is declared without any size, an array can be declared again using REDIM with the feasibility of specifying the size of an array.

PRESERVE keyword is used to preserve the contents of a current array when the size of an array gets changed.

Let’s understand the usage of these keywords with the help of a simple example:

<html>
<head>
<title>Let’s see implementation of Redim and Preserve</title>
</head>
<body>
<script language=”vbscript” type=”text/vbscript”>
Dim array1()
REDIM array1(3)
array1(0) = “hello” 
array1(1) = 12 
array1(2) = 13
array1(3) = “how are you”
REDIM PRESERVE array1(5)
array1(4) = 15
array1(5) = 16
For i = 0 to ubound(array1)
Msgbox “Value present at index ” & i & ” is “ & array1(i) & “<br />”
Next
</script>
</body>
</html>

Q #40) What is the use of the Date function in the VBScript language?

Answer: Date function displays the current system Date and Time in the VBScript language.

Q #41) Which Date function is used in the VBScript language to find the difference between the 2 dates?

Answer: DateDiff function is used to fetch the difference between the 2 dates that are specified as parameters on the basis of the interval specified.

Q #42) What is the use of the FormatDateTime function in the VBScript language?

Answer: This is a format function which is used to convert the Date to some specific format based on the parameters that are supplied to the function. The syntax of this is FormatDateTime(Date, Format). This is a widely used format function.

Q #43) Which function is used in the VBScript language to convert the specified expression into a Date type value?

Answer: cDate is used to convert a valid expression into a Date type value. The syntax of this is cDate(date) i.e. any valid Date/Time expression will be converted into a particular Date.

Q #44) What is the use of the Instr function?

Answer: This is used to find the position value of the substring at its first occurrence inside the main string.

This function requires 2 strings to be specified to perform this search operation and the search operation starts from the first character.

Syntax: is InStr(name of string1, the name of string2).

If the name of string1 or string2 is null or “ ” then this function will return null and 0 respectively. This return >=1 values when the string is found and 0 in the case when the string is not found.

Q #45) How to get the length of the string by making use of the String function?

Answer: Len function is used to get the length of a specified string i.e. the total number of characters of a specified String.

Syntax: Len(name of the string).

Q #46) Which function is used to perform string comparison?

Answer: StrComp is used to compare the 2 strings and return values on the basis of the comparison. This returns 0 if string1 = string2,-1 if string1<string2,1 if string1>string2 and null if any of the strings is null.

Syntax: StrComp(name of the string1, name of the string2).

Q #47) How can the spaces from the string be removed?

Answer: Trim function is used to trim/remove the spaces from both the sides of the specified String.

Syntax: Trim(name of the string).

Q #48) How can you fetch the value of a Cookie?

Answer: document.cookie stores the information of key-value pairs and expiration date values of a Cookie.

document.cookie = “key1=name of the value1;key2=name of the value2,…….,expires=date”.

‘;’ is used to separate the key-value pairs.

Q #49) What are Events in the VBScript language?

Answer: Events are the Actions that occur when any activity is performed like any mouse click, pressing the keys, mouse hover, etc. With the help of writing a piece of code in the programming languages like VBScript, these events can be captured and actions can be performed as per your requirements by making the best use of the Event Handling mechanism.

Q #50) Which Event is triggered when mouse focus comes out of an element in the VBScript language?

Answer: MouseOut Event is triggered when mouse focus comes out of an element in the VBScript language.

Q #51) When does ‘On Click of Button’ event gets triggered in the VBScript language?

Answer: This Event occurs in case of the clicking of any button that is present on any HTML page.

Q #52) Which object is used to work with the excel sheets in the VBScript language and what statement is used to create this object?

Answer: Excel Objects provide supports to the coders to work and deal with the Excel Sheets.

Set obj = createobject(“Excel.Application”) is the way to create an Excel Object.

Q #53) Which object is used to work with the database in the VBScript language and what statement is used to create this object?

Answer: Connection Objects provide supports to the Coders to work and deal with the database. As such, there is not any straight-forward mechanism to connect to the database in QTP but by making use of ADODB Objects, you can interact with the database and work with the SQL Queries to fetch the data from the database.

ADO stands for ActiveX Data Objects and this provides a mechanism to act as an intermediary between the QTP and the Database.

Set obj = createobject(“ADODB.Connection”)  is the way to create a Connection Object.

Q #54) What is the use of the ‘Open’ method to work with the database in the VBScript language and what connection string is passed in the same and what is its usage?

Answer: This is used to open a database connection object/recordset object.

obj.Open“Provider=SQLQLEDB;Server=.\SQLEXPRESS;UserId=test;Password=P@123;Database =AUTODB” is the connection string for opening a database connection.

The connection string is a very useful property and this is used for creating a database connection and includes connection information like details of the Driver, Database Server Name, Username, and Password.

Q #55) Why is it recommended to close the database connection every time after the work is completed?

Answer: This is a very important Interview Question which has been asked many times.

It is recommended to close the resource after its usage is completed although it’s not mandatory as library or driver ultimately will close the connection but this is required to avoid any negative effects due to improper closing of the connections which can even lead to a restriction in the access of the database by some of the users.

Q #56) What is the use of the RecordSet object and which statement is used to create such an object?

Answer: The RecordSet object is used for holding the records of the query which are extracted from the database.

Set obj = createobject(“ADODB.RecordSet”) is the statement for creating a RecordSet object.

Q #57) How can you create a file object to work with the files in the VBScript language?

Answer: Set obj = createobject(“Scripting.FileSystemObject”) is the statement for creating a File object.

Q #58) What methods are used to create text files and open text files in the VBScript language?

Answer: CreateTextFile and OpenTextFile methods are used to create open text files and open text files respectively in the VBScript language.

Q #59) What is the purpose of the Err object in the VBScript language?

Answer: This is basically used to capture the details about the Error i.e. if you want to know about the Error Number, description and other details then you can do so by accessing the properties of this Object.

Q #60) Why is Error handling required?

Answer: You can take measures to get minimum number of errors as possible by making use of Error Handling Mechanism in your scripts. Situations like issues in mathematical computations or any type of error can be handled with the help of Error Handling.

Q #61) What purpose does ‘On Error Resume Next’ serves?

Answer: On Error Resume Next moves the control of the cursor to the next line of the error statement i.e. if any runtime error occurs at any particular line in the script then the control will move into the next line of the statement where the error has occurred.

Conclusion

This is all about VBScript interview questions. I hope this tutorial must have provided you a great insight regarding the questions that can be asked during an Interview and you can now confidently handle your interview process.

This has brought me to the end of the VBScript learning tutorial series and I hope you must have now gained enough knowledge of the VBScript language. Do practice all the topics for better understanding and knowledge.

Happy Reading!! Happy Testing!!

Let us know if we have missed out some important question in the above list, also feel free to share your queries.

Was this helpful?

Thanks for your feedback!

Leave a Comment