Top 50 Vb Script Interview Questions You Must Prepare 08.Dec.2023

The numeric values should be assigned without double quotes.

Drive contains methods and properties that allow you to gather information about a drive attached to the system.

If we want to capture the error, then Err Object is used.

we need to declare the object and instantiate it using Set Keyword.


Dim obj  
Set obj = CreateObject("Scripting.Dictionary")

Use Err.Raise to throw an error.


Err.Raise 6   ' Raise an overflow error.

The Public constants are available for all the scripts and procedures.

Variables are declared using "dim" keyword.

If ByRef is specified, then the arguments are sent as by reference when the function or procedure is called.

Using IsArray function, which returns a boolean value that indicates whether or not the input variable is an array.

Using Lcase function, which returns the lower case of the specified string.

Using Join function, which returns a String that contains a specified number of substrings in an array. This is an exact opposite function of Split Method.

Following are the properties of RegExp object:

Pattern: The Pattern method represents a string that is used to define the regular expression and it should be set before using the regular expression object.

IgnoreCase: A Boolean property that represents if the regular expression should be tested against all possible matches in a string if true or false. If not specified explicitly, IgnoreCase value is set to False.

Global: A Boolean property that represents if the regular expression should be tested against all possible matches in a string. If not specified explicitly, Global value is set to False.

Using FormatPercent function, which would return an expression formatted as a percent.


Dim num : num = -645.998651
document.write(FormatPercent(num, 2))& "<br/>"    '-64,599.86%

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.

Classes can contain variables, which can be of private or public. Variables within classes should follow VBScript naming conventions. By default, the variables in class are Public. That is why they can be accessed outside the class.


Dim var1 , var2.
Private var1 , var2.
Public var1 , var2.

Using String function, which returns a String with a specified character the specified number of times.

Using StrReverse function, whihc returns a String after reversing the sequece of the characters of the given string.

+ operator adds two Values as Variable Values are Numeric. So A + B will give 15.

The StrComp Function returns an integer value after comparing the two given strings. It can return any of the three values -1, 0 or 1 based on the input strings to be compared.

  • If String 1 < String 2 then StrComp returns -1
  • If String 1 = String 2 then StrComp returns 0
  • If String 1 > String 2 then StrComp returns 1

Using Rnd function,which returns a random number between 0 and 1.


Dim num : num = -645.998651
document.write("Rnd Result of num is : " & Rnd(num))& "<br/>" '0.5130115

  • Sub Procedures are similar to functions but there are few differences.
  • Sub procedures DONOT Return a value while functions may or may not return a value.
  • Sub procedures Can be called without call keyword.
  • Sub procedures are always enclosed within Sub and End Sub statements.

Using CLng function, which converts a given number of any variant subtype to Long.


x = 123
y = 123.882
document.write("x value after converting to Long -" & CLng(x) & "<br />")

This class provides file system objects which help the developers to work with drives, folders and files.


Dim oFS, drive
Set oFS = CreateObject("Scripting.FileSystemObject")
Set drive = oFS.GetDrive(oFS.GetDriveName("C:"))
Document.write drive.VolumeName

arrays are declared the same way a variable has been declared except that the declaration of an array variable uses parenthesis. In the below example, the size of the array is mentioned in the brackets.


'Method 1 : Using Dim
Dim arr1() 'Without Size
'Method 2 : Mentioning the Size
Dim arr2(5)  'Declared with size of 5
'Method 3 : using 'Array' Parameter
Dim arr3
arr3 = Array("apple","Orange","Grapes")

Following are the scopes of variable in VBScript:

  • Dim
  • Public
  • Private

Using Erase Function, which recovers the allocated memory for the array variables.

Using Filter function, returns a zero based array that contains a subset of a string array based on a specific filter criteria.

<> operator is used to check if two numbers are equal or not.


Dim a : a = 5
Dim b : b = 10
Dim c
c = b <> a
Document.write ("Equality Check is " &c)

The most common way to define a function in VBScript is by using the Function keyword, followed by a unique function name and it may or may not carry a list of parameters and a statement with a End Function keyword, which indicates the end of the function.

Class properties, such as Property Let, which handles the process of data validation and assigning the new value to the private variable. Property set, which assigns the new property value to the private object variable.

Read-only properties have only a Property Get procedure while write-only properties (which are rare) have only a Property Let or a Property Set procedure.


Class Comp
   Private modStrType
   Private OS
   Public Property Let ComputerType(strType)
      modStrType = strType
   End Property
   Public Property Get ComputerType()
      ComputerType = modStrType
   End Property
   Public Property Set OperatingSystem(oObj)
      Set OS = oObj
   End Property
   Public Property Get OperatingSystem()
      Set OperatingSystem = OS
   End Property
End Class

Using LBound function, which returns an integer that corresponds to the smallest subscript of the given arrays.

RegExp object helps the developers to match the pattern of strings and the properties and methods help us to work with Regular Expressions easily.

Using InStrRev function, which returns the first occurrence of one string within another string. The search happens from right to left.

Using Log function, which returns the natural logarithm of the given number.


Dim num : num = 210
document.write("Log Result of num2 is : " & Log(num2))& "<br/>" '5.34710753071747

& operator concatenates two values. So A + B will give 510.

Using Exp function, which returns the value of e raised to the specified number.


Dim num : num = -645.998651
document.write("Exp Result of num is : " & Exp(num))& "<br/>" '2.79479883633128E-281

Using StrComp function, which returns an integer value after comparing the two specified strings.

+ operator concatenates two Values if values are string. So A + B will give VBScript.

Using Ltrim function, which returns a string after removing the spaces on the left side of the specified string.

Using UBound function, which returns an integer that corresponds to the largest subscript of the given arrays.

Following are the advantages of VBScript:

  1. VBScript is a lightweight scripting language, which has a lightning fast interpreter.
  2. VBScript, for the most part, is case insensitive. It has a very simple syntax, easy to learn and to implement.
  3. Unlike C++ or Java, VBScript is an object-based scripting language and NOT an Object-Oriented Programming language.
  4. It uses Component Object Model (COM) in order to access the elements of the environment in which it is executing.
  5. 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).

There are two events that are automatically associated with every class by default. Class_Initialize and Class_Terminate.

Class_Initialize is triggered whenever you instantiate an object based on the class. Class_Terminate event is fired when the object goes out of scope or when the object is set to Nothing.


In the below example, we will make you understand how the events work in VBScript.

'Instantation of the Object
Set objectname = New classname 
Private Sub Class_Initialize(  )
 Initalization code goes here
End Sub
'When Object is Set to Nothing
Private Sub Class_Terminate(  )
 Termination code goes here
End Sub

Sometimes you will want to delete a cookie so that subsequent attempts to read the cookie return nothing. To do this, you just need to set the expiration date to a time in the past.

Date and Time variables should be enclosed within hash symbol(#).

In order to destroy the objects, we need to use Set Keyword followed by the object name and point it to Nothing.


Dim obj  
Set obj = CreateObject("Scripting.Dictionary")
Set obj = Nothing

Using Ucase function, which returns the upper case of the specified string.

The Execute method works like Replace, except that it returns a Matches collection object, containing a Match object for each successful match. It doesn't modify the original string.

Using Oct function, which returns the octal value of the given number.


Dim num : num = -645.998651
document.write("Oct Result of num is : " & Oct(num))& "<br/>" '37777776572

XOR Called Logical Exclusion operator. It is used to do an XOR operation.


A. Dim a : a = 5
Dim b : b = 10
Dim c
c = b XOR a
Document.write ("XOR Check is " &c)