E-Content of
INTERNET TECHNOLOGY AND WEB DESIGN
Chapter : 10.2 Interactive Tools
Topic : 10.2.3 VB Script
VB Script
• Visual Basic is a language based on one of the most taught language
“BAISC” when first starting out with computers.
• VB Script is a subset of the Visual Basic for application programming
language for Internet Explorer.
• Visual Basic or VBA (Visual Basic Application) is used to create web
applications.
• JavaScript's syntax is arguably less intuitive and more obtuse than that
of VB Script and tends to be less forgiving of simple “mistakes” such as
case sensitivity.
• VB Script is an untyped language, which means that all variables are
variants and don't have an explicit type (such as integer or string).
• VB Script was introduced by Microsoft way back in 1996 and the first
version was 1.0. The Current Stable version of VB Script is 5.8, which is
available as part of IE8 or Windows 7.
• An example program for VB Script to print text as 'Hello World'.
<html>
<body>
<script language=”vbscript” type=”text/vbscript”>
document.write(“Hello World!”)
</script>
</body>
</html>
Page | 8
E-Content of
INTERNET TECHNOLOGY AND WEB DESIGN
Features of VB Script
• VB Script is a lightweight scripting language, which has a lightning fast
interpreter.
• VB Script, for the most part, is case insensitive. It has a very simple
syntax, easy to learn and to implement.
• Unlike C++ or Java, VB Script is an object-based scripting language and
NOT an Object-Oriented Programming language.
• It uses Component Object Model (COM) in order to access the elements
of the environment in which it is executing.
• Successful execution of VB Script can happen only if it is executed in
Host Environment such as Internet Explorer (IE), Internet Information
Services (IIS) and Windows Scripting Host (WSH).
Uses of VB Script
• The VB Script usage areas are aplenty and not restricted to the below
list.
VB Script is used as a scripting language in one of the popular
Automation testing tools – Quick Test Professional abbreviated as
QTP.
Windows Scripting Host, which is used mostly by Windows System
administrators for automating the Windows Desktop.
Active Server Pages (ASP), a server side scripting environment for
creating dynamic web pages which uses VB Script or Java Script.
VB Script is used for Client side scripting in Microsoft Internet
Explorer.
Page | 9
E-Content of
INTERNET TECHNOLOGY AND WEB DESIGN
Microsoft Outlook Forms usually runs on VB Script; however, the
application level programming relies on VBA (Outlook 2000
onwards).
Disadvantages of VB Script
• VB Script is used only by IE Browsers. Other browsers such as Chrome,
Firefox do not Support VB Script. Hence, JavaScript is preferred over
VB Script.
• VB Script has a Limited command line support.
• Since there is no development environment available by default,
debugging is difficult.
Page | 10
E-Content of
INTERNET TECHNOLOGY AND WEB DESIGN
Chapter : 10.2 Interactive Tools
Topic : 10.2.3A VB Script Variables and Constants
VB Script Variables and Constants
• Variable is a named memory location used to hold a value that can be
changed during the script execution.
• VB Script has only ONE fundamental data type, variant.
• Rules for declaring variables are
Variable Name must begin with an alphabet.
Variable names cannot exceed 255 characters.
Variables should not contain a period (.)
Variable names should be unique in the declared context.
• To declare variable
Variables are declared using “dim” keyword. Since there is only one
fundamental data type, all the declared variables are variant by
default. Hence, a user need not mention the type of data during
declaration.
For example, IntValue can be used as a String, Integer or even
arrays.
Dim Var
Two or more declarations are separated by comma (,).
Dim Variable1, Variable2
Page | 11
E-Content of
INTERNET TECHNOLOGY AND WEB DESIGN
• The following example program for to declare variable and assign value
to it.
<!DOCtype html>
<html>
<body>
<%
Dim name
name=”Gupta”
Response.write(“Myname is: “ & name)
%>
</body>
</html>
• Output for above program is shown below
My name is: Gupta
VB Script Constants
• Constant is a named memory location used to hold a value that cannot
be changed during the script execution.
• If a user tries to change a constant value, the Script execution ends up
with an error. Constants are declared the same way the variables are
declared.
Page | 12
E-Content of
INTERNET TECHNOLOGY AND WEB DESIGN
Chapter : 10.2 Interactive Tools
Topic : 10.2.3B VB Script – Loops
VB Script – Loops
• There may be a situation when user needs to execute a block of code several
number of times.
• In general, statements are executed sequentially. The first statement in a function
is executed first, followed by the second, and so on.
• Programming languages provide various control structures that allow for more
complicated execution paths.
• A loop statement allows user to execute a statement or group of statements
multiple times and following is the general from of a loop statement in VB Script.
FIG 10.2 Working of Loop
• VB Script provides the following types of loops to handle looping requirements.
Page | 13
E-Content of
INTERNET TECHNOLOGY AND WEB DESIGN
Loop Type Description
For loop Executes a sequence of statements
multiple times and abbreviates the code
that manages the loop variable.
For...each loop This is executed if there is at least one
element in group and reiterated for each
element in a group
While...wend loop This tests the condition before executing
the loop body.
do...while loops The do...While statements will be executed
as long as condition is True. (I.e..,) The
loop should be repeated till the condition is
False.
do...until loops The do...Until statements will be executed
as long as condition is False. (i.e.,) The
Loop should be repeated till the condition
is True.
FIG 10.3: Loop types and its description
• The following example shows the For loop execution.
Page | 14
E-Content of
INTERNET TECHNOLOGY AND WEB DESIGN
<!DOCTYPE html>
<html>
<body>
<%
For i = 0 to 5
response.write(“The number is “& I & “ <br>
“)
Next
%>
</body>
</html>
• The output for above script is shown below
The number is 0
The number is 1
The number is 2
The number is 3
The number is 4
The number is 5
Page | 15