Top 50 Vbscript Advanced Interview Questions You Must Prepare 07.Jul.2022

If we declare variables with some values and while using if we use (spell mistake) then user can’t know

  ‘ putting option explicit is useful there  ‘ Example starts here  option explicit  dim abcd  abcd=20  msgbox abcd  dim bcde  bcde=30  msgbox bcdef

Arrays in VB Script should be assigned within the variant separated by a comma. If arguments are not specified then the string is regarded as empty. After specifying the elements in an array an index number should be used indicating the desired element.

SGA (System Global Area) is a dynamic memory area of an Oracle Server. In SGA,the allocation is done in granuels. The size of the SGA is dependent on SGA_MAX_SIZE parameter.

The memory structures contained by SGA are:

Shared Pool :

this memory structure is divided into two sub-structures which are Library Cache and Data Dictionary Cache for storing recently used PL/SQL statements and the recent data definitions. The maximum size of the Shared Pool depends on the SHARED_POOL_SIZE parameter.

Database Buffer Cache :

This memory structure improves the performance while fetching or updating the recently used data as it stores the recently used datafiles. The size of this block is decided by DB_BLOCK_SIZE.

Redo Log Buffer :

This memory structure is used to store all the changes made to the database and it's primarily used for the data recovery purposes. The size of this block is decided by LOG_BUFFER.

Java Pool :

This memory structure is used when Java is installed on the Oracle server. Size that can be used is stored in parameter named JAVA_POOL_SIZE.

Large Pool :

This memory structure is used to reduce the burden of the Shared Pool, as the Session memory for the Shared Server, as the temporary storage for the I/O and for the backup and restore operations or RMAN. Parameter that stores the maximum size is LARGE_POOL_SIZE.

  function add(a,b)  sum=a+b  add=sum  end function  s=add(6,8)  msgbox s  sub add2(x,y)  sum=x+y  msgbox sum  end sub  call add2(6,8)

.hta extension is used whenever you want to include a VB script in HTML. Here HTML acts as an interface and VB Script as the programming language. .hta extension files do run in the safe and trusted zone of Internet explorer. Although they run in the trusted zone querying is restricted as it has to pass the guidelines of internet explorer.

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.

In operator precedence expressions are evaluated and resolved in a predetermined order. The order of evaluation can be modulated if you use parenthesis. Expressions present in parenthesis are evaluated first.

Use of dim ,private and public variables in vb script function first

dim a
a=20
msgbox a ‘ 20 displays
end function
first
msgbox a ‘ this gives empty value
‘ so dim variables are not public if we use within function
dim b
b=30
function second
msgbox b ‘ 30 displays
end function
second
‘ if we declare dim variables outside the function then it will act as public
class myclas
public c
private d
dim e
sub mysub
c=40
d=50
e=60
msgbox “public:“&c&” private :”&d&”dim :”&e
end sub
end class
set obj=new myclas
obj.mysub
msgbox obj.c
‘msgbox obj.d ‘it won’t allow to display private
variables
msgbox obj.e

A simple example detailing the running of VB Script is by utilizing Windows Script host environment. Visual basic is a stand alone application which has a .vbs as extension. Input can be provided through graphical user interface and output can be obtained by Wscript.exe from dialog and input boxes. From command line it can be invoked by Cscript.exe.

There are many useful constants present in Visual basic script which you can use in your code. They ease your work load by remembering value and implementing in the code. Maintenance is easy with VB Script because it can easily change the feature of constants.

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

Option Explicit

  Sub feet_to_inch()  Dim Inches, Feet  Feet=inputbox("Enter feet value ")  Inches = Feet * 12  MsgBox "There are " & Inches & " inches in " & Feet & " feet."  End Sub   Call feet_to_inch()

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.

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

  set xl=createobject(“excel.application”)  set wb=xl.workbooks.open(“d:/sample.xls”)  set ws=wb.worksheets(1)  ws.cells(3,4)=”welcome”  wb.save  wb.close  set wb=nothing  set ws=nothing  set xl=nothing

The actions that are performed by clicking, pressing keys, moving mouse, dragging and dropping etc are called as events. Event handling is the way to capture these events and perform the actions accordingly.

This is a scripting language developed by Microsoft and is based loosely on Visual Basic. Its functionality in a web environment is defendant upon either an ASP engine or the Windows Scripting Host, and must be used on a Windows hosting platform.

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.

ADODB.Stream class can be used as string builder. VBScript string concatenation can be very costly because of frequent memory allocation features. Binary file and memory I/O operation is provided by ADODB.Stream class. This is widely used to convert bytes into string, etc.

