2. VB Script stands for Visual Basic Script and it is
a light version of Microsoft Visual Basic.
The syntax of VBScript is very similar to that of
Visual Basic.
VBScript was developed by Microsoft with the
intention of developing dynamic web pages.
Aamir Sohail2
3. if you want your webpage to be more lively and
interactive, then you can incorporate VBScript in
your code.
VBScript is just a scripting language.
So, it cannot run its code on its own.
It needs a bigger programming language to host it.
3
4. VBScript is a lightweight scripting language, which
has a lightning fast interpreter.
VBScript, for the most part, is case insensitive. It
has a very simple syntax, easy to learn and to
implement.
Aamir Sohail4
5. Right now, there are 3 environments where VB
Script can run.
IIS (Internet Information Server) – Microsoft’s web
server
WSH (Windows Script Host)– The native hosting
environment of the Windows OS
IE (Internet Explorer)– The simplest hosting
environment we can use to run VBScripts
Aamir Sohail5
6. VBScript can be used as follows:
◦ Input Validation
◦ Mouse Rollover Effects
◦ Popup Windows
◦ Dynamic Contents
◦ User Interaction
Aamir Sohail6
7. Web Pages
◦ VBScript can be used as client side scripting. It can be
embedded in HTML document to add interactive
functionality to web pages. It can be used for data
validation and user interaction at the client-end.
7
8. The applications that use VBScript are called Host
applications. The most common host applications
are as follows.
• Internet Explorer
• Internet Information Server
• Outlook uses VBScript as its Macro language
• Windows Scripting Host
Aamir Sohail8
9. easy to learn and use
minimum programming knowledge or experience
required
allow complex tasks to be performed in relatively
few steps
allow simple creation and editing in a variety of
text editors
allow the addition of dynamic and interactive
activities to web pages
editing and running code is fast.
Aamir Sohail9
10. The main disadvantage of VBScript is that most
browsers except Internet Explorer will not process
VBScript code.
if your site has visitors who use a web browser other
than Internet Explorer like Chrome, Firefox or Opera,
then VBScript will not be useful.
Aamir Sohail10
11. Moreover, VBScript will not run on computers
that run on operating systems other than
Microsoft Windows including Linux, Mac etc.
Like any other scripting language, VBScript has
gone through many changes over the years.
Aamir Sohail11
12. VBScript code is embedded into HMTL document
using the SCRIPT tag. The <SCRIPT> tag is used
to inform browser about the start of VBScript
statements. The <SCRIPT> tag indicates the
beginning of scripting code and </SCRIPT> tah
indicates the end of scripting code.
<SCRIPT language=“VBScript”>
</SCRIPT>
Aamir Sohail12
13. VBScript uses an object called Document.
This object manages many instruction of VBScript.
It can be used is to display a string on the screen.
a string is the next that is displayed in the
browser. It is displayed by using the function
Write.
The Syntax of Write function of Document Object
is as Follows.
Document.Write(string)
Aamir Sohail13
14. The string can be constant written in double qoutes
or a variable. An example of Document.Write()
function is as follows:
<SCRIPT language=“VBScript”>
Document.Write(“VBScrip
Statement”)
</SCRIPT>
Aamir Sohail14
15. Variable is a named memory location used to hold
a value that can be changed during the script
execution.
The value of variable may changes during the
program execution but the name of the variable
cannot be changed.
Aamir Sohail15
16. The name of variable is given by the user at design
time. It may consist of alphabetic and numeric
digits. The name of variable should ne meaningful
and simple.
For example, if you have to store names of students
or salaries of employees, you will be using
variables named students or salaries.
Aamir Sohail16
17. Following are some rules for declaring variables:
• Variable Name must begin with an alphabet. The
variables 9minute, #home, and 2kg are invalid.
• A variable name may include letters, number and
Underscore(_).
• Variable names cannot exceed 255 characters.
• Variables Should NOT contain a period(.)
• Variable Names should be unique in the declared
context.
Aamir Sohail17
18. • Blank Spaces are not allowed on the variable
name. the variable “my book” and “your car” are
invalid.
• Both upper and lowercase are allowed in variable
name.
• A reserved word cannot be used as a variable
name.
Aamir Sohail18
19. Some examples of valid variables are as follows:
Marks
Home12
My_Car
F_name
Aamir Sohail19
20. Values are assigned similar to an algebraic expression.
The variable name on the left hand side followed by an
equal to (=) symbol and then its value on the right hand
side.
Rules:
The numeric values should be declared without double
quotes.
Aamir Sohail20
21. The String values should be enclosed within
doublequotes(")
Date and Time variables should be enclosed
within hash symbol(#)
Following are the examples
Aamir Sohail21
22. The value 25 is assigned to the variable. Value1 =
25
A String Value ‘VBScript’ is assigned to the
variable StrValue.
StrValue = “VBScript”
The date 01/01/2020 is assigned to the variable
DToday.
Date1 =#01/01/2020#
A Specific Time Stamp is assigned to a variable in
the below example.
Time1 = #12:30:44 PM##
Aamir Sohail22
23. The variable in VBScript are declared using Dim
Keyword. Din stands for dimension, the syntax for
declaring variable is as follows:
Dim VarName
Here, VarName is variable name. VBScript has only
one data type called variant, it can store different
types of data such as string, integers, floating
point and numbers etc
Aamir Sohail23
24. VBScript interprets a variant according to the value
stored in it.
For example, a variant is treated as a number if it
contains numeric value. Similarly, a variable is
treated as string if It contains string value.
Aamir Sohail24
25. The option explicit is used to ensure that all
variables are declared before they are used.
The option explicit statement is included before any
HTML text or script commands.
Aamir Sohail25
30. In simple words, 4 + 5 is equal to 9. Here, 4 and 5
are called operands and + is called operator.
VBScript language supports following types of
operators:
VBScript provides different mathematical operators
to manipulate data and perform calculations that
are as follows:
Aamir Sohail30
31. Assume variable A holds 5 and variable B holds 10,
then:
Aamir Sohail31
32. There are following comparison operators supported by
VBScript language.
Assume variable A holds 10 and variable B holds 20, then:
Aamir Sohail32
33. There are following Concatenation operators supported by
VBScript language:
Assume variable A holds 5 and variable B holds 10 then:
Aamir Sohail33
34. Comments are the part of script that are not
executed. Comment are actually notes about
different lines of code that explain the purpose of
the code.
Comment can be added anywhere in the code.
In VBScript, comments starts with an single (‘).
Aamir Sohail34
35. A single (‘) Quote is used to tell the browser that
ignore statements that follow the symbol while
processing the code.
Following line is an example of VBScript Comment
‘Hi…!!! This is an example of comment
Aamir Sohail35
36. A function is a group of reusable code which can be
called anywhere in your program. This eliminates
the need of writing same code over and over
again.
This will enable programmers to divide a big
program into a number of small and manageable
functions.
Aamir Sohail36
37. Before we use a function, we need to define that
particular function.
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.
Aamir Sohail37
38. The basic syntax is shown below:
Function Functionname(parameter-list)
statement 1
statement 2
statement 3
.
.
.
statement n
End Function
Aamir Sohail38
39. To invoke a function somewhere later in the script,
you would simple need to write the name of that
function with the Call keyword.
Function Functio01(parameter-list)
statement 1
End Function
Call Function01
Aamir Sohail39
40. Decision making allows programmers to control the
execution flow of a script or one of its sections.
The execution is governed by one or more
conditional statements.
Following is the general form of a typical decision
making structure found in most of the
programming languages:
Aamir Sohail40
41. If the condition is said to be True, the statements
under If condition(s) are Executed.
If the Condition is said to be False, the statements
after the If loop are executed.
Aamir Sohail41
42. <script language="vbscript">
Dim a : a = 20
Dim b : b = 10
If a > b
Then
Document.write "a is Greater than b"
End If
</script>
Aamir Sohail42
43. If the condition is said to be True, the statements
under If condition(s) are Executed.
If the Condition is said to be False, the statements
under Else Part would be executed.
Aamir Sohail43
44. Dim a : a = 5
Dim b : b = 25
If a > b
Then
Document.write "a is Greater“
Else
Document.write "b is Greater“
End If
Aamir Sohail44