VBScript Interview Questions and Answers

by Nithyanandham, on Sep 10, 2022 4:36:11 PM

Interview Questions (42)

Q1. What is VBScript?

Ans: Microsoft VBScript (Visual Basic Script) is a general-purpose, lightweight and active scripting language developed by Microsoft that is modelled on Visual Basic. Nowadays, VBScript is the primary scripting language for Quick Test Professional (QTP), which is a test automation tool.

Q2. What are the environments supported by VBScript language?

Ans: There are 3 Environments where VBScript can run:

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

Q3. How Do I Implement VBScript?

Ans: You use VB Script in exactly the same manner as you would JavaScript. Simply place all code between these tags like so:
<SCRIPT LANGUAGE=”VBScript”>
</SCRIPT>

Q4. What is the extension of the VBScript file?

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

Q5. What are the advantages of VBScript?

Ans: Following are the advantages of VBScript −
i. VBScript is a lightweight scripting language, which has a lightning fast interpreter.
ii. VBScript, for the most part, is case insensitive. It has a very simple syntax, easy to learn and to implement.
iii. Unlike C++ or Java, VBScript is an object-based scripting language and NOT an Object-Oriented Programming language.
iv. It uses Component Object Model (COM) in order to access the elements of the environment in which it is executing.
v. Successful execution of VBScript can happen only if it is executed in Host Environment such as Internet Explorer (IE), Internet Information Services (IIS) and Windows Scripting Host (WSH).

 Q6. What are the Data Types supported by VBScript?

Ans: VBScript has only one data type called a Variant. There are different categories of information that can be contained in a Variant, called subtypes. These subtypes are:
Empty, Null, Boolean, Byte, Integer, Long Single, Double, Date/Time, Currency , String , Object and Error.

Q7. How are Comments handled in the VBScript language?

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

Q8. What are keywords in the VBScript language?

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

Q9. What are the variable naming conventions in VBScript?

Ans: Variable is a named memory location used to hold a value that can be changed during the script execution. VBScript has only ONE fundamental data type, Variant.
Rules for Declaring Variables:-
Variable Name must begin with an alphabet.
Variable names cannot exceed 255 characters.
Variables Should NOT contain a period(.)
Variable Names should be unique in the declared context.

Q10. What is Dictionary object in VBScript? Explain.

Ans: The Dictionary object stores name / value pairs (referred to as the key and item respectively) in an array.
Write the below code in a notepad and save it with a .vbs extension and run it from Command Prompt by just typing the name of the file.
Dim Beers
Set Beers = CreateObject("Scripting.Dictionary")
Beers.Add "a", "Strauss"
Beers.Add "b", "Kingfisher"
Beers.Add "c", "Budweiser"
Msgbox ("The value corresponding to the key 'b' is " & Beers.Item("b"))
The Dictionary object has many properties like Count, Item, CompareMode etc and many methods like Exists, Add, and Keys etc.

Q11. What are the 2 ways in which a variable can be declared in the VBScript language?

Ans: 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 weird results while running and at times, it will not even be easy to detect this by the user.
Explicit Declaration: Declaring the variables before using them is known as Explicit Declaration of variables.

Q12. Which command is used for writing text on a page?

Ans: Document.Write (text)

Q13. What's the difference between VBScript and VB.NET?

Ans: VBScript is script - a text-based code that gets interpreted by a "host", like the Windows Script Host or IE. VB.Net is a semi-compiled language for writing java-like software.

Q14. Why is the use of Exit Do or Exit For statements within loops discouraged? 

Ans: These statements are acceptable for specific conditions, but they often make code less readable, which makes it difficult for others who look at your code to know what's really going on. If you make sure the only way out of a loop is to not satisfy the loop's condition, it's much easier to follow your code. Often, breaking out of a loop by force with an exit statement is a sign of a poorly constructed loop with a condition that does not meet your goals. Take a look at the loop structure and condition again to make sure you're not leaving something out.

Q15. Compare Java Script and VB Script?

Ans: VB and Java Script are much similar in functionality. They both interact with the document object model of the page. Many browsers have compatibility with Java Script but they are not compatible with VB script as such. For client side scripting developers using VB Script should always make sure of cross browser compatibility which is not the case when working with VB script.

Q16. What is the scope of a variable declared using Dim?

Ans: Variables declared using “Dim” keyword at a Procedure level are available only within the same procedure. Variables declared using “Dim” Keyword at script level are available to all the procedures within the same script.

Q17. What is the scope of a variable declared using Public?

Ans: Variables declared using “Public” Keyword are available to all the procedures across all the associated scripts. When declaring a variable of type “public”, Dim keyword is replaced by “Public”.

Q18. How many types of Operators are available in the VBScript language? 

Ans: There are 4 types of Operators which are supported by the VBScript language. They are:

  1. Arithmetic Operators
  2. Comparison Operators
  3. Logical Operators
  4. Concatenation Operators

Q19. How are values assigned to the variables in the VBScript language?

Ans: Values are assigned with the help of Equal (=) Operator. 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.

Q20. What are the differences between Sub Procedures and Function Procedures?

Ans: 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.

Q21. Explain about the functionality of VB Script?

Ans: Active X technology can be used to give much more functionality to VB Script. VB provides sub routines, functions, string manipulation, data/time, error handling, etc. VB can have more functionality added to it by working with languages such as ASP.
VBScript is an interpreter language, code written in VBScript is executed line by line.

Q22. Explain about .wsf files?

Ans: .wsf files are modeled in similar to XML. They can be executed with the help of Wscript.exe and it can be done from the command line also. This .wsf file can have multiple visual basic files. Reuse functionality is present with this extension file.

Q23. How to Assign values to a variable ?

Ans: Simple you have to declare a variable name and assign any value.
For ex. Name=john
Status=False
Age=30
Now all the above variables has been assigned values.This is a simple way to declare and assign related values to a variable.

Q24. List out few date functions in VBScript.

Ans: Date(),
Time(),
Now(),
Left(),
Right(),
Mid()

Q25. What are the disadvantages of VBScript?

Ans: Following are the disadvantages of VBScript −
1. VBscript is used only by IE Browsers. Other browsers such as Chrome, Firefox DONOT Support VBScript. Hence, JavaScript is preferred over VBScript.
2. VBScript has a Limited command line support.
3. Since there is no development environment available by default, debugging is difficult.

Q26. Is VBScript a case-sensitive or case-insensitive?

Ans: VBScript is a case-insensitive programming language; i.e. case is ignored when reading VBScript scripts. So myVar, MyVar, MYvar all refer to the same variable.

Topics:Interview Questions with Answers

Comments

Subscribe