VBScript Tutorial
VBScript Tutorial
in
Vbscript Complete
Tutorial
Created By www.ebooktutorials.blogspot.in
VBScript Tutorial
W3Schools Home
Next Chapter
VBScript Editor
With our online editor, you can edit the VBScript code, and click on a button to view the result.
VBScript Examples
Learn by examples! With our editor, you can edit the source code, and click on a test button to view the result.
Try-it-Yourself!
VBScript Reference
At W3Schools you will find a complete VBScript reference.
VBScript Reference
W3Schools Home
Next Chapter
Created By www.ebooktutorials.blogspot.in
VBScript Introduction
Previous
Next Chapter
What is VBScript?
VBScript is a scripting language
A scripting language is a lightweight programming language
VBScript is a light version of Microsoft's programming language Visual Basic
VBScript is only supported by Microsoft's browsers (Internet Explorer)
Previous
Next Chapter
Created By www.ebooktutorials.blogspot.in
VBScript How To
Previous
Next Chapter
The HTML <script> tag is used to insert a VBScript into an HTML page.
The example below shows how to add HTML tags to the VBScript:
Example Explained
To insert a VBScript into an HTML page, we use the <script> tag. Inside the <script> tag we use the type attribute to define the scripting language.
So, the <script type="text/vbscript"> and </script> tells where the VBScript starts and ends:
<html>
<body>
<script type="text/vbscript">
...
</script>
</body>
</html>
The document.write command is a standard VBScript command for writing output to a page.
By entering the document.write command between the <script> and </script> tags, the browser will recognize it as a VBScript command and execute the
code line. In this case the browser will write Hello World! to the page:
<html>
<body>
<script type="text/vbscript">
document.write("Hello World!")
</script>
</body>
</html>
<html>
<body>
<script type="text/vbscript">
Created By www.ebooktutorials.blogspot.in
<!-document.write("Hello World!")
-->
</script>
</body>
</html>
Previous
Next Chapter
Created By www.ebooktutorials.blogspot.in
Next Chapter
VBScripts can be placed in the body and in the head section of an HTML document.
Scripts in <head>
Put your functions and sub procedures in the head section, this way they are all in one place, and they do not interfere with page content.
Scripts in <body>
If you don't want your script to be placed inside a function, and especially if your script should write page content, it should be placed in the body section.
Created By www.ebooktutorials.blogspot.in
Using an External VBScript
If you want to run the same VBScript on several pages, without having to write the same script on every page, you can write a VBScript in an external file.
Save the external VBScript file with a .vbs file extension.
Note: The external script cannot contain the <script> tag!
To use the external script, point to the .vbs file in the "src" attribute of the <script> tag:
Example
<html>
<head>
<script type="text/vbscript" src="ex.vbs"></script>
</head>
<body>
</body>
</html>
Try it yourself
Note: Remember to place the script exactly where you normally would write the script!
Previous
Next Chapter
Created By www.ebooktutorials.blogspot.in
VBScript Variables
Previous
Next Chapter
VBScript Variables
As with algebra, VBScript variables are used to hold values or expressions.
A variable can have a short name, like x, or a more descriptive name, like carname.
Rules for VBScript variable names:
Must begin with a letter
Cannot contain a period (.)
Cannot exceed 255 characters
In VBScript, all variables are of type variant, that can store different types of data.
Dim x
Dim carname
Now you have created two variables. The name of the variables are "x" and "carname".
You can also declare variables by using its name in a script. Like this:
carname="Volvo"
Now you have also created a variable. The name of the variable is "carname". However, this method is
not a good practice, because you can misspell the variable name later in your script, and that can
cause strange results when your script is running.
If you misspell for example the "carname" variable to "carnime", the script will automatically create a
new variable called "carnime". To prevent your script from doing this, you can use the Option Explicit
statement. This statement forces you to declare all your variables with the dim, public or private
statement.
Put the Option Explicit statement on the top of your script. Like this:
Option Explicit
Dim carname
carname=some value
carname="Volvo"
x=10
The variable name is on the left side of the expression and the value you want to assign to the variable
is on the right. Now the variable "carname" has the value of "Volvo", and the variable "x" has the value
of "10".
Lifetime of Variables
Created By www.ebooktutorials.blogspot.in
How long a variable exists is its lifetime.
When you declare a variable within a procedure, the variable can only be accessed within that
procedure. When the procedure exits, the variable is destroyed. These variables are called local
variables. You can have local variables with the same name in different procedures, because each is
recognized only by the procedure in which it is declared.
If you declare a variable outside a procedure, all the procedures on your page can access it. The
lifetime of these variables starts when they are declared, and ends when the page is closed.
Dim names(2)
The number shown in the parentheses is 2. We start at zero so this array contains 3 elements. This is a
fixed-size array. You assign data to each of the elements of the array like this:
names(0)="Tove"
names(1)="Jani"
names(2)="Stale"
Similarly, the data can be retrieved from any element using the index of the particular array element
you want. Like this:
mother=names(0)
You can have up to 60 dimensions in an array. Multiple dimensions are declared by separating the
numbers in the parentheses with commas. Here we have a two-dimensional array consisting of 5 rows
and 7 columns:
Dim table(4,6)
Asign data to a two-dimensional array:
Previous
Next Chapter
Created By www.ebooktutorials.blogspot.in
VBScript Procedures
Previous
Next Chapter
Sub mysub()
some statements
End Sub
or
Sub mysub(argument1,argument2)
some statements
End Sub
Function myfunction()
some statements
myfunction=some value
End Function
or
Function myfunction(argument1,argument2)
some statements
myfunction=some value
End Function
Created By www.ebooktutorials.blogspot.in
<body>
<button onclick="myfunction()">Click me</button>
</body>
Try it yourself
carname=findname()
Here you call a Function called "findname", the Function returns a value that will be stored in the variable "carname".
Function procedures can calculate the sum of two arguments:
The function "myfunction" will return the sum of argument "a" and argument "b". In this case 14.
When you call a procedure you can use the Call statement, like this:
Call MyProc(argument)
Or, you can omit the Call statement, like this:
MyProc argument
Previous
Next Chapter
Created By www.ebooktutorials.blogspot.in
Next Chapter
Conditional Statements
Conditional statements are used to perform different actions for different decisions.
In VBScript we have four conditional statements:
If statement - executes a set of code when a condition is true
If...Then...Else statement - select one of two sets of lines to execute
If...Then...ElseIf statement - select one of many sets of lines to execute
Select Case statement - select one of many sets of lines to execute
If...Then...Else
Use the If...Then...Else statement if you want to
execute some code if a condition is true
select one of two blocks of code to execute
If you want to execute only one statement when a condition is true, you can write the code on one
line:
If i=10 Then
alert("Hello")
i = i+1
End If
There is no ..Else.. in the example above either. You just tell the code to perform multiple actions if
the condition is true.
If you want to execute a statement if a condition is true and execute another statement if the condition
is not true, you must add the "Else" keyword:
In the example above, the first block of code will be executed if the condition is true, and the other
block will be executed otherwise (if i is greater than 10).
If...Then...ElseIf
You can use the If...Then...ElseIf statement if you want to select one of many blocks of code to
execute:
Created By www.ebooktutorials.blogspot.in
<html>
<body>
<head>
<script type="text/vbscript">
Function greeting()
i=hour(time)
If i = 10 Then
document.write("Just started...!")
ElseIf i = 11 then
document.write("Hungry!")
ElseIf i = 12 then
document.write("Ah, lunch-time!")
ElseIf i = 16 then
document.write("Time to go home!")
Else
document.write("Unknown")
End If
End Function
</script>
</head>
<body onload="greeting()">
</body>
</html>
Try it yourself
Select Case
You can also use the "Select Case" statement if you want to select one of many blocks of code to
execute:
This is how it works: First we have a single expression (most often a variable), that is evaluated once.
The value of the expression is then compared with the values for each Case in the structure. If there is
a match, the block of code associated with that Case is executed.
Previous
Next Chapter
Created By www.ebooktutorials.blogspot.in
VBScript Looping
Previous
Next Chapter
Looping Statements
Looping statements are used to run the same block of code a specified number of times.
In VBScript we have four looping statements:
For...Next statement - runs code a specified number of times
For Each...Next statement - runs code for each item in a collection or each element of an
array
Do...Loop statement - loops while or until a condition is true
While...Wend statement - Do not use it - use the Do...Loop statement instead
For...Next Loop
Use the For...Next statement to run a block of code a specified number of times.
The For statement specifies the counter variable (i), and its start and end values. The Next statement
increases the counter variable (i) by one.
Example
<html>
<body>
<script type="text/vbscript">
For i = 0 To 5
document.write("The number is " & i & "<br />")
Next
</script>
</body>
</html>
Try it yourself
Exit a For...Next
You can exit a For...Next statement with the Exit For keyword.
For i=1 To 10
If i=5 Then Exit For
some code
Next
Example
Created By www.ebooktutorials.blogspot.in
<html>
<body>
<script type="text/vbscript">
Dim cars(2)
cars(0)="Volvo"
cars(1)="Saab"
cars(2)="BMW"
For Each x In cars
document.write(x & "<br />")
Next
</script>
</body>
</html>
Try it yourself
Do...Loop
If you don't know how many repetitions you want, use a Do...Loop statement.
The Do...Loop statement repeats a block of code while a condition is true, or untila condition becomes
true.
Do While i>10
some code
Loop
If i equals 9, the code inside the loop above will never be executed.
Do
some code
Loop While i>10
The code inside this loop will be executed at least one time, even if i is less than 10.
Do Until i=10
some code
Loop
If i equals 10, the code inside the loop will never be executed.
Do
some code
Loop Until i=10
The code inside this loop will be executed at least one time, even if i is equal to 10.
Exit a Do...Loop
You can exit a Do...Loop statement with the Exit Do keyword.
Do Until i=10
i=i-1
If i<10 Then Exit Do
Loop
The code inside this loop will be executed as long as i is different from 10, and as long as i is greater
than 10.
Previous
Next Chapter
Created By www.ebooktutorials.blogspot.in
Next Chapter
VBScript Summary
This tutorial has taught you how to add VBScript to your HTML pages, to make your web site more dynamic and interactive.
You have learned how to create variables and functions, and how to make different scripts run in response to different scenarios.
For more information on VBScript, please look at our VBScript examples and our VBScript references.
Previous
Next Chapter
Created By www.ebooktutorials.blogspot.in
VBScript Examples
Previous
Next Chapter
Basic
Write text using VBScript
Format text with HTML tags
A function in the head section
A script in the body section
Variables
Create a variable
Insert a variable value in a text
Create an array
Procedures
Sub procedure
Function procedure
Conditional Statements
If...Then..Else statement
If...Then..ElseIf statement
Select Case statement
Random link
Looping
For..Next loop
Looping through the HTML headers
For..Each loop
Do...While loop
Date and Time Functions
Display Date and Time
Display the days
Display the months
Display the current month and day
Countdown to year 3000
Add a time interval to a date
Format Date and Time
Is this a date?
Other Built-in Functions
Uppercase or lowercase characters?
Remove leading or trailing spaces from a string
Reverse a string
Round a number
Return a random number
Return a random number between 0-99
Return a specified number of characters from the left or right side of a string
Replace some characters in a string
Return a specified number of characters from a string
Previous
Next Chapter
Created By www.ebooktutorials.blogspot.in
Your Result:
<!DOCTYPE html>
<html>
<body>
<script type="text/vbscript">
document.write("Hello World!")
</script>
</body>
</html>
Created By www.ebooktutorials.blogspot.in
Your Result:
<!DOCTYPE html>
<html>
<body>
<script type="text/vbscript">
document.write("<h1>Hello World!</h1>")
</script>
</body>
</html>
Created By www.ebooktutorials.blogspot.in
<!DOCTYPE html>
<html>
<head>
<script type="text/vbscript">
function myFunction()
alert("Hello World!")
end function
</script>
</head>
Your Result:
We usually use the head section for functions (to be sure that the
functions are loaded before they are called).
<body onload="myFunction()">
<p>We usually use the head section for functions (to be sure
that the functions are loaded before they are called).</p>
</body>
</html>
Created By www.ebooktutorials.blogspot.in
Your Result:
<!DOCTYPE html>
<html>
<body>
<script type="text/vbscript">
document.write("This message is written by VBScript")
</script>
</body>
</html>
Created By www.ebooktutorials.blogspot.in
<!DOCTYPE html>
<html>
<body>
Your Result:
<script type="text/vbscript">
Dim firstname
firstname="Hege"
document.write(firstname)
document.write("<br />")
firstname="Tove"
document.write(firstname)
</script>
<p>The script above declares a variable, assigns a value to it, and
displays the value. Then, it changes the value, and displays the value
again.</p>
</body>
</html>
Created By www.ebooktutorials.blogspot.in
Your Result:
<!DOCTYPE html>
<html>
<body>
<script type="text/vbscript">
Dim name
name="Jan Egil"
document.write("My name is: " & name)
</script>
</body>
</html>
Created By www.ebooktutorials.blogspot.in
Your Result:
<!DOCTYPE html>
<html>
<body>
<script type="text/vbscript">
Dim famname(5)
famname(0)="Jan Egil"
famname(1)="Tove"
famname(2)="Hege"
famname(3)="Stale"
famname(4)="Kai Jim"
famname(5)="Borge"
For i=0 To 5
document.write(famname(i) & "<br />")
Next
</script>
</body>
</html>
Created By www.ebooktutorials.blogspot.in
<!DOCTYPE html>
<html>
Your Result:
<head>
<script type="text/vbscript">
Sub mySub()
msgbox("This is a Sub procedure")
End Sub
</script>
</head>
<body>
<script type="text/vbscript">
Call mySub()
</script>
<p>A Sub procedure does not return a result.</p>
</body>
</html>
Created By www.ebooktutorials.blogspot.in
<!DOCTYPE html>
<html>
Your Result:
<head>
<script type="text/vbscript">
Function myFunction()
myFunction = "BLUE"
End Function
</script>
</head>
<body>
<script type="text/vbscript">
document.write("My favorite color is " & myFunction())
</script>
<p>A Function procedure can return a result.</p>
</body>
</html>
Created By www.ebooktutorials.blogspot.in
Your Result:
<!DOCTYPE html>
<html>
<head>
<script type="text/vbscript">
Function greeting()
i=hour(time)
If i < 10 Then
document.write("Good morning!")
Else
document.write("Have a nice day!")
End If
End Function
</script>
</head>
<body onload="greeting()">
</body>
</html>
Created By www.ebooktutorials.blogspot.in
Your Result:
<!DOCTYPE html>
<html>
<head>
<script type="text/vbscript">
Function greeting()
i=hour(time)
If i = 10 Then
document.write("Just started...!")
ElseIf i = 11 Then
document.write("Hungry!")
ElseIf i = 12 Then
document.write("Ah, lunch-time!")
ElseIf i = 16 Then
document.write("Time to go home!")
Else
document.write("Unknown")
End If
End Function
</script>
</head>
<body onload="greeting()">
</body>
</html>
Created By www.ebooktutorials.blogspot.in
<!DOCTYPE html>
<html>
<body>
<script type="text/vbscript">
d=weekday(Date)
Your Result:
Select Case d
Case 1
document.write("Sleepy Sunday")
Case 2
document.write("Monday again!")
Case 3
document.write("Just Tuesday!")
Case 4
document.write("Wednesday!")
Case 5
document.write("Thursday...")
Case 6
document.write("Finally Friday!")
Case Else
document.write("Super Saturday!!!!")
End Select
</script>
<p>This example demonstrates the "Select Case" statement.<br />
You will receive a different greeting based on what day it is.<br />
Note that Sunday=1, Monday=2, Tuesday=3, etc.</p>
</body>
</html>
Created By www.ebooktutorials.blogspot.in
<!DOCTYPE html>
<html>
<body>
Your Result:
This example demonstrates a link, when you click on the link it will
take you to W3Schools.com OR to RefsnesData.no. There is a 50%
chance for each of them.
<script type="text/vbscript">
randomize()
r=rnd()
If r>0.5 Then
document.write("<a href='http://www.w3schools.com'>Learn Web
Development!</a>")
Else
document.write("<a href='http://www.refsnesdata.no'>Visit Refsnes Data!</a>")
End If
</script>
<p>
This example demonstrates a link, when you click on the link it will take you to
W3Schools.com OR to
RefsnesData.no. There is a 50% chance for each of them.
</p>
</body>
</html>
Created By www.ebooktutorials.blogspot.in
Your Result:
<!DOCTYPE html>
<html>
<body>
<script type="text/vbscript">
For i = 0 To 5
document.write("The number is " & i & "<br />")
Next
</script>
</body>
</html>
Created By www.ebooktutorials.blogspot.in
Your Result:
<!DOCTYPE html>
<html>
<body>
<script type="text/vbscript">
For i=1 To 6
document.write("<h" & i & ">This is header " & i &
"</h" & i & ">")
Next
</script>
</body>
</html>
Created By www.ebooktutorials.blogspot.in
Your Result:
<!DOCTYPE html>
<html>
<body>
<script type="text/vbscript">
Dim cars(2)
cars(0)="Volvo"
cars(1)="Saab"
cars(2)="BMW"
For Each x In cars
document.write(x & "<br />")
Next
</script>
</body>
</html>
Created By www.ebooktutorials.blogspot.in
Your Result:
<!DOCTYPE html>
<html>
<body>
<script type="text/vbscript">
i=0
Do While i < 10
document.write(i & "<br />")
i=i+1
Loop
</script>
</body>
</html>
Created By www.ebooktutorials.blogspot.in
Your Result:
<!DOCTYPE html>
<html>
<body>
<script type="text/vbscript">
document.write("Today's date is " & Date())
document.write("<br />")
document.write("The time is " & Time())
</script>
</body>
</html>
Created By www.ebooktutorials.blogspot.in
<!DOCTYPE html>
<html>
<body>
Your Result:
Created By www.ebooktutorials.blogspot.in
<!DOCTYPE html>
<html>
<body>
Your Result:
Created By www.ebooktutorials.blogspot.in
Your Result:
<!DOCTYPE html>
<html>
<body>
<script type="text/vbscript">
document.write("Today's day is " & WeekdayName
(Weekday(Date)))
document.write("<br />")
document.write("The month is " & MonthName(Month
(Date)))
</script>
</body>
</html>
Created By www.ebooktutorials.blogspot.in
<!DOCTYPE html>
<html>
<body>
Your Result:
Created By www.ebooktutorials.blogspot.in
<!DOCTYPE html>
<html>
<body>
<script type="text/vbscript">
document.write(DateAdd("d",30,Date()))
</script>
Your Result:
<p>
This example uses <b>DateAdd</b> to calculate a date 30 days from today.
</p>
<p>
Syntax for DateAdd: DateAdd(interval,number,date).
</p>
</body>
</html>
Created By www.ebooktutorials.blogspot.in
<!DOCTYPE html>
<html>
<body>
Your Result:
<script type="text/vbscript">
document.write(FormatDateTime(Date(),vbGeneralDate))
document.write("<br />")
document.write(FormatDateTime(Date(),vbLongDate))
document.write("<br />")
document.write(FormatDateTime(Date(),vbShortDate))
document.write("<br />")
document.write(FormatDateTime(Now(),vbLongTime))
document.write("<br />")
document.write(FormatDateTime(Now(),vbShortTime))
</script>
<p>Syntax for FormatDateTime: FormatDateTime(Date,namedformat).</p>
</body>
</html>
Created By www.ebooktutorials.blogspot.in
Your Result:
<!DOCTYPE html>
<html>
<body>
<script type="text/vbscript">
somedate="10/30/99"
document.write(IsDate(somedate))
</script>
</body>
</html>
Created By www.ebooktutorials.blogspot.in
Your Result:
<!DOCTYPE html>
<html>
<body>
<script type="text/vbscript">
txt="Have a nice day!"
document.write(UCase(txt))
document.write("<br />")
document.write(LCase(txt))
</script>
</body>
</html>
Created By www.ebooktutorials.blogspot.in
Your Result:
<!DOCTYPE html>
<html>
<body>
<script type="text/vbscript">
fname=" Bill "
document.write("Hello" & Trim(fname) & "Gates<br />")
document.write("Hello" & RTrim(fname) &
"Gates<br />")
document.write("Hello" & LTrim(fname) &
"Gates<br />")
</script>
</body>
</html>
Created By www.ebooktutorials.blogspot.in
Your Result:
<!DOCTYPE html>
<html>
<body>
<script type="text/vbscript">
sometext = "Hello Everyone!"
document.write(StrReverse(sometext))
</script>
</body>
</html>
Created By www.ebooktutorials.blogspot.in
Your Result:
<!DOCTYPE html>
<html>
<body>
<script type="text/vbscript">
i = 48.66776677
j = 48.3333333
document.write(Round(i))
document.write("<br />")
document.write(Round(j))
</script>
</body>
</html>
Created By www.ebooktutorials.blogspot.in
Your Result:
<!DOCTYPE html>
<html>
<body>
<script type="text/vbscript">
Randomize()
document.write(Rnd())
</script>
</body>
</html>
Created By www.ebooktutorials.blogspot.in
Your Result:
<!DOCTYPE html>
<html>
<body>
<script type="text/vbscript">
Randomize()
randomNumber=Int(100 * Rnd())
document.write("A random number: <b>" &
randomNumber & "</b>")
</script>
</body>
</html>
Created By www.ebooktutorials.blogspot.in
Your Result:
<!DOCTYPE html>
<html>
<body>
<script type="text/vbscript">
sometext="Welcome to our Web Site!!"
document.write(Left(sometext,5))
document.write("<br />")
document.write(Right(sometext,5))
</script>
</body>
</html>
Created By www.ebooktutorials.blogspot.in
Your Result:
<!DOCTYPE html>
<html>
<body>
<script type="text/vbscript">
sometext="Welcome to this Web!!"
document.write(Replace(sometext, "Web", "Page"))
</script>
</body>
</html>
Created By www.ebooktutorials.blogspot.in
Your Result:
<!DOCTYPE html>
<html>
<body>
<script type="text/vbscript">
sometext="Welcome to our Web Site!!"
document.write(Mid(sometext, 9, 2))
</script>
</body>
</html>
Created By www.ebooktutorials.blogspot.in
VBScript Functions
Previous
Next Chapter
This page contains all the built-in VBScript functions. The page is divided into following sections:
Date/Time functions
Conversion functions
Format functions
Math functions
Array functions
String functions
Other functions
Date/Time Functions
Function
Description
CDate
Converts a valid date and time expression to the variant of subtype Date
Date
DateAdd
DateDiff
DatePart
DateSerial
DateValue
Returns a date
Day
Returns a number that represents the day of the month (between 1 and 31, inclusive)
FormatDateTime
Hour
Returns a number that represents the hour of the day (between 0 and 23, inclusive)
IsDate
Returns a Boolean value that indicates if the evaluated expression can be converted to a date
Minute
Returns a number that represents the minute of the hour (between 0 and 59, inclusive)
Month
Returns a number that represents the month of the year (between 1 and 12, inclusive)
MonthName
Now
Second
Returns a number that represents the second of the minute (between 0 and 59, inclusive)
Time
Timer
TimeSerial
TimeValue
Returns a time
Weekday
Returns a number that represents the day of the week (between 1 and 7, inclusive)
WeekdayName
Year
Conversion Functions
Top
Function
Description
Asc
CBool
CByte
CCur
CDate
Converts a valid date and time expression to the variant of subtype Date
CDbl
Chr
CInt
CLng
CSng
CStr
Hex
Oct
Format Functions
Function
Top
Description
FormatCurrency
Created By www.ebooktutorials.blogspot.in
FormatDateTime
FormatNumber
FormatPercent
Math Functions
Top
Function
Description
Abs
Atn
Cos
Exp
Hex
Int
Fix
Log
Oct
Rnd
Sgn
Sin
Sqr
Tan
Array Functions
Top
Function
Description
Array
Filter
Returns a zero-based array that contains a subset of a string array based on a filter criteria
IsArray
Join
LBound
Split
UBound
String Functions
Top
Function
Description
InStr
Returns the position of the first occurrence of one string within another. The search begins at the first
character of the string
InStrRev
Returns the position of the first occurrence of one string within another. The search begins at the last
character of the string
LCase
Left
Len
LTrim
RTrim
Trim
Removes spaces on both the left and the right side of a string
Mid
Replace
Replaces a specified part of a string with another string a specified number of times
Right
Space
StrComp
Compares two strings and returns a value that represents the result of the comparison
String
StrReverse
Reverses a string
UCase
Other Functions
Content downloaded from www.w3schools.com
Top
Created By www.ebooktutorials.blogspot.in
Function
Description
CreateObject
Eval
GetLocale
GetObject
GetRef
InputBox
Displays a dialog box, where the user can write some input and/or click on a button, and returns the
contents
IsEmpty
Returns a Boolean value that indicates whether a specified variable has been initialized or not
IsNull
Returns a Boolean value that indicates whether a specified expression contains no valid data (Null)
IsNumeric
Returns a Boolean value that indicates whether a specified expression can be evaluated as a number
IsObject
Returns a Boolean value that indicates whether the specified expression is an automation object
LoadPicture
MsgBox
Displays a message box, waits for the user to click a button, and returns a value that indicates which
button the user clicked
RGB
Round
Rounds a number
ScriptEngine
ScriptEngineBuildVersion
ScriptEngineMajorVersion
ScriptEngineMinorVersion
SetLocale
TypeName
VarType
Previous
Next Chapter
Created By www.ebooktutorials.blogspot.in
Syntax
CDate(date)
Parameter
Description
date
Examples
Example 1
How to convert a string to a date:
<script type="text/vbscript">
d=CDate("April 22, 2010")
</script>
Try it yourself
Example 2
How to convert numbers with separators to a date:
<script type="text/vbscript">
d=CDate(#4/22/10#)
</script>
Try it yourself
Example 3
How to use CDate to convert a string to a time object:
<script type="text/vbscript">
d=CDate("3:18:40 AM")
</script>
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
Date
Example
Example (IE Only)
<script type="text/vbscript">
document.write("The current system date is: ")
document.write(Date)
</script>
The output of the code above will be:
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
DateAdd(interval,number,date)
Parameter
Description
interval
number
Required. The number of interval you want to add. Can either be positive, for
dates in the future, or negative, for dates in the past
date
Examples
Example 1
How to use the parameters:
<script type="text/vbscript">
document.write(DateAdd("yyyy",1,"31-Jan-10") & "<br />")
document.write(DateAdd("q",1,"31-Jan-10") & "<br />")
document.write(DateAdd("m",1,"31-Jan-10") & "<br />")
document.write(DateAdd("y",1,"31-Jan-10") & "<br />")
document.write(DateAdd("d",1,"31-Jan-10") & "<br />")
document.write(DateAdd("w",1,"31-Jan-10") & "<br />")
document.write(DateAdd("ww",1,"31-Jan-10") & "<br />")
document.write(DateAdd("h",1,"31-Jan-10 08:50:00") & "<br />")
document.write(DateAdd("n",1,"31-Jan-10 08:50:00") & "<br />")
document.write(DateAdd("s",1,"31-Jan-10 08:50:00") & "<br />")
</script>
The output of the code above will be:
1/31/2011
4/30/2010
2/28/2010
2/1/2010
2/1/2010
2/1/2010
2/7/2010
1/31/2010 9:50:00 AM
1/31/2010 8:51:00 AM
1/31/2010 8:50:01 AM
Try it yourself
Example 2
Subtract one month from January 31, 2010
<script type="text/vbscript">
document.write(DateAdd("m",-1,"31-Jan-10"))
</script>
The output of the code above will be:
Created By www.ebooktutorials.blogspot.in
12/31/2009
Try it yourself
Example 3
Add one day from now:
<script type="text/vbscript">
document.write(DateAdd("d",1,Now()))
</script>
The output of the code above will be:
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
DateDiff(interval,date1,date2[,firstdayofweek[,firstweekofyear]])
Parameter
Description
interval
Required. The interval you want to use to calculate the differences between
date1 and date2
Can take the following values:
yyyy - Year
q - Quarter
m - Month
y - Day of year
d - Day
w - Weekday
ww - Week of year
h - Hour
n - Minute
s - Second
date1,date2
Required. Date expressions. Two dates you want to use in the calculation
firstdayofweek
firstweekofyear
Examples
Example 1
The difference between January 31 2009, and January 31 2010:
<script type="text/vbscript">
fromDate="31-Jan-09 00:00:00"
toDate="31-Jan-10 23:59:00"
document.write(DateDiff("yyyy",fromDate,toDate) & "<br />")
document.write(DateDiff("q",fromDate,toDate) & "<br />")
document.write(DateDiff("m",fromDate,toDate) & "<br />")
document.write(DateDiff("y",fromDate,toDate) & "<br />")
document.write(DateDiff("d",fromDate,toDate) & "<br />")
document.write(DateDiff("w",fromDate,toDate) & "<br />")
document.write(DateDiff("ww",fromDate,toDate) & "<br />")
document.write(DateDiff("h",fromDate,toDate) & "<br />")
document.write(DateDiff("n",fromDate,toDate) & "<br />")
document.write(DateDiff("s",fromDate,toDate) & "<br />")
</script>
The output of the code above will be:
Created By www.ebooktutorials.blogspot.in
1
4
12
365
365
52
53
8783
527039
31622340
Try it yourself
Example 2
How many weeks (start on Monday),
between December 31 2009 and December 31 2012:
<script type="text/vbscript">
fromDate=CDate("2009/12/31")
toDate=CDate("2012/12/31")
document.write(DateDiff("w",fromDate,toDate,vbMonday))
</script>
The output of the code above will be:
156
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
DatePart(interval,date[,firstdayofweek[,firstweekofyear]])
Parameter
Description
interval
date
firstdayofweek
firstweekofyear
Examples
Example 1
Get the month from a date:
<script type="text/vbscript">
d=CDate("2010-02-16")
document.write(DatePart("m",d))
</script>
The output of the code above will be:
2
Try it yourself
Example 2
Get the month we are in:
Created By www.ebooktutorials.blogspot.in
<script type="text/vbscript">
document.write(DatePart("m",Now()))
</script>
The output of the code above will be:
Try it yourself
Example 3
Get the hour:
<script type="text/vbscript">
document.write(DatePart("h",Now())
</script>
The output of the code above will be:
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
DateSerial(year,month,day)
Parameter
Description
year
month
day
Examples
Example 1
<script type="text/vbscript">
document.write(DateSerial(2010,2,3))
</script>
The output of the code above will be:
2/3/2010
Try it yourself
Example 2
Subtract 10 days:
<script type="text/vbscript">
document.write(DateSerial(2010,2,3-10))
</script>
The output of the code above will be:
1/24/2010
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
DateValue(date)
Parameter
Description
date
Required. A date from January 1, 100 through December 31, 9999 or any
expression that can represent a date, a time, or both a date and time
Example
Example
<script type="text/vbscript">
document.write(DateValue("31-Jan-10"))
document.write("<br />")
document.write(DateValue("31-Jan"))
</script>
The output of the code above will be:
1/31/2010
1/31/2010
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
Day(date)
Parameter
Description
date
Example
Example
<script type="text/vbscript">
document.write(Day("2010-02-16"))
</script>
The output of the code above will be:
16
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
FormatDateTime(date,format)
Parameter
Description
date
format
Example
Example
Display a date in different formats:
<script type="text/vbscript">
d=CDate("2010-02-16 13:45")
document.write(FormatDateTime(d) &
document.write(FormatDateTime(d,1)
document.write(FormatDateTime(d,2)
document.write(FormatDateTime(d,3)
document.write(FormatDateTime(d,4)
"<br />")
& "<br />")
& "<br />")
& "<br />")
& "<br />")
</script>
The output of the code above will be:
2/16/2010 1:45:00 PM
Tuesday, February 16, 2010
2/16/2010
1:45:00 PM
13:45
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
Hour(time)
Parameter
Description
time
Examples
Example 1
<script type="text/vbscript">
document.write(Hour("13:45"))
</script>
The output of the code above will be:
13
Try it yourself
Example 2
<script type="text/vbscript">
document.write(Hour(Now()))
</script>
The output of the code above will be:
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
IsDate(expression)
Parameter
Description
expression
Example 1
Legal dates:
<script type="text/vbscript">
document.write(IsDate("April 22, 1947"))
document.write("<br />")
document.write(IsDate(#01/31/10#))
</script>
The output of the code above will be:
True
True
Try it yourself
Example 2
Illegal dates:
<script type="text/vbscript">
document.write(IsDate("#01/31/10#"))
document.write("<br />")
document.write(IsDate("52/17/2010"))
document.write("<br />")
document.write(IsDate("Hello World!"))
</script>
The output of the code above will be:
False
False
False
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
Minute(time)
Parameter
Description
time
Examples
Example 1
<script type="text/vbscript">
document.write(Minute("13:45"))
</script>
The output of the code above will be:
45
Try it yourself
Example 2
<script type="text/vbscript">
document.write(Minute(Now()))
</script>
The output of the code above will be:
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
Month(date)
Parameter
Description
date
Example
Example
<script type="text/vbscript">
document.write(Month("2010-02-16"))
</script>
The output of the code above will be:
2
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
MonthName(month[,abbreviate])
Parameter
Description
month
abbreviate
Examples
Example 1
Get the name of the 8th month:
<script type="text/vbscript">
document.write(MonthName(8))
</script>
The output of the code above will be:
August
Try it yourself
Example 2
Get the short name of the 8th month:
<script type="text/vbscript">
document.write(MonthName(8,True))
</script>
The output of the code above will be:
Aug
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
Now
Example
Example (IE Only)
<script type="text/vbscript">
document.write("The current system date and time is: ")
document.write(Now)
</script>
The output of the code above will be:
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
Second(time)
Parameter
Description
time
Examples
Example 1
<script type="text/vbscript">
document.write(Second("13:45:21"))
</script>
The output of the code above will be:
21
Try it yourself
Example 2
<script type="text/vbscript">
document.write(Second(Now()))
</script>
The output of the code above will be:
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
Time
Example
Example (IE Only)
<script type="text/vbscript">
document.write("The current system time is: ")
document.write(Time)
</script>
The output of the code above will be:
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
Timer
Example
Example (IE Only)
<script type="text/vbscript">
document.write("Number of seconds and milliseconds since 12:00 AM: ")
document.write(Timer)
</script>
The output of the code above will be:
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
TimeSerial(hour,minute,second)
Parameter
Description
hour
minute
second
Example
Example
<script type="text/vbscript">
document.write(TimeSerial(23,2,3) & "<br />")
document.write(TimeSerial(0,9,11) & "<br />")
document.write(TimeSerial(14+2,9-2,1-1))
</script>
The output of the code above will be:
11:02:03 PM
12:09:11 AM
4:07:00 PM
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
TimeValue(time)
Parameter
Description
time
Required. A time from 0:00:00 (12:00:00 A.M.) to 23:59:59 (11:59:59 P.M.) or any expression that represents a time in
that range
Example
Example
<script type="text/vbscript">
document.write(TimeValue("5:55:59 PM") & "<br />")
document.write(TimeValue(#5:55:59 PM#) & "<br />")
document.write(TimeValue("15:34"))
</script>
The output of the code above will be:
5:55:59 PM
5:55:59 PM
3:34:00 PM
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
Weekday(date[,firstdayofweek])
Parameter
Description
date
firstdayofweek
=
=
=
=
=
=
=
=
Example
Example
<script type="text/vbscript">
document.write(Weekday("2010-02-16",1)
document.write(Weekday("2010-02-16",2)
document.write(Weekday("2010-02-16",3)
document.write(Weekday("2010-02-16",4)
document.write(Weekday("2010-02-16",5)
document.write(Weekday("2010-02-16",6)
&
&
&
&
&
&
"<br
"<br
"<br
"<br
"<br
"<br
/>")
/>")
/>")
/>")
/>")
/>")
</script>
The output of the code above will be:
3
2
1
7
6
5
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
WeekdayName(weekday[,abbreviate[,firstdayofweek]])
Parameter
Description
weekday
abbreviate
firstdayofweek
Examples
Example 1
Get the name of the 3rd day of the week:
<script type="text/vbscript">
document.write(WeekdayName(3))
</script>
The output of the code above will be:
Tuesday
Try it yourself
Example 2
Get the short name of the 3rd day of the week:
<script type="text/vbscript">
document.write(WeekdayName(3,True))
</script>
The output of the code above will be:
Tue
Try it yourself
Example 3
Get the name of the 3rd day of the week, where the first day is monday:
<script type="text/vbscript">
document.write(WeekdayName(3,False,2))
</script>
Created By www.ebooktutorials.blogspot.in
The output of the code above will be:
Wednesday
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
Year(date)
Parameter
Description
date
Example
Example
<script type="text/vbscript">
document.write(Year("2010-02-16"))
</script>
The output of the code above will be:
2010
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
Asc(string)
Parameter
Description
string
Examples
Example 1
<script type="text/vbscript">
document.write(Asc("A")
document.write(Asc("a")
document.write(Asc("F")
document.write(Asc("f")
document.write(Asc("2")
document.write(Asc("#")
&
&
&
&
&
&
"<br
"<br
"<br
"<br
"<br
"<br
/>")
/>")
/>")
/>")
/>")
/>")
</script>
The output of the code above will be:
65
97
70
102
50
35
Try it yourself
Example 2
Asc returns the ANSI code of only the first character in a string:
<script type="text/vbscript">
document.write(Asc("W") & "<br />")
document.write(Asc("W3Schools.com"))
</script>
The output of the code above will be:
87
87
Try it yourself
Example 3
How to return the ANSI code of all the characters in a string:
<script type="text/vbscript">
txt="W3schools.com"
for i=1 to len(txt)
document.write(Asc(mid(txt,i,1)) & "<br />")
next
</script>
The output of the code above will be:
87
51
115
Created By www.ebooktutorials.blogspot.in
99
104
111
111
108
115
46
99
111
109
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
CBool(expression)
Parameter
Description
expression
Required. Any valid expression. A nonzero value returns True, zero returns False.
A run-time error occurs if the expression can not be interpreted as a numeric
value
Example
Example
<script type="text/vbscript">
document.write(CBool(5) & "<br />")
document.write(CBool(0) & "<br />")
document.write(CBool(-5) & "<br />")
</script>
The output of the code above will be:
True
False
True
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
CByte(expression)
Parameter
Description
expression
Example
Example
<script type="text/vbscript">
document.write(CByte(0) & "<br />")
document.write(CByte(56.8) & "<br />")
document.write(CByte(123.2) & "<br />")
document.write(CByte(255) & "<br />")
</script>
The output of the code above will be:
0
57
123
255
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
CCur(expression)
Parameter
Description
expression
Examples
Example 1
<script type="text/vbscript">
document.write(CCur(30) & "<br />")
</script>
The output of the code above will be:
30
Try it yourself
Example 2
Note that CCur rounds off to 4 decimals:
<script type="text/vbscript">
document.write(CCur(5.9555555555555) & "<br />")
</script>
The output of the code above will be:
5.9556
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
CDate(date)
Parameter
Description
date
Examples
Example 1
How to convert a string to a date:
<script type="text/vbscript">
d=CDate("April 22, 2010")
</script>
Try it yourself
Example 2
How to convert numbers with separators to a date:
<script type="text/vbscript">
d=CDate(#4/22/10#)
</script>
Try it yourself
Example 3
How to use CDate to convert a string to a time object:
<script type="text/vbscript">
d=CDate("3:18:40 AM")
</script>
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
CDbl(expression)
Parameter
Description
expression
Examples
Example 1
<script type="text/vbscript">
document.write(CDbl(134.345) & "<br />")
</script>
The output of the code above will be:
134.345
Try it yourself
Example 2
<script type="text/vbscript">
document.write(CDbl(14111111113353355.345455) & "<br />")
</script>
The output of the code above will be:
1.41111111133534E+16
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
Chr(charcode)
Parameter
Description
charcode
Examples
Example 1
<script type="text/vbscript">
document.write(Chr(65)
document.write(Chr(66)
document.write(Chr(67)
document.write(Chr(97)
document.write(Chr(98)
document.write(Chr(99)
&
&
&
&
&
&
"<br
"<br
"<br
"<br
"<br
"<br
/>")
/>")
/>")
/>")
/>")
/>")
</script>
The output of the code above will be:
A
B
C
a
b
c
Try it yourself
Example 2
<script type="text/vbscript">
document.write(Chr(34)
document.write(Chr(35)
document.write(Chr(36)
document.write(Chr(37)
&
&
&
&
"<br
"<br
"<br
"<br
/>")
/>")
/>")
/>")
</script>
The output of the code above will be:
"
#
$
%
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
CInt(expression)
Parameter
Description
expression
Example
Example
<script type="text/vbscript">
document.write(CInt("300") & "<br />")
document.write(CInt(36.75) & "<br />")
document.write(CInt(-67) & "<br />")
</script>
The output of the code above will be:
300
37
-67
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
CLng(expression)
Parameter
Description
expression
Example
Example
<script type="text/vbscript">
document.write(CLng("300000") & "<br />")
document.write(CLng(1536.750) & "<br />")
document.write(CLng(-6700000) & "<br />")
</script>
The output of the code above will be:
300000
1537
-6700000
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
CSng(expression)
Parameter
Description
expression
Example
Example
<script type="text/vbscript">
document.write(CSng("300000") & "<br />")
document.write(CSng(1536.75263541) & "<br />")
document.write(CSng(-6700000) & "<br />")
</script>
The output of the code above will be:
300000
1536.753
-6700000
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
CStr(expression)
Parameter
Description
expression
Example
Example
<script type="text/vbscript">
document.write(CStr("300000") & "<br />")
document.write(CStr(#10-05-25#) & "<br />")
</script>
The output of the code above will be:
300000
10/5/2025
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
Hex(number)
Parameter
Description
number
Example
Example
<script type="text/vbscript">
document.write(Hex(3) & "<br />")
document.write(Hex(5) & "<br />")
document.write(Hex(9) & "<br />")
document.write(Hex(10) & "<br />")
document.write(Hex(11) & "<br />")
document.write(Hex(12) & "<br />")
document.write(Hex(400) & "<br />")
document.write(Hex(459) & "<br />")
document.write(Hex(460) & "<br />")
</script>
The output of the code above will be:
3
5
9
A
B
C
190
1CB
1CC
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
Oct(number)
Parameter
Description
number
Example
Example
<script type="text/vbscript">
document.write(Oct(3) & "<br />")
document.write(Oct(5) & "<br />")
document.write(Oct(9) & "<br />")
document.write(Oct(10) & "<br />")
document.write(Oct(11) & "<br />")
document.write(Oct(12) & "<br />")
document.write(Oct(400) & "<br />")
document.write(Oct(459) & "<br />")
document.write(Oct(460) & "<br />")
</script>
The output of the code above will be:
3
5
11
12
13
14
620
713
714
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
FormatCurrency(Expression[,NumDigAfterDec[,
IncLeadingDig[,UseParForNegNum[,GroupDig]]]])
Parameter
Description
expression
NumDigAfterDec
Optional. Indicates how many places to the right of the decimal are displayed.
Default is -1 (the computer's regional settings are used)
IncLeadingDig
UseParForNegNum
GroupDig
Optional. Indicates whether or not numbers are grouped using the group
delimiter specified in the computer's regional settings:
-2 = TristateUseDefault - Use the computer's regional settings
-1 = TristateTrue - True
0 = TristateFalse - False
Examples
Example 1
<script type="text/vbscript">
document.write(FormatCurrency(20000))
</script>
The output of the code above will be:
$20,000.00
Try it yourself
Example 2
Setting number of decimals:
<script type="text/vbscript">
document.write(FormatCurrency(20000,2) & "<br />")
document.write(FormatCurrency(20000,5))
</script>
The output of the code above will be:
$20,000.00
$20,000.00000
Try it yourself
Created By www.ebooktutorials.blogspot.in
Example 3
Fractional values with or without a leading zero:
<script type="text/vbscript">
document.write(FormatCurrency(.20,,0) & "<br />")
document.write(FormatCurrency(.20,,-1))
</script>
The output of the code above will be:
$.20
$0.20
Try it yourself
Example 4
Negative values inside parentheses or not:
<script type="text/vbscript">
document.write(FormatCurrency(-50,,,0) & "<br />")
document.write(FormatCurrency(-50,,,-1))
</script>
The output of the code above will be:
-$50.00
($50.00)
Try it yourself
Example 5
Grouping a million dollars - or not:
<script type="text/vbscript">
document.write(FormatCurrency(1000000,,,,0) & "<br />")
document.write(FormatCurrency(1000000,,,,-1))
</script>
The output of the code above will be:
$1000000.00
$1,000,000.00
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
FormatDateTime(date,format)
Parameter
Description
date
format
Example
Example
Display a date in different formats:
<script type="text/vbscript">
d=CDate("2010-02-16 13:45")
document.write(FormatDateTime(d) &
document.write(FormatDateTime(d,1)
document.write(FormatDateTime(d,2)
document.write(FormatDateTime(d,3)
document.write(FormatDateTime(d,4)
"<br />")
& "<br />")
& "<br />")
& "<br />")
& "<br />")
</script>
The output of the code above will be:
2/16/2010 1:45:00 PM
Tuesday, February 16, 2010
2/16/2010
1:45:00 PM
13:45
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
FormatNumber(Expression[,NumDigAfterDec[,
IncLeadingDig[,UseParForNegNum[,GroupDig]]]])
Parameter
Description
expression
NumDigAfterDec
Optional. Indicates how many places to the right of the decimal are displayed.
Default is -1 (the computer's regional settings are used)
IncLeadingDig
UseParForNegNum
GroupDig
Optional. Indicates whether or not numbers are grouped using the group
delimiter specified in the computer's regional settings:
-2 = TristateUseDefault - Use the computer's regional settings
-1 = TristateTrue - True
0 = TristateFalse - False
Examples
Example 1
<script type="text/vbscript">
document.write(FormatNumber(20000))
</script>
The output of the code above will be:
20,000.00
Try it yourself
Example 2
Setting number of decimals:
<script type="text/vbscript">
document.write(FormatNumber(20000,2) & "<br />")
document.write(FormatNumber(20000,5))
</script>
The output of the code above will be:
20,000.00
20,000.00000
Try it yourself
Example 3
Created By www.ebooktutorials.blogspot.in
Fractional values with or without a leading zero:
<script type="text/vbscript">
document.write(FormatNumber(.20,,0) & "<br />")
document.write(FormatNumber(.20,,-1))
</script>
The output of the code above will be:
.20
0.20
Try it yourself
Example 4
Negative values inside parentheses or not:
<script type="text/vbscript">
document.write(FormatNumber(-50,,,0) & "<br />")
document.write(FormatNumber(-50,,,-1))
</script>
The output of the code above will be:
-50.00
(50.00)
Try it yourself
Example 5
Grouping numbers - or not:
<script type="text/vbscript">
document.write(FormatNumber(1000000,,,,0) & "<br />")
document.write(FormatNumber(1000000,,,,-1))
</script>
The output of the code above will be:
1000000.00
1,000,000.00
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
FormatPercent(Expression[,NumDigAfterDec[,
IncLeadingDig[,UseParForNegNum[,GroupDig]]]])
Parameter
Description
expression
NumDigAfterDec
Optional. Indicates how many places to the right of the decimal are displayed.
Default is -1 (the computer's regional settings are used)
IncLeadingDig
UseParForNegNum
GroupDig
Optional. Indicates whether or not numbers are grouped using the group
delimiter specified in the computer's regional settings:
-2 = TristateUseDefault - Use the computer's regional settings
-1 = TristateTrue - True
0 = TristateFalse - False
Example 1
'How many percent is 6 of 345?
document.write(FormatPercent(6/345))
Output:
1.74%
Example 2
'How many percent is 6 of 345?
document.write(FormatPercent(6/345,1))
Output:
1.7%
Created By www.ebooktutorials.blogspot.in
Syntax
Abs(number)
Parameter
Description
number
Examples
Example 1
<script type="text/vbscript">
document.write(Abs(1) & "<br />")
document.write(Abs(-1))
</script>
The output of the code above will be:
1
1
Try it yourself
Example 2
<script type="text/vbscript">
document.write(Abs(48.4) & "<br />")
document.write(Abs(-48.4))
</script>
The output of the code above will be:
48.4
48.4
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
Atn(number)
Parameter
Description
number
Examples
Example 1
<script type="text/vbscript">
document.write(Atn(89) & "<br />")
document.write(Atn(8.9))
</script>
The output of the code above will be:
1.55956084453693
1.45890606062322
Try it yourself
Example 2
Calculate the value of pi:
<script type="text/vbscript">
Dim pi
pi=4*Atn(1)
document.write(pi)
</script>
The output of the code above will be:
3.14159265358979
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
Cos(number)
Parameter
Description
number
Example
Example
<script type="text/vbscript">
document.write(Cos(50.0) & "<br />")
document.write(Cos(-50.0))
</script>
The output of the code above will be:
0.964966028492113
0.964966028492113
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
Exp(number)
Parameter
Description
number
Example
Example
<script type="text/vbscript">
document.write(Exp(6.7) & "<br />")
document.write(Exp(-6.7))
</script>
The output of the code above will be:
812.405825167543
1.23091190267348E-03
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
Hex(number)
Parameter
Description
number
Example
Example
<script type="text/vbscript">
document.write(Hex(3) & "<br />")
document.write(Hex(5) & "<br />")
document.write(Hex(9) & "<br />")
document.write(Hex(10) & "<br />")
document.write(Hex(11) & "<br />")
document.write(Hex(12) & "<br />")
document.write(Hex(400) & "<br />")
document.write(Hex(459) & "<br />")
document.write(Hex(460) & "<br />")
</script>
The output of the code above will be:
3
5
9
A
B
C
190
1CB
1CC
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
Int(number)
Parameter
Description
number
Examples
Example 1
<script type="text/vbscript">
document.write(Int(6.83227) & "<br />")
document.write(Int(6.23443))
</script>
The output of the code above will be:
6
6
Try it yourself
Example 2
<script type="text/vbscript">
document.write(Int(-6.13443) & "<br />")
document.write(Int(-6.93443))
</script>
The output of the code above will be:
-7
-7
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
Fix(number)
Parameter
Description
number
Examples
Example 1
<script type="text/vbscript">
document.write(Fix(6.83227) & "<br />")
document.write(Fix(6.23443))
</script>
The output of the code above will be:
6
6
Try it yourself
Example 2
<script type="text/vbscript">
document.write(Fix(-6.13443) & "<br />")
document.write(Fix(-6.93443))
</script>
The output of the code above will be:
-6
-6
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
Log(number)
Parameter
Description
number
Example
Example
<script type="text/vbscript">
document.write(Log(38.256783227))
</script>
The output of the code above will be:
3.64432088381777
Try it yourself
Created By www.ebooktutorials.blogspot.in
WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Best Hosting Coupons
The Oct function returns a string that represents the octal value of a specified number.
Note: If number is not already a whole number, it is rounded to the nearest whole number before being
evaluated.
Syntax
UK Reseller Hosting
Cloud Hosting
Top Web Hosting
$3.98 Unlimited Hosting
Premium Website Design
Oct(number)
WEB BUILDING
XML Editor - Free Trial!
Parameter
Description
number
If number is:
Null - then the Oct function returns Null.
Empty - then the Oct function returns zero (0).
Any other number - then the Oct function returns up to 11 octal characters.
W3SCHOOLS EXAMS
Get Certified in:
HTML, CSS, JavaScript,
XML, PHP, and ASP
Example
W3SCHOOLS BOOKS
Example
New Books:
HTML, CSS
JavaScript, and Ajax
<script type="text/vbscript">
document.write(Oct(3) & "<br />")
document.write(Oct(5) & "<br />")
document.write(Oct(9) & "<br />")
document.write(Oct(10) & "<br />")
document.write(Oct(11) & "<br />")
document.write(Oct(12) & "<br />")
document.write(Oct(400) & "<br />")
document.write(Oct(459) & "<br />")
document.write(Oct(460) & "<br />")
STATISTICS
Browser Statistics
Browser OS
Browser Display
SHARE THIS PAGE
Share with
</script>
The output of the code above will be:
3
5
11
12
13
14
620
713
714
Try it yourself
Complete VBScript Reference
REPORT
ERROR
HOME
TOP
FORUM
ABOUT
Created By www.ebooktutorials.blogspot.in
Created By www.ebooktutorials.blogspot.in
Syntax
Rnd[(number)]
Parameter
Description
number
Examples
Example 1
A random number:
<script type="text/vbscript">
document.write(Rnd)
</script>
Note that you will get the same number every time. To avoid this, use the Randomize statement like
in Example 2
The output of the code above will be:
0.7055475
Try it yourself
Example 2
To avoid getting the same number every time, like in Example 1, use the Randomize statement:
<script type="text/vbscript">
Randomize
document.write(Rnd)
</script>
The output of the code above will be:
0.4758112
Try it yourself
Example 3
Here is how to produce random integers in a given range:
<script type="text/vbscript">
Dim max,min
max=100
min=1
Randomize
document.write(Int((max-min+1)*Rnd+min))
</script>
Created By www.ebooktutorials.blogspot.in
The output of the code above will be:
71
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
Sgn(number)
Parameter
Description
number
Example
Example
<script type="text/vbscript">
document.write(Sgn(15) & "<br />")
document.write(Sgn(-5.67) & "<br />")
document.write(Sgn(0))
</script>
The output of the code above will be:
1
-1
0
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
Sin(number)
Parameter
Description
number
Example
Example
<script type="text/vbscript">
document.write(Sin(47) & "<br />")
document.write(Sin(-47))
</script>
The output of the code above will be:
0.123573122745224
-0.123573122745224
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
Sqr(number)
Parameter
Description
number
Example
Example
<script type="text/vbscript">
document.write(Sqr(9) & "<br />")
document.write(Sqr(0) & "<br />")
document.write(Sqr(47))
</script>
The output of the code above will be:
3
0
6.85565460040104
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
Tan(number)
Parameter
Description
number
Example
Example
<script type="text/vbscript">
document.write(Tan(40) & "<br />")
document.write(Tan(-40))
</script>
The output of the code above will be:
-1.1172149309239
1.1172149309239
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
Array(arglist)
Parameter
Description
arglist
Examples
Example 1
<script type="text/vbscript">
a=Array(5,10,15,20)
document.write(a(3))
</script>
The output of the code above will be:
20
Try it yourself
Example 2
<script type="text/vbscript">
a=Array(5,10,15,20)
document.write(a(0))
</script>
The output of the code above will be:
5
Try it yourself
Example 3
Looping through all items in an array:
<script type="text/vbscript">
a=Array(5,10,15,20)
for each x in a
document.write(x & "<br />")
next
</script>
The output of the code above will be:
5
10
15
20
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
Filter(inputstrings,value[,include[,compare]])
Parameter
Description
inputstrings
value
include
Optional. A Boolean value that indicates whether to return the substrings that
include or exclude value. True returns the subset of the array that contains value
as a substring. False returns the subset of the array that does not contain value
as a substring. Default is True.
compare
Examples
Example 1
Filter: items that contains "S"
<script type="text/vbscript">
a=Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
b=Filter(a,"S")
for each x in b
document.write(x & "<br />")
next
</script>
The output of the code above will be:
Sunday
Saturday
Try it yourself
Example 2
Filter: items that does NOT contain "S" (include=False):
<script type="text/vbscript">
a=Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
b=Filter(a,"S",False)
for each x in b
document.write(x & "<br />")
next
</script>
The output of the code above will be:
Monday
Tuesday
Wednesday
Thursday
Friday
Created By www.ebooktutorials.blogspot.in
Try it yourself
Example 3
Filter: items that contains "S", with a textual comparison (compare=1):
<script type="text/vbscript">
a=Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
b=Filter(a,"S",True,1)
for each x in b
document.write(x & "<br />")
next
</script>
The output of the code above will be:
Sunday
Tuesday
Wednesday
Thursday
Saturday
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
IsArray(variable)
Parameter
Description
variable
Examples
Example 1
<script type="text/vbscript">
days=Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat")
document.write(IsArray(days))
</script>
The output of the code above will be:
True
Try it yourself
Example 2
<script type="text/vbscript">
Dim a(5)
a(0)="Saturday"
a(1)="Sunday"
a(2)="Monday"
a(3)="Tuesday"
a(4)="Wednesday"
document.write(IsArray(a))
</script>
The output of the code above will be:
True
Try it yourself
Example 3
<script type="text/vbscript">
a="Saturday"
document.write(IsArray(a))
</script>
The output of the code above will be:
False
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
Join(list[,delimiter])
Parameter
Description
list
delimiter
Optional. The character(s) used to separate the substrings in the returned string.
Default is the space character
Example
Example
Separating items in an array, with and without using the delimeter parameter:
<script type="text/vbscript">
days=Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat")
document.write(Join(days) & "<br />")
document.write(Join(days,",") & "<br />")
document.write(Join(days," ### "))
</script>
The output of the code above will be:
Created By www.ebooktutorials.blogspot.in
Syntax
LBound(arrayname[,dimension])
Parameter
Description
arrayname
dimension
Examples
Example 1
<script type="text/vbscript">
days=Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat")
document.write(LBound(days) & "<br />")
document.write(UBound(days) & "<br />")
</script>
The output of the code above will be:
0
6
Try it yourself
Example 2
A two dimensional array:
<script type="text/vbscript">
Dim food(2,3)
food(0,0)="Apple"
food(0,1)="Banana"
food(0,2)="Orange"
food(0,3)="Lemon"
food(1,0)="Pizza"
food(1,1)="Hamburger"
food(1,2)="Spaghetti"
food(1,3)="Meatloaf"
food(2,0)="Cake"
food(2,1)="Cookie"
food(2,2)="Icecream"
food(2,3)="Chocolate"
document.write(LBound(food,1)
document.write(UBound(food,1)
document.write(LBound(food,2)
document.write(UBound(food,2)
&
&
&
&
"<br
"<br
"<br
"<br
/>")
/>")
/>")
/>")
</script>
The output of the code above will be:
0
2
0
3
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
Split(expression[,delimiter[,count[,compare]]])
Parameter
Description
expression
delimiter
Optional. A string character used to identify substring limits. Default is the space
character
count
compare
Examples
Example 1
<script type="text/vbscript">
a=Split("W3Schools is my favourite website")
for each x in a
document.write(x & "<br />")
next
</script>
The output of the code above will be:
W3Schools
is
my
favourite
website
Try it yourself
Example 2
Splitting the text using the delimeter parameter
<script type="text/vbscript">
a=Split("Brown cow, White horse, Yellow chicken",",")
for each x in a
document.write(x & "<br />")
next
</script>
The output of the code above will be:
Brown cow
White horse
Yellow chicken
Try it yourself
Example 3
Splitting the text using the delimeter parameter, and the count parameter
Created By www.ebooktutorials.blogspot.in
<script type="text/vbscript">
a=Split("W3Schools is my favourite website"," ",2)
for each x in a
document.write(x & "<br />")
next
</script>
The output of the code above will be:
W3Schools
is my favourite website
Try it yourself
Example 4
Splitting the text using the delimeter parameter with a textual comparison:
<script type="text/vbscript">
a=Split("SundayMondayTuesdayWEDNESDAYThursdayFridaySaturday","day",-1,1)
for each x in a
document.write(x & "<br />")
next
</script>
The output of the code above will be:
Sun
Mon
Tues
WEDNES
Thurs
Fri
Satur
Try it yourself
Example 5
Splitting the text using the delimeter parameter with a binary comparison:
<script type="text/vbscript">
a=Split("SundayMondayTuesdayWEDNESDAYThursdayFridaySaturday","day",-1,0)
for each x in a
document.write(x & "<br />")
next
</script>
The output of the code above will be:
Sun
Mon
Tues
WEDNESDAYThurs
Fri
Satur
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
UBound(arrayname[,dimension])
Parameter
Description
arrayname
dimension
Examples
Example 1
<script type="text/vbscript">
days=Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat")
document.write(LBound(days) & "<br />")
document.write(UBound(days) & "<br />")
</script>
The output of the code above will be:
0
6
Try it yourself
Example 2
A two dimensional array:
<script type="text/vbscript">
Dim food(2,3)
food(0,0)="Apple"
food(0,1)="Banana"
food(0,2)="Orange"
food(0,3)="Lemon"
food(1,0)="Pizza"
food(1,1)="Hamburger"
food(1,2)="Spaghetti"
food(1,3)="Meatloaf"
food(2,0)="Cake"
food(2,1)="Cookie"
food(2,2)="Icecream"
food(2,3)="Chocolate"
document.write(LBound(food,1)
document.write(UBound(food,1)
document.write(LBound(food,2)
document.write(UBound(food,2)
&
&
&
&
"<br
"<br
"<br
"<br
/>")
/>")
/>")
/>")
</script>
The output of the code above will be:
0
2
0
3
Try it yourself
Created By www.ebooktutorials.blogspot.in
string1
string1
string2
string2
string2
string2
start >
Syntax
InStr([start,]string1,string2[,compare])
Parameter
Description
start
Optional. Specifies the starting position for each search. The search begins at the first character position (1) by default. This
parameter is required if compare is specified
string1
string2
compare
Examples
Example 1
<script type="text/vbscript">
txt="This is a beautiful day!"
document.write(InStr(txt,"beautiful"))
</script>
The output of the code above will be:
11
Try it yourself
Example 2
Finding the letter "i", using different starting positions:
<script type="text/vbscript">
txt="This is a beautiful day!"
document.write(InStr(1,txt,"i") & "<br />")
document.write(InStr(7,txt,"i") & "<br />")
</script>
The output of the code above will be:
3
16
Try it yourself
Example 3
Finding the letter "t", with textual, and binary, comparison:
Created By www.ebooktutorials.blogspot.in
<script type="text/vbscript">
txt="This is a beautiful day!"
document.write(InStr(1,txt,"t",1) & "<br />")
document.write(InStr(1,txt,"t",0) & "<br />")
</script>
The output of the code above will be:
1
15
Try it yourself
Created By www.ebooktutorials.blogspot.in
string1
string1
string2
string2
string2
string2
start >
Syntax
InStrRev(string1,string2[,start[,compare]])
Parameter
Description
string1
string2
start
Optional. Specifies the starting position for each search. The search begins at the last character position by default (-1)
compare
Examples
Example 1
<script type="text/vbscript">
txt="This is a beautiful day!"
document.write(InStrRev(txt,"beautiful"))
</script>
The output of the code above will be:
11
Try it yourself
Example 2
Finding the letter "i", using different starting positions:
<script type="text/vbscript">
txt="This is a beautiful day!"
document.write(InStrRev(txt,"i",-1) & "<br />")
document.write(InStrRev(txt,"i",7) & "<br />")
</script>
The output of the code above will be:
16
6
Try it yourself
Example 3
Finding the letter "T", with textual, and binary, comparison:
Created By www.ebooktutorials.blogspot.in
<script type="text/vbscript">
txt="This is a beautiful day!"
document.write(InStrRev(txt,"T",-1,1) & "<br />")
document.write(InStrRev(txt,"T",-1,0) & "<br />")
</script>
The output of the code above will be:
15
1
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
LCase(string)
Parameter
Description
string
Examples
Example 1
<script type="text/vbscript">
txt="THIS IS A BEAUTIFUL DAY!"
document.write(LCase(txt))
</script>
The output of the code above will be:
Example 2
<script type="text/vbscript">
txt="This is a BEAUTIFUL day!"
document.write(LCase(txt))
</script>
The output of the code above will be:
Created By www.ebooktutorials.blogspot.in
Syntax
Left(string,length)
Parameter
Description
string
length
Examples
Example 1
<script type="text/vbscript">
txt="This is a beautiful day!"
document.write(Left(txt,15))
</script>
The output of the code above will be:
This is a beaut
Try it yourself
Example 2
Return the whole string:
<script type="text/vbscript">
txt="This is a beautiful day!"
x=Len(txt)
document.write(Left(txt,x))
</script>
The output of the code above will be:
Created By www.ebooktutorials.blogspot.in
Syntax
Len(string)
Parameter
Description
string
A string expression
Examples
Example 1
<script type="text/vbscript">
txt="This is a beautiful day!"
document.write(Len(txt))
</script>
The output of the code above will be:
24
Try it yourself
Example 2
You can also put the string directly into the Len function:
<script type="text/vbscript">
document.write(Len("This is a beautiful day!"))
</script>
The output of the code above will be:
24
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
LTrim(string)
Parameter
Description
string
Example
Example
<script type="text/vbscript">
fname=" Jack "
document.write("Hello" & LTrim(fname) & "and welcome.")
</script>
The output of the code above will be:
Created By www.ebooktutorials.blogspot.in
Syntax
RTrim(string)
Parameter
Description
string
Example
Example
<script type="text/vbscript">
fname=" Jack "
document.write("Hello" & RTrim(fname) & "and welcome.")
</script>
The output of the code above will be:
Created By www.ebooktutorials.blogspot.in
Syntax
Trim(string)
Parameter
Description
string
Example
Example
<script type="text/vbscript">
fname=" Jack "
document.write("Hello" & Trim(fname) & "and welcome.")
</script>
The output of the code above will be:
HelloJackand welcome.
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
Mid(string,start[,length])
Parameter
Description
string
start
Required. Specifies the starting position. If set to greater than the number of
characters in string, it returns an empty string ("")
length
Examples
Example 1
Return 1 character, starting at postion 1:
<script type="text/vbscript">
txt="This is a beautiful day!"
document.write(Mid(txt,1,1))
</script>
The output of the code above will be:
T
Try it yourself
Example 2
Return 15 characters, starting at postion 1:
<script type="text/vbscript">
txt="This is a beautiful day!"
document.write(Mid(txt,1,15))
</script>
The output of the code above will be:
This is a beaut
Try it yourself
Example 3
Return all characters, starting at postion 1:
<script type="text/vbscript">
txt="This is a beautiful day!"
document.write(Mid(txt,1))
</script>
The output of the code above will be:
Created By www.ebooktutorials.blogspot.in
Example 4
Return all characters, starting at postion 12:
<script type="text/vbscript">
txt="This is a beautiful day!"
document.write(Mid(txt,12))
</script>
The output of the code above will be:
eautiful day!
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
Replace(string,find,replacewith[,start[,count[,compare]]])
Parameter
Description
string
find
replacewith
start
Optional. Specifies the start position. Default is 1. All characters before the start
position will be removed.
count
compare
Examples
Example 1
Replace the word "beautiful" with "fantastic":
<script type="text/vbscript">
txt="This is a beautiful day!"
document.write(Replace(txt,"beautiful","fantastic"))
</script>
The output of the code above will be:
Example 2
Replace the letter "i" with "##":
<script type="text/vbscript">
txt="This is a beautiful day!"
document.write(Replace(txt,"i","##"))
</script>
The output of the code above will be:
Example 3
Replace the letter "i" with "##", starting at position 15:
Note that all characters before position 15 are removed.
<script type="text/vbscript">
Created By www.ebooktutorials.blogspot.in
txt="This is a beautiful day!"
document.write(Replace(txt,"i","##",15))
</script>
The output of the code above will be:
t##ful day!
Try it yourself
Example 4
Replace the 2 first occurences of the letter "i" with "##", starting at position 1:
<script type="text/vbscript">
txt="This is a beautiful day!"
document.write(Replace(txt,"i","##",1,2))
</script>
The output of the code above will be:
Example 5
Replace the letter "t" with "##", with textual, and binary, comparison:
<script type="text/vbscript">
txt="This is a beautiful day!"
document.write(Replace(txt,"t","##",1,-1,1) & "<br />")
document.write(Replace(txt,"t","##",1,-1,0))
</script>
The output of the code above will be:
Created By www.ebooktutorials.blogspot.in
Syntax
Right(string,length)
Parameter
Description
string
length
Examples
Example 1
<script type="text/vbscript">
txt="This is a beautiful day!"
document.write(Right(txt,10))
</script>
The output of the code above will be:
tiful day!
Try it yourself
Example 2
Return the whole string:
<script type="text/vbscript">
txt="This is a beautiful day!"
x=Len(txt)
document.write(Right(txt,x))
</script>
The output of the code above will be:
Created By www.ebooktutorials.blogspot.in
Syntax
Space(number)
Parameter
Description
number
Example 1
Dim txt
txt=Space(10)
document.write(txt)
Output:
""
Created By www.ebooktutorials.blogspot.in
Syntax
StrComp(string1,string2[,compare])
Parameter
Description
string1
string2
compare
Example 1
document.write(StrComp("VBScript","VBScript"))
Output:
0
Example 2
document.write(StrComp("VBScript","vbscript"))
Output:
-1
Example 3
document.write(StrComp("VBScript","vbscript",1))
Output:
0
Created By www.ebooktutorials.blogspot.in
Syntax
String(number,character)
Parameter
Description
number
character
Example 1
document.write(String(10,"#"))
Output:
##########
Example 2
document.write(String(4,"*"))
Output:
****
Example 3
document.write(String(4,42))
Output:
****
Example 4
document.write(String(4,"XYZ"))
Output:
XXXX
Created By www.ebooktutorials.blogspot.in
Syntax
StrReverse(string)
Parameter
Description
string
Example 1
Dim txt
txt="This is a beautiful day!"
document.write(StrReverse(txt))
Output:
!yad lufituaeb a si sihT
Created By www.ebooktutorials.blogspot.in
Syntax
UCase(string)
Parameter
Description
string
Examples
Example 1
<script type="text/vbscript">
txt="This is a beautiful day!"
document.write(UCase(txt))
</script>
The output of the code above will be:
Example 2
<script type="text/vbscript">
txt="This is a BEAUTIFUL day!"
document.write(UCase(txt))
</script>
The output of the code above will be:
Created By www.ebooktutorials.blogspot.in
Syntax
CreateObject(servername.typename[,location])
Parameter
Description
servername
typename
location
Example
Example
Creating a regular expression object:
<script type="text/vbscript">
txt="This is a beautiful day"
Set objReg=CreateObject("vbscript.regexp")
objReg.Pattern="i"
document.write(objReg.Replace(txt,"##"))
</script>
The output of the code above will be:
Created By www.ebooktutorials.blogspot.in
Syntax
Eval(expression)
Parameter
Description
expression
Example
Example
Creating a regular expression object:
<script type="text/vbscript">
function myFunction()
alert("Hello world")
end function
eval("myFunction()")
</script>
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
GetLocale()
Example
Example (IE Only)
<script type="text/vbscript">
document.write(GetLocale)
</script>
The output of the code above will be:
Try it yourself
Locale ID Chart
Locale Description
Short String
Hex Value
Decimal Value
Afrikaans
af
0x0436
1078
Albanian
sq
0x041C
1052
ar-ae
0x3801
14337
Arabic - Bahrain
ar-bh
0x3C01
15361
Arabic - Algeria
ar-dz
0x1401
5121
Arabic - Egypt
ar-eg
0x0C01
3073
Arabic - Iraq
ar-iq
0x0801
2049
Arabic - Jordan
ar-jo
0x2C01
11265
Arabic - Kuwait
ar-kw
0x3401
13313
Arabic - Lebanon
ar-lb
0x3001
12289
Arabic - Libya
ar-ly
0x1001
4097
Arabic - Morocco
ar-ma
0x1801
6145
Arabic - Oman
ar-om
0x2001
8193
Arabic - Qatar
ar-qa
0x4001
16385
ar-sa
0x0401
1025
Arabic - Syria
ar-sy
0x2801
10241
Arabic - Tunisia
ar-tn
0x1C01
7169
Arabic - Yemen
ar-ye
0x2401
9217
Armenian
hy
0x042B
1067
Azeri Latin
az-az
0x042C
1068
Azeri Cyrillic
az-az
0x082C
2092
Basque
eu
0x042D
1069
Belarusian
be
0x0423
1059
Bulgarian
bg
0x0402
1026
Catalan
ca
0x0403
1027
Chinese - China
zh-cn
0x0804
2052
zh-hk
0x0C04
3076
zh-mo
0x1404
5124
Created By www.ebooktutorials.blogspot.in
Chinese - Singapore
zh-sg
0x1004
4100
Chinese - Taiwan
zh-tw
0x0404
1028
Croatian
hr
0x041A
1050
Czech
cs
0x0405
1029
Danish
da
0x0406
1030
nl-nl
0x0413
1043
Dutch - Belgium
nl-be
0x0813
2067
English - Australia
en-au
0x0C09
3081
English - Belize
en-bz
0x2809
10249
English - Canada
en-ca
0x1009
4105
English Carribbean
en-cb
0x2409
9225
English - Ireland
en-ie
0x1809
6153
English - Jamaica
en-jm
0x2009
8201
en-nz
0x1409
5129
English Phillippines
en-ph
0x3409
13321
en-za
0x1C09
7177
English - Trinidad
en-tt
0x2C09
11273
en-gb
0x0809
2057
en-us
0x0409
1033
Estonian
et
0x0425
1061
Farsi
fa
0x0429
1065
Finnish
fi
0x040B
1035
Faroese
fo
0x0438
1080
French - France
fr-fr
0x040C
1036
French - Belgium
fr-be
0x080C
2060
French - Canada
fr-ca
0x0C0C
3084
French - Luxembourg
fr-lu
0x140C
5132
French - Switzerland
fr-ch
0x100C
4108
Gaelic Ireland
gd-ie
0x083C
2108
Gaelic - Scotland
gd
0x043C
1084
German - Germany
de-de
0x0407
1031
German - Austria
de-at
0x0C07
3079
German - Liechtenstein
de-li
0x1407
5127
German - Luxembourg
de-lu
0x1007
4103
German - Switzerland
de-ch
0x0807
2055
Greek
el
0x0408
1032
Hebrew
he
0x040D
1037
Hindi
hi
0x0439
1081
Hungarian
hu
0x040E
1038
Icelandic
is
0x040F
1039
Indonesian
id
0x0421
1057
Italian - Italy
it-it
0x0410
1040
Italian - Switzerland
it-ch
0x0810
2064
Japanese
ja
0x0411
1041
Korean
ko
0x0412
1042
Latvian
lv
0x0426
1062
Lithuanian
lt
0x0427
1063
FYRO Macedonian
mk
0x042F
1071
Malay - Malaysia
ms-my
0x043E
1086
Malay Brunei
ms-bn
0x083E
2110
Maltese
mt
0x043A
1082
Marathi
mr
0x044E
1102
Norwegian - Bokml
no-no
0x0414
1044
Norwegian Nynorsk
no-no
0x0814
2068
Polish
pl
0x0415
1045
Portuguese - Portugal
pt-pt
0x0816
2070
Created By www.ebooktutorials.blogspot.in
Portuguese - Brazil
pt-br
0x0416
1046
Raeto-Romance
rm
0x0417
1047
Romanian - Romania
ro
0x0418
1048
Romanian - Moldova
ro-mo
0x0818
2072
Russian
ru
0x0419
1049
Russian - Moldova
ru-mo
0x0819
2073
Sanskrit
sa
0x044F
1103
Serbian - Cyrillic
sr-sp
0x0C1A
3098
Serbian Latin
sr-sp
0x081A
2074
Setsuana
tn
0x0432
1074
Slovenian
sl
0x0424
1060
Slovak
sk
0x041B
1051
Sorbian
sb
0x042E
1070
Spanish - Spain
es-es
0x0C0A
1034
Spanish - Argentina
es-ar
0x2C0A
11274
Spanish - Bolivia
es-bo
0x400A
16394
Spanish - Chile
es-cl
0x340A
13322
Spanish - Colombia
es-co
0x240A
9226
es-cr
0x140A
5130
es-do
0x1C0A
7178
Spanish - Ecuador
es-ec
0x300A
12298
Spanish - Guatemala
es-gt
0x100A
4106
Spanish - Honduras
es-hn
0x480A
18442
Spanish - Mexico
es-mx
0x080A
2058
Spanish - Nicaragua
es-ni
0x4C0A
19466
Spanish - Panama
es-pa
0x180A
6154
Spanish - Peru
es-pe
0x280A
10250
es-pr
0x500A
20490
Spanish - Paraguay
es-py
0x3C0A
15370
Spanish - El Salvador
es-sv
0x440A
17418
Spanish - Uruguay
es-uy
0x380A
14346
Spanish - Venezuela
es-ve
0x200A
8202
Sutu
sx
0x0430
1072
Swahili
sw
0x0441
1089
Swedish - Sweden
sv-se
0x041D
1053
Swedish - Finland
sv-fi
0x081D
2077
Tamil
ta
0x0449
1097
Tatar
tt
0X0444
1092
Thai
th
0x041E
1054
Turkish
tr
0x041F
1055
Tsonga
ts
0x0431
1073
Ukrainian
uk
0x0422
1058
Urdu
ur
0x0420
1056
Uzbek Cyrillic
uz-uz
0x0843
2115
Uzbek Latin
uz-uz
0x0443
1091
Vietnamese
vi
0x042A
1066
Xhosa
xh
0x0434
1076
Yiddish
yi
0x043D
1085
Zulu
zu
0x0435
1077
Created By www.ebooktutorials.blogspot.in
Syntax
GetObject([pathname][,class])
Parameter
Description
pathname
Optional. The full path and name of the file that contains the automation object.
If this parameter is omitted, the class parameter is required
class
Optional. The class of the automation object. This parameter uses this syntax:
appname.objectype
Created By www.ebooktutorials.blogspot.in
Syntax
Set object.event=GetRef(procname)
Parameter
Description
object
event
procname
Example
Example
<button id="myBtn">Click me</button>
<script type="text/vbscript">
document.getElementById("myBtn").onclick=GetRef("mySub")
Sub mySub()
alert("Hello world")
End Sub
</script>
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
InputBox(prompt[,title][,default][,xpos][,ypos][,helpfile,context])
Parameter
Description
prompt
Required. The message to show in the dialog box. Maximum length is 1024
characters. You can separate the lines using a carriage return character
(Chr(13)), a linefeed character (Chr(10)), or carriage returnlinefeed character
combination (Chr(13) & Chr(10)) between each line
title
Optional. The title of the dialog box. Default is the application name
default
xpos
Optional. The prompt box' distance from the left edge of the screen.
Measurement unit: twips*. If omitted, the dialog box is horizontally centered.
ypos
Optional. The prompt box' distance from the top edge of the screen.
Measurement unit: twips*. If omitted, the dialog box is vertically positioned onethird of the way down the screen
helpfile
Optional. The name of a Help file to use. Must be used with the context
parameter
context
Optional. The Help context number to the Help topic. Must be used with the
helpfile parameter
* A twip is a measurement unit that is visually the same on all display systems.
1 twip is 1/1440 of an inch.
Examples
Example 1
<script type="text/vbscript">
Function myFunction()
fname=InputBox("Enter your name")
End Function
</script>
Try it yourself
Example 2
A prompt box with a title:
<script type="text/vbscript">
Function myFunction()
fname=InputBox("Enter your name","Userinput")
End Function
</script>
Try it yourself
Example 3
A prompt box with a deafult text in the inputbox:
<script type="text/vbscript">
Created By www.ebooktutorials.blogspot.in
Function myFunction()
fname=InputBox("Enter your name",,"Donald Duck")
End Function
</script>
Try it yourself
Example 4
A prompt box wich is positioned 700 twips* from the left edge of your screen.
<script type="text/vbscript">
Function myFunction()
fname=InputBox("Enter your name",,,700)
End Function
</script>
Try it yourself
Example 5
A prompt box wich is positioned 500 twips* from the top edge of your screen.
<script type="text/vbscript">
Function myFunction()
fname=InputBox("Enter your name",,,,500)
End Function
</script>
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
IsEmpty(expression)
Parameter
Description
expression
Example
Example
<script type="text/vbscript">
Dim x
document.write(IsEmpty(x) & "<br />")
x=10
document.write(IsEmpty(x) & "<br />")
x=Empty
document.write(IsEmpty(x) & "<br />")
x=Null
document.write(IsEmpty(x))
</script>
The output of the code above will be:
True
False
True
False
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
IsNull(expression)
Parameter
Description
expression
Required. An expression
Example
Example
<script type="text/vbscript">
Dim x
document.write(IsNull(x) & "<br />")
x=10
document.write(IsNull(x) & "<br />")
x=Empty
document.write(IsNull(x) & "<br />")
x=Null
document.write(IsNull(x))
</script>
The output of the code above will be:
False
False
False
True
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
IsNumeric(expression)
Parameter
Description
expression
Required. An expression
Example
Example
<script type="text/vbscript">
Dim x
x=10
document.write(IsNumeric(x) &
x=Empty
document.write(IsNumeric(x) &
x=Null
document.write(IsNumeric(x) &
x="10"
document.write(IsNumeric(x) &
x="911 Help"
document.write(IsNumeric(x))
"<br />")
"<br />")
"<br />")
"<br />")
</script>
The output of the code above will be:
True
True
False
True
False
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
IsObject(expression)
Parameter
Description
expression
Required. An expression
Examples
Example 1
<script type="text/vbscript">
Set x=document
document.write(IsObject(x))
</script>
The output of the code above will be:
True
Try it yourself
Example 2
<script type="text/vbscript">
x="Peter"
document.write(IsObject(x))
</script>
The output of the code above will be:
False
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
LoadPicture(picturename)
Parameter
Description
picturename
Created By www.ebooktutorials.blogspot.in
=
=
=
=
=
=
=
Note: The user can press F1 to view the Help topic when both the helpfile and the context parameter
are specified.
Tip: Also look at the InputBox function.
Syntax
MsgBox(prompt[,buttons][,title][,helpfile,context])
Parameter
Description
prompt
Required. The message to show in the message box. Maximum length is 1024
characters. You can separate the lines using a carriage return character
(Chr(13)), a linefeed character (Chr(10)), or carriage returnlinefeed character
combination (Chr(13) & Chr(10)) between each line
buttons
Optional. A value or a sum of values that specifies the number and type of
buttons to display, the icon style to use, the identity of the default button, and
the modality of the message box. Default value is 0
0 = vbOKOnly - OK button only
1 = vbOKCancel - OK and Cancel buttons
2 = vbAbortRetryIgnore - Abort, Retry, and Ignore buttons
3 = vbYesNoCancel - Yes, No, and Cancel buttons
4 = vbYesNo - Yes and No buttons
5 = vbRetryCancel - Retry and Cancel buttons
16 = vbCritical - Critical Message icon
32 = vbQuestion - Warning Query icon
48 = vbExclamation - Warning Message icon
64 = vbInformation - Information Message icon
0 = vbDefaultButton1 - First button is default
256 = vbDefaultButton2 - Second button is default
512 = vbDefaultButton3 - Third button is default
768 = vbDefaultButton4 - Fourth button is default
0 = vbApplicationModal - Application modal (the current application will
not work until the user responds to the message box)
4096 = vbSystemModal - System modal (all applications wont work until
the user responds to the message box)
We can divide the buttons values into four groups: The first group (05)
describes the buttons to be displayed in the message box, the second group (16,
32, 48, 64) describes the icon style, the third group (0, 256, 512, 768) indicates
which button is the default; and the fourth group (0, 4096) determines the
modality of the message box. When adding numbers to create a final value for
the buttons parameter, use only one number from each group
title
Optional. The title of the message box. Default is the application name
helpfile
Optional. The name of a Help file to use. Must be used with the context
parameter
context
Optional. The Help context number to the Help topic. Must be used with the
helpfile parameter
Examples
Example 1
<script type="text/vbscript">
MsgBox("Hello world")
</script>
Created By www.ebooktutorials.blogspot.in
Try it yourself
Example 2
A messagebox with a line feed:
<script type="text/vbscript">
MsgBox("Hello" & chr(13) & "world")
</script>
Try it yourself
Example 3
Different buttonsets and different icons. Returns the value of the clicked button:
<script type="text/vbscript">
x=MsgBox("Hello world",n)
document.getElementById("myDiv").innerHTML="You clicked: " & x
</script>
Try it yourself
Example 4
A messagebox with a title:
<script type="text/vbscript">
x=MsgBox("Are you a programmer",4,"Please answer")
</script>
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
RGB(red,green,blue)
Parameter
Description
red
green
blue
Examples
Example 1
<script type="text/vbscript">
document.write(rgb(255,0,0))
</script>
The output of the code above will be:
255
Try it yourself
Example 2
<script type="text/vbscript">
document.write(rgb(255,30,30))
</script>
The output of the code above will be:
1974015
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
Round(expression[,numdecimalplaces])
Parameter
Description
expression
numdecimalplaces
Optional. Specifies how many places to the right of the decimal are included in
the rounding. Default is 0
Examples
Example 1
<script type="text/vbscript">
document.write(Round(24.13278) & "<br />")
document.write(Round(24.75122))
</script>
The output of the code above will be:
24
25
Try it yourself
Example 2
How to round a number, keeping 2 decimals:
<script type="text/vbscript">
document.write(Round(24.13278,2))
</script>
The output of the code above will be:
24.13
Try it yourself
Created By www.ebooktutorials.blogspot.in
ScriptEngine Function
The ScriptEngine function returns the scripting language in use.
This function can return one of the following strings:
VBScript - Indicates that Microsoft Visual Basic Scripting Edition is the current scripting engine
JScript - Indicates that Microsoft JScript is the current scripting engine
VBA - Indicates that Microsoft Visual Basic for Applications is the current scripting engine
ScriptEngineBuildVersion Function
The ScriptEngineBuildVersion function returns the build version number of the scripting engine in use.
ScriptEngineMajorVersion Function
The ScriptEngineMajorVersion function returns the major version number of the scripting engine in use.
ScriptEngineMinorVersion Function
The ScriptEngineMinorVersion function returns the minor version number of the scripting engine in use.
Syntax
ScriptEngine
ScriptEngineBuildVersion
ScriptEngineMajorVersion
ScriptEngineMinorVersion
Example
Example
<script type="text/vbscript">
document.write(ScriptEngine & "<br />")
document.write(ScriptEngineBuildVersion & "<br />")
document.write(ScriptEngineMajorVersion & "<br />")
document.write(ScriptEngineMinorVersion)
</script>
The output of the code above could be:
VBScript
18702
5
8
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
SetLocale(lcid)
Parameter
Description
lcid
Required. A short string, hex value, or decimal value in the Locale ID chart, that
identifies a geographic locale. If the lcid parameter is set to 0, the locale will be
set by the system
Examples
Example 1 (IE Only)
Check the current local ID using the GetLocale function. Set the local ID = 2057, and check the
local ID again:
<script type="text/vbscript">
document.write(GetLocale() & "<br />")
SetLocale(2057)
document.write(GetLocale())
</script>
The output of the code above will be:
Try it yourself
<script type="text/vbscript">
document.write(SetLocale(1044))
</script>
The output of the code above will be:
Try it yourself
Locale ID Chart
Locale Description
Short String
Hex Value
Decimal Value
Afrikaans
af
0x0436
1078
Albanian
sq
0x041C
1052
ar-ae
0x3801
14337
Arabic - Bahrain
ar-bh
0x3C01
15361
Arabic - Algeria
ar-dz
0x1401
5121
Arabic - Egypt
ar-eg
0x0C01
3073
Arabic - Iraq
ar-iq
0x0801
2049
Arabic - Jordan
ar-jo
0x2C01
11265
ar-kw
0x3401
13313
Arabic - Kuwait
Created By www.ebooktutorials.blogspot.in
Arabic - Lebanon
ar-lb
0x3001
12289
Arabic - Libya
ar-ly
0x1001
4097
Arabic - Morocco
ar-ma
0x1801
6145
Arabic - Oman
ar-om
0x2001
8193
Arabic - Qatar
ar-qa
0x4001
16385
ar-sa
0x0401
1025
Arabic - Syria
ar-sy
0x2801
10241
Arabic - Tunisia
ar-tn
0x1C01
7169
Arabic - Yemen
ar-ye
0x2401
9217
Armenian
hy
0x042B
1067
Azeri Latin
az-az
0x042C
1068
Azeri Cyrillic
az-az
0x082C
2092
Basque
eu
0x042D
1069
Belarusian
be
0x0423
1059
Bulgarian
bg
0x0402
1026
Catalan
ca
0x0403
1027
Chinese - China
zh-cn
0x0804
2052
zh-hk
0x0C04
3076
zh-mo
0x1404
5124
Chinese - Singapore
zh-sg
0x1004
4100
Chinese - Taiwan
zh-tw
0x0404
1028
Croatian
hr
0x041A
1050
Czech
cs
0x0405
1029
Danish
da
0x0406
1030
nl-nl
0x0413
1043
Dutch - Belgium
nl-be
0x0813
2067
English - Australia
en-au
0x0C09
3081
English - Belize
en-bz
0x2809
10249
English - Canada
en-ca
0x1009
4105
English Carribbean
en-cb
0x2409
9225
English - Ireland
en-ie
0x1809
6153
English - Jamaica
en-jm
0x2009
8201
en-nz
0x1409
5129
English Phillippines
en-ph
0x3409
13321
en-za
0x1C09
7177
English - Trinidad
en-tt
0x2C09
11273
en-gb
0x0809
2057
en-us
0x0409
1033
Estonian
et
0x0425
1061
Farsi
fa
0x0429
1065
Finnish
fi
0x040B
1035
Faroese
fo
0x0438
1080
French - France
fr-fr
0x040C
1036
French - Belgium
fr-be
0x080C
2060
French - Canada
fr-ca
0x0C0C
3084
French - Luxembourg
fr-lu
0x140C
5132
French - Switzerland
fr-ch
0x100C
4108
Gaelic Ireland
gd-ie
0x083C
2108
Gaelic - Scotland
gd
0x043C
1084
German - Germany
de-de
0x0407
1031
German - Austria
de-at
0x0C07
3079
German - Liechtenstein
de-li
0x1407
5127
German - Luxembourg
de-lu
0x1007
4103
German - Switzerland
de-ch
0x0807
2055
Greek
el
0x0408
1032
Hebrew
he
0x040D
1037
Created By www.ebooktutorials.blogspot.in
Hindi
hi
0x0439
1081
Hungarian
hu
0x040E
1038
Icelandic
is
0x040F
1039
Indonesian
id
0x0421
1057
Italian - Italy
it-it
0x0410
1040
Italian - Switzerland
it-ch
0x0810
2064
Japanese
ja
0x0411
1041
Korean
ko
0x0412
1042
Latvian
lv
0x0426
1062
Lithuanian
lt
0x0427
1063
FYRO Macedonian
mk
0x042F
1071
Malay - Malaysia
ms-my
0x043E
1086
Malay Brunei
ms-bn
0x083E
2110
Maltese
mt
0x043A
1082
Marathi
mr
0x044E
1102
Norwegian - Bokml
no-no
0x0414
1044
Norwegian Nynorsk
no-no
0x0814
2068
Polish
pl
0x0415
1045
Portuguese - Portugal
pt-pt
0x0816
2070
Portuguese - Brazil
pt-br
0x0416
1046
Raeto-Romance
rm
0x0417
1047
Romanian - Romania
ro
0x0418
1048
Romanian - Moldova
ro-mo
0x0818
2072
Russian
ru
0x0419
1049
Russian - Moldova
ru-mo
0x0819
2073
Sanskrit
sa
0x044F
1103
Serbian - Cyrillic
sr-sp
0x0C1A
3098
Serbian Latin
sr-sp
0x081A
2074
Setsuana
tn
0x0432
1074
Slovenian
sl
0x0424
1060
Slovak
sk
0x041B
1051
Sorbian
sb
0x042E
1070
Spanish - Spain
es-es
0x0C0A
1034
Spanish - Argentina
es-ar
0x2C0A
11274
Spanish - Bolivia
es-bo
0x400A
16394
Spanish - Chile
es-cl
0x340A
13322
Spanish - Colombia
es-co
0x240A
9226
es-cr
0x140A
5130
es-do
0x1C0A
7178
Spanish - Ecuador
es-ec
0x300A
12298
Spanish - Guatemala
es-gt
0x100A
4106
Spanish - Honduras
es-hn
0x480A
18442
Spanish - Mexico
es-mx
0x080A
2058
Spanish - Nicaragua
es-ni
0x4C0A
19466
Spanish - Panama
es-pa
0x180A
6154
Spanish - Peru
es-pe
0x280A
10250
es-pr
0x500A
20490
Spanish - Paraguay
es-py
0x3C0A
15370
Spanish - El Salvador
es-sv
0x440A
17418
Spanish - Uruguay
es-uy
0x380A
14346
Spanish - Venezuela
es-ve
0x200A
8202
Sutu
sx
0x0430
1072
Swahili
sw
0x0441
1089
Swedish - Sweden
sv-se
0x041D
1053
Swedish - Finland
sv-fi
0x081D
2077
Tamil
ta
0x0449
1097
Created By www.ebooktutorials.blogspot.in
Tatar
tt
0X0444
1092
Thai
th
0x041E
1054
Turkish
tr
0x041F
1055
Tsonga
ts
0x0431
1073
Ukrainian
uk
0x0422
1058
Urdu
ur
0x0420
1056
Uzbek Cyrillic
uz-uz
0x0843
2115
Uzbek Latin
uz-uz
0x0443
1091
Vietnamese
vi
0x042A
1066
Xhosa
xh
0x0434
1076
Yiddish
yi
0x043D
1085
Zulu
zu
0x0435
1077
Created By www.ebooktutorials.blogspot.in
Syntax
TypeName(varname)
Parameter
Description
varname
Example
Example
<script type="text/vbscript">
x="Hello World!"
document.write(TypeName(x) &
x=4
document.write(TypeName(x) &
x=4.675
document.write(TypeName(x) &
x=Null
document.write(TypeName(x) &
x=Empty
document.write(TypeName(x) &
x=True
document.write(TypeName(x))
"<br />")
"<br />")
"<br />")
"<br />")
"<br />")
</script>
The output of the code above will be:
String
Integer
Double
Null
Empty
Boolean
Try it yourself
Created By www.ebooktutorials.blogspot.in
Syntax
VarType(varname)
Parameter
Description
varname
Example
Example
<script type="text/vbscript">
x="Hello World!"
document.write(VarType(x) &
x=4
document.write(VarType(x) &
x=4.675
document.write(VarType(x) &
x=Null
document.write(VarType(x) &
x=Empty
document.write(VarType(x) &
x=True
document.write(VarType(x))
"<br />")
"<br />")
"<br />")
"<br />")
"<br />")
</script>
The output of the code above will be:
8
2
5
1
0
11
Try it yourself