0% found this document useful (0 votes)
4 views

VBScript notes

VBScript is a Microsoft scripting language primarily used for client-side scripting in Internet Explorer and server-side scripting in ASP. It features a single data type called Variant, supports conditional statements and loops, and allows for automation and error handling. Key differences between VBScript and JavaScript include platform support, syntax style, and popularity, with VBScript being largely obsolete for modern web development.

Uploaded by

mayankkhanna827
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

VBScript notes

VBScript is a Microsoft scripting language primarily used for client-side scripting in Internet Explorer and server-side scripting in ASP. It features a single data type called Variant, supports conditional statements and loops, and allows for automation and error handling. Key differences between VBScript and JavaScript include platform support, syntax style, and popularity, with VBScript being largely obsolete for modern web development.

Uploaded by

mayankkhanna827
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

VBScript

 VBScript is the subset of Visual Basic Language.


 Internet Explorer is the only browser that can execute VBScript
 It is a Scripting Language
 It is created by Microsoft to use either as client-side scripting
language for Microsoft Internet Explorer, or as a server-side
scripting language with Microsoft Internet Information Server.
 VBScript cannot run on its own.
 It requires an execution host. An execution host is another
program such as web browser that interpret and execute your
script.

Features of VBScript:
1. Easy to learn and use
2. Not case sensitive
3. Built in formatting: (built in features for formatting date and
numbers)
4. ASP Default language: (if we don’t specify language in ASP, it is
considering VBScript as default language)
5. Lightweight: (program of VBScript is very lightweight and can be
write using notepad)
6. Automation support: (it provides automation support we can
automate our tasks)
7. Conditional statements: (it supports if…Then)
8. Loops and repetition: (for next, do while, Do until)
9. Error Handling Support: (Error handling features we have error
object to handle i.e. Err)
10. ActiveX scripting: (means using script to control another windows
program automatically)

Comparison of JS and VBScript


Feature JavaScript VBScript
Platform Support Works in all modern Only works in Internet
browsers Explorer
Default Language Default in web Default in classic ASP
development
Case Sensitivity Case-sensitive (var ≠ Not case-sensitive
Var)
Syntax Style C-style syntax (like C, More like BASIC
Java)
Client-Side Use Still widely used Obsolete for client-side
Server-Side Use Node.js for backend Used in Classic ASP
(legacy)
Speed & Fast, supported by Slower, no active
Performance modern engines development
File Extension .js .vbs
Security Sandboxed in browsers Has more access to
system (less safe)
Popularity Very popular and Outdated and rarely
current used
Development More development Less Development time
Time time

Data Types:
 VBScript has only one data type called Variant.
 A variant can contain either numeric or string information.
 Variant behaves as a number when you use it in a numeric context
and as a string when you use it in a string context.
 By default, data type of a variable is variant.
 The different categories of information that can be contained in a
variant are called subtypes.
Name Size Description
Byte 1 byte Only positive values
Integer 2 bytes Whole numbers (–
32,768 to 32,767)
Long 4 bytes Larger whole numbers
Single 4 bytes Small decimal numbers
(.6)
Double 8 bytes Large/precise decimal
numbers (.14)
Currenc 8 bytes Monetary values, fixed
y decimal (.4)
String String Text values
length+10 bytes
Date 8 bytes Stores both date and
time
Boolean 2 bytes True or False
Object 4 bytes It is used to hold object
Empty 0 bytes Uninitialized variable

Variable:
 It is a name given to storage location.
 Value of a variable can be varied.
 Variable has two associated things with it: a name and its datatype
 It is used to store value.
 All variable are treated as type variant by default.

Rules for Variable name:


1. Must begin with a letter.
2. Can contain letter, number and underscore.
3. Maximum size is 255 characters.
4. Cannot be a keyword.
5. Not case sensitive.
6. Must be unique.

Declaring Variable:
Variable are declared using “Dim” keyword.
In VBScript, you cannot specify a variable’s data type directly. All
variables are automatically of type Variant, which is a flexible data type
that can hold any kind of value — string, number, date, object, etc.
Ex: Dim name
Dim rollno , name

Assigning values to Variables:


Variable_name = expression
Expression can be a literal, arithmetic expression, another variable
Ex: age=18
Marks=92.34
Name=”Mayank”
Tommorow=#4/27/2025#
Time = #10:30:00 AM#