The On Error Resume Next statement provides you some degree of error handling by preventing program interruptions from runtime errors.

When an error occurs, by using this statement, the line of code containing the error is simply skipped over and the program continues.

On Error Resume Next statement does not correct an error, just ignore it, without even displaying the error message.

The Statement essentially has two ways it is used. First to turn off the script engine error checking:

On Error Resume Next

The second is to turn it on, thereby allowing the script engine to stop execution of a script when an error is encountered. Like so:

On Error Goto 0

How to read from file and write into the file

  set files = createobject(“scripting.filesystemobject”)  set obj1=files.opentextfile(“d:file2.txt”,2,true)  ‘ true uses for ceating txt file  set obj2=files.opentextfile(“d:file2.txt”,1,false)  ‘ false will not create any file  obj1.writeline(“write this line into file”)  str=obj2.readline  msgbox str  set files=nothing

Tristate constants can be used with functions which allow formatting of numbers. These constants can be used with VB Script without defining them. It can be used anywhere in the code to reflect and represent the values.

If functionality aspect is considered VB Script acts similar to Java Script but it is compatible only on internet explorer. They interact with Document object model. Visual basic script can also be used for server side processing with ASP.

  Asc() - Returns ANSI Character Code  Chr() - Returns Character from ANSI Code  InStr() - Find a string within another  InStrRev() - Find a string within another (Reverse)  LCase() - Convert a string to lowercase  Left() - Crops a string from left  Len() - Determine the length of a string  LTrim() - Remove leading spaces from a string  Mid() - Crops a string  Replace() - Replace a substring within a string  Right() - Crops a string from right  RTrim() - Remove trailing spaces from a string  Space() - Creates a string with the specified number of spaces  StrComp() - Compare two strings  String() - Creates a repeated character string  StrReverse() - Reverse the characters of a string  Trim() - Remove both leading and trailing spaces from a string  UCase() - Convert a string to uppercase  

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.

By default, arguments are passed to functions and subroutines by reference; that is, the address of the argument is provided to the function or subroutine.

VBScript is a subset of Visual Basic for Applications, but there are still many differences:

VBScript doesn't have a debugger like Visual Basic or you can say that VBScript does not provide any debugging features.You'll resort to using lots of message boxes, instead.

Unlike Visual Basic and Visual Basic for Applications, in which the developer can define the data type of a variable in advance, all variables in VBScript are variants.

There is no integrated development environment for VBScript that parallels the IDE for Visual Basic and Visual Basic for Applications.

Because variables are untyped and code is not compiled, all external objects instantiated in VBScript code are necessarily late-bound. This has a number of implications. First, late binding typically entails a substantial performance penalty in comparison to early binding. Second, while the properties and methods of early-bound objects can be examined in Visual Basic or hosted VBA environments using the Object Browser, this is not the case with late-bound objects. Finally, the help facilities available for early-bound objects in VB and VBA (like Auto List Members and Auto Quick Info) are not available, making syntax errors more likely and ready access to good documentation all the more necessary.

A dictionary can't be multidimensional but an array can be.

A dictionary has extra methods to add new items and check for existing items.

When you delete a particular item from a dictionary, all the subsequent items automatically shift up. For example, if you delete the second item in a three-item dictionary, the original third item automatically shifts up into the second-item slot.

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.

There are four types of segments used in Oracle databases:

  • data segments
  • index segments
  • rollback segments
  • temporary segments

Data Segments:

There is a single data segment to hold all the data of every non clustered table in an oracle database. This data segment is created when you create an object with the CREATE TABLE/SNAPSHOT/SNAPSHOT LOG command. Also, a data segment is created for a cluster when a CREATE CLUSTER command is issued. The storage parameters control the way that its data segment's extents are allocated. These affect the efficiency of data retrieval and storage for the data segment associated with the object.

Index Segments:

Every index in an Oracle database has a single index segment to hold all of its data. Oracle creates the index segment for the index when you issue the CREATE INDEX command. Setting the storage parameters directly affects the efficiency of data retrieval and storage.

Rollback Segments:

Rollbacks are required when the transactions that affect the database need to be undone. Rollbacks are also needed during the time of system failures. The way the roll-backed data is saved in rollback segment, the data can also be redone which is held in redo segment.

A rollback segment is a portion of the database that records the actions of transactions if the transaction should be rolled back. Each database contains one or more rollback segments. Rollback segments are used to provide read consistency, to rollback transactions, and to recover the database.

