Top 50 Vb Script Interview Questions You Must Prepare 23.Jul.2024

Q1. How To Assign A Numeric Value To A Variable?

The numeric values should be assigned without double quotes.

Q2. What Is The Purpose Of Drive Object Of Scripting.filesystemobject Class In Vbscript?

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

Q3. How To Capture A Runtime Error In Vbscript?

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

Q4. How Can You Create An Object In Vbscript?

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

Example:

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

Q5. How To Throw An Error In Vbscript?

Use Err.Raise to throw an error.

Example:

Err.Raise 6   ' Raise an overflow error.

Q6. What Is The Scope Of A Constant Declared Using Public?

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

Q7. How Do You Declare A Variable In Vbscript?

Variables are declared using "dim" keyword.

Q8. How To Pass Argument By Reference To A Function In Vbscript?

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

Q9. How Will You Check That A Variable Is An Array In Vbscript?

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

Q10. How Will You Convert A String To Lower Case String Using Vbscript?

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

Q11. How Will You Get A Combined String From Array Of String In Vbscript?

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.

Q12. What Are The Properties Of Regexp Object?

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.

Q13. How Will You Format A Number In Percetage Format In Vbscript?

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

Example:

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

Q14. What Are The Disadvantages Of Vbscript?

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.

Q15. What Are Class Variables?

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.

Example:

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

Q16. How Will You Get A String With The Specified Character The Specified Number Of Times In Vbscript?

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

Q17. How Will You Reverse A String In Vbscript?

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

Q18. What Is The Output Of A + B In Vbscript If A = 5 And B = 10?

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

Q19. How Strcomp Function Works?

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

Q20. How Will You Get A Random Number Between 0 And 1 In Vbscript?

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

Example:

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

Q21. What Are Subprocedures In Vbscript?

  • 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.

Q22. How Will You Convert A Given Number To Long In Vbscript?

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

Example:

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

Q23. What Is Purpose Of Scripting.filesystemobject Class In Vbscript?

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

Example:

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

Q24. How To Declare An Array In Vbscript?

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.

Example:

'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")

Q25. What Are The Valid Scopes Of A Variable In Vbscript?

Following are the scopes of variable in VBScript:

  • Dim
  • Public
  • Private

Q26. How Will You Release The Memory Acquired By An Array Variable In Vbscript?

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

Q27. How Will You Get A Subset Of A Array In Vbscript?

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

Q28. Which Opearator Can Be Used To Check If Two Numbers Are Equal Or Not In Vbscript?

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

Example:

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

Q29. How To Create A Function In Vbscript?

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.

Q30. What Are Class Properties?

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.

Example:

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

Q31. How Will You Get The Smallest Subscript Of An Array In Vbscript?

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

Q32. What Is The Purpose Of Regexp Object In Vbscript?

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

Q33. How Will You Get The Last Occurrence Of One String Within Another String Using Vbscript?

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

Q34. How Will You Get The Natural Logarithm Of The Given Number In Vbscript?

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

Example:

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

Q35. What Is The Output Of A & B In Vbscript If A = 5 And B = 10?

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

Q36. How Will You Get The Exponent Of The Given Number In Vbscript?

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

Example:

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

Q37. How Will You Compare Two Strings In Vbscript?

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

Q38. What Is The Output Of A + B In Vbscript If A = "vb" And B = "script"?

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

Q39. What Is The Purpose Of Folders Object Of Scripting.filesystemobject Class In Vbscript?

Folders provides a list of all the folders within a Folder.

Q40. How Will You Trim The Spaces On The Left Of A String Using Vbscript?

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

Q41. How Will You Get The Largest Subscript Of An Array In Vbscript?

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

Q42. What Are The Advantages Of Vbscript?

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).

Q43. What Are Class Events?

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.

Example:

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

Q44. How To Delete A Cookie Using Vbscript?

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.

Q45. How To Assign A Date Value To A Variable?

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

Q46. How Can You Destroy An Object In Vbscript?

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

Example:

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

Q47. How Will You Convert A String To Upper Case String Using Vbscript?

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

Q48. How Regexp.execute Method Works?

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.

Q49. How Will You Get The Octal Value Of The Given Number In Vbscript?

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

Example:

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

Q50. Which Opearator Can Be Used To Do An Xor Operation In Vbscript?

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

Example:

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