Constants:
Constant is a named given to memory location.
It is used to hold values that cannot be changed during the script
execution.
Syntax: const constant_name=value

MsgBox:
A message box is a function used to displays a pop-up message box to
the user.
It is used to show information, warnings, errors, or to ask the user for a
response
Syntax: MsgBox(prompt, [buttons], [title])
Constant Value Description
vbOKOnly 0 Display only the OK button
vbOKCancel 1 Display OK and Cancel buttons
vbAbortRetryIgnor 2 Display Abort, Retry, and Ignore
e buttons
vbYesNoCancel 3 Display Yes, No, and Cancel buttons
vbYesNo 4 Display Yes and No buttons
vbRetryCancel 5 Display Retry and Cancel buttons

Constant Value Description


vbCritical 16 Display critical message icon
vbQuestion 32 Display question message icon
vbExclamation 48 Display warning message icon
vbInformation 64 Display information message
icon

Butto Constant Value Description


n
OK vbOK (1) The OK button was clicked.
Cancel vbCancel (2) The Cancel button was
clicked.
Abort vbAbort (3) The Abort button was clicked.
Retry vbRetry (4) The Retry button was clicked.
Ignore vbIgnore (5) The Ignore button was clicked.
Yes vbYes (6) The Yes button was clicked.
No vbNo (7) The No button was clicked.

InputBox:
InputBox is used to take input value from the user.
Syntax: InputBox(prompt,[title],[default value],[x pos,y pos]).

Conditional Statements:
It is used to execute part of code based on some condition.
If – then
If – Then – else
If – then- elseif-then-else
Select case
Syntax:

If -then
If (condition) then
Statements
End if

If – then – else
If (condition) then
Statements
Else
Statements
End if

If -then -elseif -else


If(condition) then
Statements
Elseif condition then
Statements
Elseif condition then
Statements
Else
Statements
End if

Select case
Select case expression
Case value1
Statements
Case value2
Statemenets
Case value3
Statements
Case else
Statements
End select

Looping structure:
If we want to execute certain part of code repeatedly we can use loops
There are two types of looping structure:
1. Condition controlled
2. Counter controlled

DO While_loop
Do while condition
Statements
Loop

Do until_loop
Do until condition
Statements
Loop

While_wend
While condition
Statements
wend

For_Next
For counter=start value to end value [step value]
Statements
Next counter

Array
An array is a collection of values represented by a single variable name
each value in an array is accessed by its index i.e position.
Dim arrayname(size)
Or
Array_name= Array(value1, value2, value3….)
Multidimensional array
Syntax
Dim array_name(dimension1, dimension2)

Array functions
LBound(arrayname,[dimension])
Returns the Lowest index of the specified array.

UBound(arrayname,[dimension])
Returns the highest index of the specified array.

Split(string,[delimeter],[limit],[compare])
The Split function in VBScript is used to split a string into an array based
on a specified delimiter. It returns an array where each element is a
portion of the original string.
 expression: The string you want to split.
 delimiter (Optional): The character or substring used to divide the
string. If not provided, the default is a space (" ").
 limit (Optional): The maximum number of substrings to return. If
omitted, all substrings are returned.
 compare (Optional): A numeric value that defines how strings are
compared. 0 for case-sensitive comparison and 1 for case-insensitive.

Join Function
The Join function in VBScript is used to combine an array of strings into
a single string, with a specified delimiter between each element.
Syntax: Join(array, [delimiter])
 array: The array of strings you want to join.
 delimiter (Optional): The delimiter you want to insert between
each element of the array. The default delimiter is an empty string
("").

Filter Function
The Filter function in VBScript is used to search for a specific substring
within an array and return a new array containing only the elements
that match the search criteria.

Syntax: Filter(sourceArray, filter, [include], [start])


 sourceArray: The array you want to search.
 filter: The substring or pattern you're looking for.
 include (Optional): A Boolean value that determines whether to
include or exclude items that match the filter.
o True (default): Only include items that match the filter.
o False: Exclude items that match the filter.
 start (Optional): The position in the array from where to start
searching. The default is 0 (the beginning).

IsArray(variable)
It is used to check a variable is array or not if the specified variable is
array it will return true otherwise it will give false.

You might also like