YouTube Icon

Interview Questions.

Top 50 Vb Script Interview Questions - Jul 28, 2022

fluid

Top 50 Vb Script Interview Questions

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

The numeric values need to be assigned without double costs.

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

Drive includes techniques and homes that will let you accumulate facts approximately a drive attached to the device.

Q3. How To Capture A Runtime Error In Vbscript?

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

Q4. How Can You Create An Object In Vbscript?

We need to claim the object and instantiate it the use of Set Keyword.

Example:

Dim obj  

Set obj = CreateObject("Scripting.Dictionary")

Q5. How To Throw An Error In Vbscript?

Use Err.Raise to throw an errors.

Example:

Err.Raise 6   ' Raise an overflow error.

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

The Public constants are to be had for all of the scripts and techniques.

Q7. How Do You Declare A Variable In Vbscript?

Variables are declared the use of "dim" key-word.

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

If ByRef is special, then the arguments are sent as with the aid of reference whilst the feature or manner is referred to as.

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

Using IsArray characteristic, which returns a boolean price that shows whether or not or now 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 required 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 distinctive number of substrings in an array. This is an specific contrary feature of Split Method.

Q12. What Are The Properties Of Regexp Object?

Following are the houses of RegExp object:

Pattern: The Pattern technique represents a string that is used to outline the ordinary expression and it ought to be set before the usage of the ordinary expression object.

IgnoreCase: A Boolean assets that represents if the ordinary expression have to be examined against all possible fits in a string if actual or false. If now not distinct explicitly, IgnoreCase fee is about to False.

Global: A Boolean assets that represents if the everyday expression have to be examined against all viable suits in a string. If no longer detailed explicitly, Global value is ready to False.

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

Using FormatPercent characteristic, which might return an expression formatted as a percentage.

Example:

Dim num : num = -645.998651

file.Write(FormatPercent(num, 2))& "<br/>"    '-sixty four,599.86%

Q14. What Are The Disadvantages Of Vbscript?

Following are the risks of VBScript:

VBscript is used most effective by using IE Browsers. Other browsers along with Chrome, Firefox DONOT Support VBScript. Hence, JavaScript is preferred over VBScript.

VBScript has a Limited command line help.

Since there is no development environment to be had by default, debugging is hard.

Q15. What Are Class Variables?

Classes can incorporate variables, which can be of personal or public. Variables within training should comply with VBScript naming conventions. By default, the variables in class are Public. That is why they can be accessed out of doors the elegance.

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 special man or woman the required quantity of instances.

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  Values as Variable Values are Numeric. So A + B will provide 15.

Q19. How Strcomp Function Works?

The StrComp Function returns an integer price after evaluating the two given strings. It can return any of the 3 values -1, 0 or 1 primarily based on the input strings to be in comparison.

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 zero and 1.

Example:

Dim num : num = -645.998651

record.Write("Rnd Result of num is : " & Rnd(num))& "<br/>" 'zero.5130115

Q21. What Are Subprocedures In Vbscript?

Sub Procedures are much like features but there are few variations.

Sub approaches DONOT Return a fee even as capabilities might also or won't return a value.

Sub processes Can be known as with out call key-word.

Sub methods are usually enclosed within Sub and End Sub statements.

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

Using CLng feature, which converts a given variety of any variant subtype to Long.

Example:

x = 123

y = 123.882

document.Write("x price after changing to Long -" & CLng(x) & "<br />")

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

This magnificence presents file gadget gadgets which help the developers to paintings with drives, folders and files.

Example:

Dim oFS, force

Set oFS = CreateObject("Scripting.FileSystemObject")

Set power = oFS.GetDrive(oFS.GetDriveName("C:"))

Document.Write power.VolumeName

Q24. How To Declare An Array In Vbscript?

Arrays are declared the same way a variable has been declared besides that the assertion of an array variable makes use of parenthesis. In the underneath example, the dimensions of the array is stated inside the brackets.

Example:

'Method 1 : Using Dim

Dim arr1() 'Without Size

'Method 2 : Mentioning the Size

Dim arr2(five)  'Declared with size of 5

'Method three : the use of '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 reminiscence for the array variables.

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

Using Filter characteristic, returns a 0 based totally array that incorporates a subset of a string array based totally on a selected clear out criteria.

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

<> operator is used to check if  numbers are identical or now not.

Example:

Dim a : a = five

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 not unusual way to define a function in VBScript is by means of the use of the Function key-word, followed by a completely unique characteristic call and it can or won't carry a list of parameters and a announcement with a End Function keyword, which shows the give up of the function.

Q30. What Are Class Properties?

Class residences, which includes Property Let, which handles the system of facts validation and assigning the new cost to the personal variable. Property set, which assigns the brand new property fee to the private object variable.

Read-only properties have only a Property Get process at the same time as write-simplest homes (which are uncommon) have handiest 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 characteristic, 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 fit the pattern of strings and the homes and strategies help us to paintings with Regular Expressions without problems.

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 1 string inside some other string. The seek takes place from right to left.

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

Using Log characteristic, which returns the herbal logarithm of the given wide variety.

Example:

Dim num : num = 210

report.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 supply 510.

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

Using Exp characteristic, which returns the fee of e raised to the specified quantity.

Example:

Dim num : num = -645.998651

report.Write("Exp Result of num is : " & Exp(num))& "<br/>" '2.79479883633128E-281

Q37. How Will You Compare Two Strings In Vbscript?

Using StrComp feature, which returns an integer cost after evaluating the 2 exact 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 provide VBScript.

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

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

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

Using Ltrim characteristic, which returns a string after casting off the areas on the left side of the required string.

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

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

Q42. What Are The Advantages Of Vbscript?

Following are the blessings of VBScript:

VBScript is a lightweight scripting language, which has a lightning speedy interpreter.

VBScript, for the most element, is case insensitive. It has a very simple syntax, easy to analyze and to put in force.

Unlike C++ or Java, VBScript is an object-primarily based scripting language and NOT an Object-Oriented Programming language.

It makes use of Component Object Model (COM) so one can access the factors of the environment in which it's far executing.

Successful execution of VBScript can appear handiest if it is completed in Host Environment inclusive of Internet Explorer (IE), Internet Information Services (IIS) and Windows Scripting Host (WSH).

Q43. What Are Class Events?

There are two events that are routinely associated with every elegance by using default. Class_Initialize and Class_Terminate.

Class_Initialize is induced each time you instantiate an item primarily based on the elegance. Class_Terminate occasion is fired whilst the item goes out of scope or when the item is set to Nothing.

Example:

In the beneath example, we will make you understand how the occasions work in VBScript.

'Instantation of the Object

Set objectname = New classname 

   

Private Sub Class_Initialize(  )

 Initalization code goes right here

End Sub

'When Object is Set to Nothing

Private Sub Class_Terminate(  )

 Termination code is going right here

End Sub

Q44. How To Delete A Cookie Using Vbscript?

Sometimes you may want to delete a cookie so that subsequent attempts to study the cookie return nothing. To try this, you simply 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 need to be enclosed within hash image(#).

Q46. How Can You Destroy An Object In Vbscript?

In order to destroy the items, we want to use Set Keyword observed by the object call 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 characteristic, which returns the higher case of the required string.

Q48. How Regexp.Execute Method Works?

The Execute technique works like Replace, except that it returns a Matches collection item, containing a Match item for each successful healthy. It does not regulate the authentic string.

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

Using Oct function, which returns the octal cost of the given range.

Example:

Dim num : num = -645.998651

report.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 = five

Dim b : b = 10

Dim c

c = b XOR a

Document.Write ("XOR Check is " &c)




CFG