VBScript examples
NOTE: VBScript works only in Internet Explorer.
Each example can be viewed in the online code editor so that you can expirement with the code as much as you like.
Jump to:
Basics | Variables | Conditions | Loops | Arrays | Functions/procedures | Strings | Date & time
VBScript basics
Script in the head section of a page
Script in the body section of a page
Script in both the body & head section of a page
Printing text on a page
Printing HTML tags
Handling browsers that do not support scripts at all
Handling browsers that do not support VBScript
Comments in VBScript code
^Back to top
VBScript variables
Declaring variables
Setting option explicit
Printing variables
Declaring, printing, changing variable values
^Back to top
VBScript conditions
If statement
Else statement
Multiple conditions using the If statement
Multiple conditions using the Select statement
^Back to top
VBScript loops
For next loop
For each loop
Do-while loop
An infinite loop
^Back to top
VBScript arrays
Creating an array
Adding values to an array and printing them
Printing a random value from an array
Looping through an array with the For each loop
Modifying an array's elements
^Back to top
VBScript functions/procedures
Displaying various boxes (alert, prompt)
Creating a subprocedure
Creating a function
Calling a function/procedure
Returning a value from a function
Using VBScript's built-in functions
^Back to top
VBScript strings
Creating and printing a string
String concatenation
Using VBScript's string functions
^Back to top
VBScript date & time
Print the current date and time
Print the current date and time in a custom format
Print the current day of the week and the current month
Print the time remaining until a certain date
Find out if a given value is really a date or not
^Back to top