You are on page 1of 5

o VBScript is a scripting language.

o A scripting language is a lightweight programming language.


o VBScript is a light version of Microsoft's programming language Visual Basic.

1.2 Creating a script with Notepad

1.Start Notepad.

2.Write your script. For example purposes, type Msgbox "Hello VB Script"

3.Save this text file with a .vbs extension (instead of the default .txt extension). For
example, Hello.vbs

4.Navigate to the file you just saved, and double-click it.

5.Windows Script Host invokes the VB Script engine and runs your script. In the example, a
message box is displayed with the message "Hello VB Script"

Comments

The comment argument is the text of any comment we want to include.

2.0 Purpose of comments:

o We can use comments for making the script understandable.


o We can use comments for making one or more statements disable from execution.
2.1 Syntax

Rem comment (After the Rem keyword, a space is required before comment.)

Or

Apostrophe (') symbol before the comment

2.2 Comment/Uncomment a block of statements

Select block of statement and use short cut key Ctrl + M (for comment)
Select comment block and use short cut key Ctrl + Shift + M (for uncomment)

//////////////////////////////////////////////////

What is the scope of a variable ?

The scope of a variable defines whether a variable will be accessible in the whole
function or will be accessed only to its local instance.I have defined earlier in the
tutorials that they can also be deemed as a local variables or can be deemed as a
global variables.

For ex.

< script >


Dim name
Sub cmdclickme_OnClick
Dim age
End Sub
< / script >

It is clear from the above example about the scope of the variable that the variable
name will be available to the whole script as it is declared outside sub procedure so
enhance his behaviour to the global as compared to the variable name age which is
defined inside the sub procedure hence making his behaviour local and will be only
accessed in this sub procedure only.

Which Browsers Support VBScript?

VBScript is a trademark of Microsoft Corporation and is only supported by Microsoft


Internet Explorer 3.0+ and Microsoft Internet Information Server.

Which Platforms Support VBScript?

VBScript is supported by Windows 95, Windows NT (including a native version for


Alpha), 16-bit Windows, and Unix Solaris. Microsoft is currently working with others
to bring VBScript to UNIX versions for HP, Digital, and IBM platforms.

What are Variants?

VbScript deals with a single datatype called variant. Datatype means the kind of the
data a variable will store.It can be a character data,string data,number data , byte
data and a Boolean data. But you don?t have to worry in Vb Script as it only has a
datatype of variant to store any type of data.

How Do I Use Arrays?

Arrays may either be static or dynamic. A static array has its dimensions pre-
defined and may not be re-sized, whereas a dynamic array does not have a pre-
defined number of dimensions and must be resized to store any data. To define any
of the two arrays first use either the Dim, Public, or Private statments as you would
with a normal variable. Then, to define a one-dimensional static array with three
elements, you could go:
Dim myArray(2)
To assign values to each element go:
myArray(0) = 34
myArray(1) = 45
myArray(2) = 12
You may have also defined the above array by using the Array( ) function like so:
Dim A
A = Array(34,45,12)
Arrays may be defined with as many as 60 dimensions. Array dimensions are
separated by commas. For example to define a three-dimensional array you could
go:
Public myArray(4, 7, 9)
Where the first dimension has 5 elements, the second has 8 elements, and the last
has 10 elements.
Dynamic arrays have no dimensions when they are defined and cannot contain data
until they are re-dimensioned. To define a dynamic array simply go: Dim myArray( )
How Do I Re-Dimension Arrays?

You may only re-dimension dynamic arrays. To do so, use the ReDim statement in the same
manner as either the Dim, Public, or Private statments. For example to re-dimension an existing
dynamic array you could go:
ReDim myArray(5, 5)
Note that using the ReDim statement will reset all data within the array. To keep the data from
being erased use the Preserve statement in conjuction with the ReDim statement like so:
ReDim Preserve myArray(5, 5)
There is no limit to the number of times you can resize a dynamic array, but if you make an array
smaller than it was, the data in the eliminated elements will be lost.

Explain about constants in VB Script?

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.

What is VBScript?

VBScript is a somewhat simplified version of its superset, Visual Basic, as some


prototypes are made easier, you do not have to worry about variable sizes, etc. This
is too try and allow optimum web development with minimal programming abilities
by the programmer. The main difference between Visual Basic and its subset is that
VBScript is limited to the web and is fully integrated with the web browser rather
than the operating system. This is purely for security reasons. Nonetheless,
VBScript is a very powerful asset because it is geared towards Microsoft web
technologies such as ASP and ActiveX.

Give examples where VB script can directly run on users system with
Windows as OS?

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.

What Is The Difference Between the Dim, Public, and Private Statements?
Private statement variables are available only to the script in which they are
declared.
Public statement variables are available to all procedures in all scripts.
Variables declared with Dim at the script level are available to all procedures within
the script. At the procedure level, variables are available only within the procedure.

What Is The Variant Datatype?

The Variant datatype can contain a wide array of subtypes, thus, the programmer
need not worry about making sure that certain variables are capable of supporting a
specific type of data. The following table shows the subtypes of data that a Variant
can contain.

What is the use of Option Explicit in VBScript?

When you use the Option Explicit statement, you must explicitly declare all variables using the
Dim, Private, Public, or ReDim statements. If you attempt to use an undeclared variable name,
an error occurs.

Use Option Explicit to avoid incorrectly typing the name of an existing variable or to avoid
confusion in code where the scope of the variable is not clear.

How does VBScript differ from JavaScript and which proves better? State
the reason for the same

VB Script is compatible with only IE

Java is compatible with all browsers.

What are the types of arrays handled by VBScript?

Broadly the array can categorized in 2 different ways.


1. Static Array.
2. Dynamic Array.

Static Array can be categorized into


- Single dimension Array.
- Multi dimension Array.

You might also like