Types of rollbacks:

  • statement level rollback
  • rollback to a savepoint
  • rollback of a transaction due to user request
  • rollback of a transaction due to abnormal process termination
  • rollback of all outstanding transactions when an instance terminates abnormally
  • rollback of incomplete transactions during recovery.

Temporary Segments:

The SELECT statements need a temporary storage. When queries are fired, oracle needs area to do sorting and other operation due to which temporary storages are useful.

The commands that may use temporary storage when used with SELECT are:

GROUP BY, UNION, DISTINCT, etc.

Order of evaluation of operators is, first arithmetic operators are evaluated, and comparison operators are evaluated next and at the last logical operators are evaluated at the last. In arithmetic operators negation, Exponentiation, multiplication and division, integer division, modulus arithmetic, addition and subtraction and string concatenation are provided.

Date(), Time(), Now(), Left(), Right(), & Mid()

The SMON background process performs all system monitoring functions on the oracle database.
Each time oracle is re-started, SMON performs a warm start and makes sure that the transactions that were left incomplete at the last shut down are recovered.

SMON performs periodic cleanup of temporary segments that are no longer needed.

A function, which is called differently from a subroutine, returns a value to the code that calls it, while a procedure (subroutine) does not. Functions must be set equal to a return value:

Variable_1 = My_Function(A, B, C)

A subroutine, on the other hand, isn't set to a variable. It can be called like

My_Subroutine A, B, C
Or
Call My_Subroutine(A, B, C)

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.

Visual Basic should rely on ASP for sever side processing. Asp.dll is used to make VB Script run on ASP engine and it invokes vbscript.dll. VB Script should be embedded with in <% and %> context switches. ASP can provide varied functionality to VB Script.

VB script is a Microsoft programming language and it resembles a lower version of the VB. It is an Active Scripting language. This scripting language is included in windows operating system by default. With the use of msscript.ocx you can install VB Script.

Variant is the only datatype in vb script.There are many subtypes under variant.They are Empty, Null, Boolean, Byte, Integer, Currency, Long, Single, Double,Date, String, Object, Error.

  i=5  j=6  if i>j then  msgbox i  elseif i msgbox j
else
msgbox “nothing”
end if
for i=5 to 10 step 2
msgbox i
next
do while i<15
msgbox i
i=i+3
loop
mycase=”gitam”
select case mycase
case “abcd”
msgbox “abcd”
case mycase
msgbox mycase
case else
msgbox “wrong”
end select

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.

The VBScript code that comes along in a Web page cannot directly access any files on the client's computer. This prevents a Web page from making any modifications to sensitive files on the user's computer. VBScript is also very safe in that it doesn't give programmers the ability to create unrecoverable crashes by virtue of its language syntax.

SQL*Loader is a bulk loader utility used for moving data from external files into the Oracle database. SQL*Loader supports various load formats, selective loading, and multi-table loads. When a control file is fed to an SQL*Loader, it writes messages to the log file, bad rows to the bad file and discarded rows to the discard file.

Control file:

The SQL*Loader control file contains information that describes how the data will be loaded. It contains the table name, column datatypes, field delimiters, etc.

controlfile.sql should be used to generate an accurate control file for a given table.

Log File:

The log file contains information about the SQL*loader execution. It should be viewed after each SQL*Loader job is complete.

Difference between VB Debugger and the Script Debugger:

No "on the fly" editing

Because the scripting window is read-only, you cannot edit the code during execution, as you can most of the time with VB.

No Instant Watch (Shift-F9)

The VB debugger's instant watch facility, which allows you to highlight a variable in your code, press Shift-F9, and see the value of the variable, is not available in the Script Debugger.

Cannot set watches Watches do not exist in the Script Debugger.

Cannot set the next statement Using the VB Debugger, you can place the cursor on a line of code and, by clicking CTRL-F9, have program execution resume at that line. This is particularly useful to backtrack or to re-execute a section of code. Unfortunately, this feature is not available in the Script Debugger.

  set ie=createobject(“internetexplorer.application”)  ie.navigate(“http://www.google.co.in/”)  ie.visible=true  set ie = nothing

According to the first letter in a string it returns the ANSI code relevant to that first letter. If string is not present then a runtime error occurs. Asc function returns the first byte used. It is used only with elements containing byte data in a string.

Filter expression returns an array based on a specific filter search condition and it returns a zero based array. Arguments included in the filter array are Input strings, value, include and compare. If there is no match for the value it returns an empty string.