Vous êtes sur la page 1sur 20

Module 3

WEB DESIGNING

August 2010 / BLY

~ ~ ~ INDEX ~ ~ ~

TOPIC INTRODUCTION OF VBSCRIPT ....... DIFFERENCE BETWEEN VBSCRIPT & VISUAL BASIC . PLACING VBSCRIPT IN A HTML FILE............... THE DOCUMENT OBJECT . ... ................... .................. .................. ..................

PAGE 02 02 02~03 03 03 ~ 04 04 ~ 05 05 05 ~ 06 06 ~ 12 12 12 ~ 14 14 ~ 15 15 ~ 16 17 ~ 20

VARIABLE ...... .................. DATA TYPES AND LITERALS...... ... .................. POPUP BOXES ...... .................. WORKING WITH ARRAYS . .................. OPERATORS & EXPRESSIONS ..... .................. CONSTANT ......... .................. CONTROL STATEMENTS . .................. LOOPING .... .................. PROCEDURES & FUNCTIONS .... .................. VBSCRIPT LIBRARY FUNCTIONS ........................ ..................

Note: If you find any typing or printing error/s, inform immediately to your branch office.

ADCPM

VBSCRIPT

Page - 1

Module 3

WEB DESIGNING

August 2010 / BLY

INTRODUCTION TO VBSCRIPT
VBScript is a computer language interpreted by a browser. VBScript is an interpreted programming language that can be embedded into an HTML web page or used in server side scripting language. VBScript is used in conjunction with other languages to tie computer based application to the Internet. VBScript can also perform calculation on data such as computing the cost of an item. VBScript is mainly supported by Internet Explorer and Netscape.

Difference between VBScript and Visual Basic :


VBScript is a subset of Visual Basic. There are many differences between VBScript and Visual Basic: Visual Basic has a design time environment, when you run Visual basic, you get an interactive editing environment where you can design forms and write code by using an interactive cell. But there is no such as environment available when you work with VBScript. Visual Basic code creates windows application that operates in and off them. On the other hand VBScript code works inside HTML document, which are the text files and run along with HTML. Visual Basic supports many commands, keywords and data type while VBScript does not support. VBScript provides no support for classes as used in Visual Basic. VBScript do not support data access. VBScript do not support the Screen, Printer, Debug and Clipboard objects. It supports only the Err object.

Placing VBScript in a HTML Page/File


VBScript code is written within paired <Script> tags. To set the instructions of a script from the HTML tags, the section that has the script must start with the <Script> tag and end with the </Script> tag. Script tags should be placed inside the HEAD tag of the document. VBScript code should also be placed inside an HTML comment tag set. That is, VBScript in the Body of the HTML file: VBScript in the body of the HTML page will be executed when the page loads. There are various scripting languages, to use a script; you should let the browser know what scripting language you are using. To let the browser know, you have to type the word Language, followed by the = sign, followed by the name of the script language included in double quotes. For example<Script Language=VBScript> </Script> Script in the body will generate the content of the page. Example: <html> <head><title>ELFIN COMPUTER EDUCATION CENTRE</title> </head> <body> <Script Language=VBScript>
ADCPM

VBSCRIPT

Page - 2

Module 3

WEB DESIGNING

August 2010 / BLY

Or <Script Type=Text/VBScript> document.write(ELFIN COMPUTER EDUCATION CENTRE) </Script> </body></html> VBScript in the Head of the file: If you want be sure that the script executes before displaying any elements in the page, you can include this in the Head part of the HTML file. The VBScript in the head section will be executed when called or when an event is triggered. Example: <html> <head><title>ELFIN COMPUTER EDUCATION CENTRE</title> <Script Language=VBScript> document.write(THIS IS ELFIN COMPUTER EDUCATION CENTRE) </Script></head> <body> <p>Welcome to the Elfin Computer Education Centre</p> </body><html> The Document object: VBScript uses an object called Document. This object manages many of the instructions that VBScript can handle for HTML. One of the functions of that is to display a string on the screen. The function used is called Write. The syntax is: Document.Write(string) Example: <html> <head><title>ELFIN COMPUTER EDUCATION CENTRE</title> <Script Language=VBScript> document.write(THIS IS ELFIN COMPUTER EDUCATION CENTRE) </Script></head> <body> document.write(THIS IS ELFIN COMPUTER EDUCATION CENTRE) </body></html>

VARIABLE
A variable is a convenient placeholder that refers to a computer memory location where you can store program information, depending during the time your script is running. That is, a variable is a name assigned t o a location in computers memory to store data. The Variable are the memory cells used for storing forms input data and/or its computational results. For example, if you want to store a name in computers memory, you have to create a variable. You can cr eate the variable as you want to store the name value. You have to refer a variable by name to see its value or to change its value. Variable are always of one fundamental data type, Variant which can contain any kind of data. Rules for naming the Variable in VBScript: An identifier must begin with a letter. Cant be longer than 255 characters.
ADCPM

VBSCRIPT

Page - 3

Module 3

WEB DESIGNING

August 2010 / BLY

Cant contain embedded period or embedded type declaration characters. Declaring Variable: The declaration of variable is realized by using the dim or Redim statement. dim is short for dimension. When you declare a variable the interpreter needs to allocate memory to hold the contents for you. No memory is allocated until you store a value in the variable. You can also declare a variable implicitly by simply using its name in your script. Example: If you want to add two numbers and display the sum of that numbers: dim a dim b dim sum You have to declare three variables with dim keyword. You can declare multiple variables by separating each variable name with a comma (,). Such as: dim a, b, sum Assigning values to Variable: Values are assigned to variable creating an expression. The variable is on the left side of the expression and the value you want to assign/initialize to a variable is on the right. This is performed with the assignment operation. The assignment operation gives a value to a variable. Syntax: Variable_Name = Value Once a variable has been declared and assigned a value, you can call the document.write() function to display its value.

Data Types and Literals


VBScript uses the Variant data type. The Variant is used often to store numbers and strings, but it can store a variety of other types of data. These data types are often call Subtypes. Description Sub Type Variant is un-initialized. Value is either 0 for numeric variable or a Empty 0 length string () for string variable. Variant intentionally contains no valid data. Null Contains either True or False. Boolean Contains an integer in the range 0 to 255. Byte Contains an integer in the range -32,768 to 32,767. Integer Contains an integer in the range -2,147,483,648 to 2,147,483,647. Single Contains a single-precision. Long Contains a variables-length string that can be up to approximately String 2 billion characters in length. Date(Time) Contains a number that represents a date between January 1, 100 to December 31, 9999. Contains an object. Object Contains an error number. Error
ADCPM

VBSCRIPT

Page - 4

Module 3

WEB DESIGNING

August 2010 / BLY

Popup Boxes
In VBScript, you can create two types of popup boxes by invoking the functions. Inputbox (text to be displayed): Provides text box to fill data. When you want to input the data from user in a program, you should use this function/popup box. Msgbox: Displays a message box, waits for the user to click a button, and returns a value that indicates which button the user clicked.

Working with Arrays


It is convenient to assign more than one related value to a single variable. Then you can create a variable that can contain a series of values. This is called an array variable. A variable that contain a series of values is called Array. The declaration of an array variable uses parentheses () following the variable name. For example, dim a (5) The number shown in the parentheses is 5, all arrays in VBScript are zero based, so this array actually contains 6 elements. In a zero based array, the number of array elements is always the number shown in parentheses plus one. This kind of array is called a Fixed Size Array. You can also declare an array whose size changes during the time your script running this is called a Dynamic Array. The array is initially declared within a procedure using either the dim statement or using the Redim statements. However, for a dynamic array, no size or number of dimensions is placed inside the parentheses. Example: dim a () Program: Write a program in HTML using VBScript, using Array. Input the family member maximum 5 and print all family members. Solution: <html> <head><title>family members are</title> <script language="vbscript"> dim femname(5) femname(0)=inputbox("enter the name of first member") femname(1)=inputbox("enter the name of second member") femname(2)=inputbox("enter the name of third member") femname(3)=inputbox("enter the name of fourth member") femname(4)=inputbox("enter the name of fifth member") </script></head> <body> <script language="vbscript"> document.write(femname(0)&"<br>") document.write(femname(1)&"<br>") document.write(femname(2)&"<br>")
ADCPM

VBSCRIPT

Page - 5

Module 3

WEB DESIGNING

August 2010 / BLY

document.write(femname(3)&"<br>") document.write(femname(4)&"<br>") </script> </body> </html>

Operators & Expressions:


Operators are the things that act on variables or operators are the symbols which are used in the expression and are applied on the operands. Operand may be a value or variable. Types of Operators: Arithmetic Operator: It allows you to perform simple arithmetic operations. Addition (+) Operator: This operator is used to add one value to another. The syntax is: Variable1 + Variable2 The addition operator as implemented in VBScript can be applied to natural numbers called integers and to floating point numbers called float numbers. You can also add the values of two variables using their names. Example: <html> <head><title>addition</title> <script language="vbscript"> dim a, b, sum a=6 b=5 sum=a+b </script></head> <body bgcolor=yellow> <script language="vbscript"> document.write("the result is "&sum) </script> </body> </html>

Result = 11 Subtraction (-) Operator: This operator is used to subtract one value
from another. The syntax is: Variable1 Variable2 The subtraction operation as implemented in VBScript can be applied to naturals or decimal numbers. The subtraction can also be applied on variables or their values. Example: <html> <head><title>subtraction</title> <script language="vbscript"> dim a, b, sub a=6
ADCPM

VBSCRIPT

Page - 6

Module 3

WEB DESIGNING

August 2010 / BLY

b=5 sub=a-b document.write("the result is "&sub) </script></head> </html>

Result = 1 Multiplication (*) Operator: This operator is used to add a number to


itself a certain numbers of times, means multiply the one value from another value. The syntax is: Variable1 * Variable2 This operator can be performed on numeric values or variables that hold valid values. Example: <html> <head><title>multiplication </title> <script language="vbscript"> dim a, b, mul a=6 b=5 mul=a*b document.write("the result is "&mul) </script></head> </html>

Result = 30 Integer Division (\) Operator: Dividing an item means cutting it in


pieces or fraction of a set value. Division is used to get the fraction of one number in terms of another. The Integer operator is performed using the backslash (\). The syntax is: Variable1 \ Variable2 This operator can be performed on two types of valid numbers, with or without decimal parts. After the operation the result would be a natural number. Example: <html> <head><title>integer division </title> <script language="vbscript"> dim a, b, intdiv a=6 b=5 intdiv=a\b document.write("the result is "&intdiv) </script></head> </html>

Result = 1
ADCPM

VBSCRIPT

Page - 7

Module 3

WEB DESIGNING

August 2010 / BLY

Division (/) Operator: This operator is used to divide a numeric value or


the value held by a variable. This operator is performed using the forward slash (/). The syntax is: Variable1 / Variable2 Example: <html> <head><title>integer division </title> <script language="vbscript"> dim a, b, div a=35 b=5 div=a/b document.write("the result is "&div) </script></head> </html>

Result = 7 Remainder (Mod) Operator: If you want to get the value remaining
after a division renders a natural result, you can use this operator. This operator is performed with keyword Mod. The syntax is: Variable1 Mod Variable2 Example: <html> <head><title>integer division </title> <script language="vbscript"> dim a,b,rem a=37 b=5 rem=a mod b document.write("the result is "&rem) </script></head> </html>

Result = 2 Negation (-) Operator: An unsigned number has a value greater than 0.
If a number is less than 0, such a number qualifies as negative. To indicate that a number is negative, you write the sign on its left. This operator is referred to as a unary operator because it applies to only one variable or value. Exponentiation (^) Operator: This operator has the ability to raise a number to the power of another number. This operator is expressed using the (^) sign. Example: <html> <head><title>integer division </title> <script language="vbscript"> dim a,b,exp
ADCPM

VBSCRIPT

Page - 8

Module 3

WEB DESIGNING

August 2010 / BLY

a=5 b=3 exp=a ^ b document.write("the result is "&exp) </script></head> </html>

Result = 125 String Concatenation (&) Operator: The document.write function you
have used to display a string on a web page. You can use this function various times to display different strings. VBScript provides an operator that allows you to add different strings and create a new one. This operator is performed using the & sign. The syntax is: Variable1 & Variable2 This operator is performed on strings and you can use it to display various items using the document.write function. Example: <html> <head><title>integer division </title> <script language="vbscript"> dim firstname, lastname, fullname firstname="Elfin" lastname="Computer Education Centre" fullname=firstname&" "&lastname document.write("the result is "&fullname) </script></head> </html>

Result = Elfin Computer Education Centre Comparison (Conditional) Operators: You can check the conditions or
compare the variable value with these types of operators. Equality (=) Operator: If you want to find out whether two variables hold the same value, you should use the equality operator. This operator is performed with = sign. The syntax is: Variable1 = Variable2 Inequality (<>) Operator: If you want to compare two variables in order to find out whether they are different, you can use this operator. The syntax is: Variable1 <> Variable2 Less Than (<) Operator: To find out whether one value is less than another value, you can use this operator. This operator compares the values held by Variable1 and Variable2. If the value held by Variable1 is less than that of Variable2, the comparison would produce a true value. Otherwise, the result is rendered false. The syntax is: Variable1 < Variable2 Example: <html>
ADCPM

VBSCRIPT

Page - 9

Module 3

WEB DESIGNING

August 2010 / BLY

<head><title>Less than</title> <script language="vbscript"> dim a,b a=8 b=9 if (a<b)then document.write("small value is"&a) else document.write("small value is"&b) end if </script></head> </html>

Result = 8 Greater Than (>) Operator: If you want to compare two values in order
to find out whether one value is greater than another, you can easily check this condition with this operator. The syntax is: Variable1 > Variable2 Example: <html> <head><title>Greater than</title> <script language="vbscript"> dim a,b a=8 b=9 if (a>b)then document.write("Greater value is"&a) else document.write("Greater value is"&b) end if </script></head> </html>

Result = 9 Logical Operators: These operators are used when there is more than one
condition to check. And (Conjunction) Operator: This operator is used in between two conditions or expression. The answer will true when the both conditions will true otherwise the answer will false. Example: <html> <head><title>Greater than</title> <script language="vbscript"> dim a,b,c a=10 b=9 c=6
ADCPM

VBSCRIPT

Page - 10

Module 3

WEB DESIGNING

August 2010 / BLY

if(a>b) and (a>c)then document.write("Greater value is"&a) elseif(b>a) and (b>c)then document.write("Greater value is"&b) else document.write("Greater value is"&c) end if </script></head> </html>

Result = 10 Or (Disjunction) Operator: This function is used in more than one


condition. In this operator, the result will true when any of the condition is true and the result will false if all the condition will false. Example: <html> <head><title>Greater than</title> <script language="vbscript"> dim a,b,c a=12 b=10 c=6 if(a>b) or (a>c)then document.write("Greater value is"&a) else if(b>a) or (b>c)then document.write("Greater value is"&b) else document.write("Greater value is"&c) end if </script></head> </html>

Result = 12 Not (Negation) Operator: This operator is used when you reverse the
condition value. If the condition value is true then it will return false.

Constant
A constant is a meaningful name that takes the place of a number or string and never changes. VBScript defines a number of intrinsic constant. A constant is a named storage location that contains data that cannot be modified during the script execution. You create user defined constants in VBScript using the Const statement. The syntax is: const constname = expression[..] Example: const pi=3.14 const MyAge=55 const MyName= Raj
ADCPM

VBSCRIPT

Page - 11

Module 3

WEB DESIGNING

August 2010 / BLY

The most used constant are number constants and string constants. A string constant is sequences from 0 to 1024 characters enclosed in quotes.

Control Statement / Conditional Checking:


Conditional statements allow you to control the flow of execution of a script or one of its sections. You can control the flow of your script with conditional statements and looping statement. Using conditional statement, you can write VBScript code that makes decisions and repeats actions. If - Then - Else statement: The If statement is a fundamental control statement. It allows your program to perform a test and act based on the result of that test. The If - Then - else statement is used to evaluate whether a condition is true or false and depending on the result, to specify one or more statements to run. If a condition is true and running others of a condition is false. You can use an If - Then - Else statement to define two blocks of executable abatements: one block to run if the condition is true, the other block to run if the condition is false. The syntax is: if(condition)then Statements else Statements end if Example: <html> <head><title>Greater than</title> <script language="vbscript"> dim a,b a=8 b=9 if(a>b)then document.write("Greater value is"&a) else document.write("Greater value is"&b) end if </script></head> </html>

Result = 9 If - Then - ElseIf statement: Elseif can be used to refine your code so that
you can reduce the number of statements and make your program code easier to read. That is, a variation on the If - Then - Else statement allows you to choose from several alternatives. The syntax is: if(condition)then Statements elseif(condition)then Statement end if Example:
ADCPM

VBSCRIPT

Page - 12

Module 3

WEB DESIGNING

August 2010 / BLY

<html> <head><title>Greater than</title> <script language="vbscript"> dim a,b,c a=12 b=10 c=6 if(a>b) or (a>c)then document.write("Greater value is"&a) elseif(b>a) or (b>c)then document.write("Greater value is"&b) else document.write("Greater value is"&c) end if </script></head> </html>

Result = 12 Select - Case statement: This statement is used where you have to
perform a large no. of test on the same expression. The select statement often makes your code easier to read and interact. The syntax is: Select - Case <text-expression> Case <expression1> Statement Case <expression2> Statement Case else Statement End select Example: Write a program to print the Weekday. Solution: <html> <head><title>WEEKDAY</title> <script language="vbscript"> dim day day=inputbox("enter the value of the day") select case day case 1 document.write("Today is Holiday") case 2 document.write("Today is Monday") case 3 document.write("Today is Tuesday") case 4 document.write("Today is Wednesday") case 5 document.write("Today is Thursday")
ADCPM

VBSCRIPT

Page - 13

Module 3

WEB DESIGNING

August 2010 / BLY

case 6 document.write("Today is Friday") case 7 document.write("Today is Saturday") case else document.write("It is a wrong value") end select </script></head> </html>

Looping:
A looping is a programming structure that forces the statements contained within its delimiters to execute over and over again until a condition is met at which point the loop ends. Looping allows you to run a group of statements repeatedly. Some loops repeat statements until a condition are false, other repeat statements until a condition is true. Do - While Loop: You can use Do - While loop statement to run a block of statements an indefinite number of times. The statements are repeated either while a condition is true or until a condition becomes true. That is while a condition is true, execute one or more statement. While loops are especially useful when you do not know how many times you have to loop, but you know you should stop when you meet the condition. The syntax is: do while <condition> Statement Statement .. loop Example: Write a program to print the Natural numbers. Solution: <html> <head><title>do while</title> <script language="vbscript"> dim i do while i<=10 document.write(i&"<br>") i=i+1 loop </script></head> </html> For .. Next Loop: You can use for.next statement to run a block of statements a specific number of times. For loops, use a counter variable whose value is increased or decreased with each repetition of the loop. The syntax is: Example: Write a program to print the Odd numbers. Solution:
ADCPM

VBSCRIPT

Page - 14

Module 3

WEB DESIGNING

August 2010 / BLY

<html> <head><title>do while</title> <script language="vbscript"> dim i for i= 1 to 10 step 2 document.write(i&"<br>") next </script></head> </html>

Procedures & Functions What are Procedures?


A procedure is an assignment to perform besides or to complete the normal flow of the program. A procedure is created to work in conjunction with the controls events of a script. There are two kinds of procedure in VBScript: 1. Sub Procedure: A Sub procedure is a section of code that carries an assignment but does not give back the result. 2. Function Declaring Procedures A procedure can be included in the body of an html file but to separate the script behavior. It is a good idea to include the procedure in the head section of the file. To create a Sub procedure, start the section code with the Sub keyword followed by a name for the sub procedure. To differentiate the name of the sub procedure with any other regular name, it must be followed by an opening and closing parentheses. The sub keyword and the name of the procedure are written on one line. The section of the sub procedure code closes with End Sub. Example: <html> <head><title> using function procedure</title> <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> Calling Procedures After creating a procedure, you can call it from another procedure, function or control event in the body section of an HTML file. What is Function procedure? A Function procedure is a series of VBScript statements enclosed by the
ADCPM

VBSCRIPT

Page - 15

Module 3

WEB DESIGNING

August 2010 / BLY

Function and End Function. A Function procedure is similar to a sub procedure, but can also return a value. A Function procedure can take arguments. If a Function has no arguments, its Function statement must include an empty set of parentheses. A Function returns a value by assigning a value to its name in one or more statements of the procedure. The return type of a Function is always a Variant. Example: <html> <head><title>function</title> <script language="vbscript"> dim hour,minute,seconds,convertseconds function getseconds(hrs,mins,sec) getseconds=(hrs*36000+min*60+sec) end function hour=inputbox("enter the value") minute=inputbox("enter the value") seconds=inputbox("enter the value") convertseconds=getseconds(hour,minute,seconds) </script></head> <body> <script language="vbscript"> document.write(convertseconds) </script> </body></html> Example: <html> <head><title> using function procedure</title> <script type="text/vbscript"> function goodbye() alert("Goodbye!") end function function hello() alert("Hello World") end function </script></head> <body onLoad="hello()" onUnLoad="goodbye()"> ELFIN COMPUTER EDUCATION CENTRE<br> Rajendra Nagar, Bareilly <br> </body></html>
z

VBScript Library Functions Date/Time Function:


Function CDate Date
ADCPM

Description Converts a valid date and time expression to the variant of subtype Date Returns the current system date
VBSCRIPT
Page - 16

Module 3

WEB DESIGNING

August 2010 / BLY

DateAdd

Returns a date to which a specified time interval has been added DateDiff Returns the number of intervals between two dates DatePart Returns the specified part of a given date DateSerial Returns the date for a specified year, month, and day DateValue Returns a date Day Returns a number that represents the day of the month (between 1 and 31, inclusive) FormatDateTime Returns an expression formatted as a date or time 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 Returns the name of a specified month Now Returns the current system date and time Second Returns a number that represents the second of the minute (between 0 and 59, inclusive) Time Returns the current system time Timer Returns the number of seconds since 12:00 AM TimeSerial Returns the time for a specific hour, minute, and second TimeValue Returns a time Weekday Returns a number that represents the day of the week (between 1 and 7, inclusive) WeekdayName Returns the weekday name of a specified day of the week Year Returns a number that represents the year

Conversion Functions
Function Asc CBool CByte CCur CDate CDbl Chr CInt
ADCPM

Description Converts the first letter in a string to ANSI code Converts an expression to a variant of subtype Boolean Converts an expression to a variant of subtype Byte Converts an expression to a variant of subtype Currency Converts a valid date & time expression to the variant of subtype Date Converts an expression to a variant of subtype Double Converts the specified ANSI code to a character Converts an expression to a variant of subtype Integer
VBSCRIPT
Page - 17

Module 3

WEB DESIGNING

August 2010 / BLY

CLng CSng CStr Hex Oct

Converts an expression to a variant of subtype Long Converts an expression to a variant of subtype Single Converts an expression to a variant of subtype String Returns the hexadecimal value of a specified number Returns the octal value of a specified number Description Returns an expression formatted as a currency value Returns an expression formatted as a date or time Returns an expression formatted as a number Returns an expression formatted as a percentage

Format Functions
Function FormatCurrency FormatDateTime FormatNumber FormatPercent Function Abs Atn Cos Exp Hex Int Fix Log Oct Rnd Sgn Sin Sqr

Math Functions
Description Returns the absolute value of a specified number Returns the arctangent of a specified number Returns the cosine of a specified number (angle) Returns e raised to a power Returns the hexadecimal value of a specified number Returns the integer part of a specified number Returns the integer part of a specified number Returns the natural logarithm of a specified number Returns the octal value of a specified number Returns a random number less than 1 but greater or equal to 0 Returns an integer that indicates the sign of a specified number Returns the sine of a specified number (angle) Returns the square root of a specified number

String Functions
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 Converts a specified string to lowercase Left Returns a specified number of characters from the left side of a string Len Returns the number of characters in a string LTrim Removes spaces on the left side of a string
ADCPM

VBSCRIPT

Page - 18

Module 3

WEB DESIGNING

August 2010 / BLY

RTrim Trim Mid Replace

Removes spaces on the right side of a string Removes spaces on both the left and the right side of a string Returns a specified number of characters from a string Replaces a specified part of a string with another string a specified number of times Right Returns a specified number of characters from the right side of a string Space Returns a string that consists of a specified number of spaces StrComp Compares two strings and returns a value that represents the result of the comparison String Returns a string that contains a repeating character of a specified length StrReverse Reverses a string UCase Converts a specified string to uppercase

Other Functions
Function CreateObject Eval GetLocale GetObject GetRef InputBox IsEmpty IsNull IsNumeric IsObject LoadPicture MsgBox Description Creates an object of a specified type Evaluates an expression and returns the result Returns the current locale ID Returns a reference to an automation object from a file Allows you to connect a VBScript procedure to a DHTML event on your pages Displays a dialog box, where the user can write some input and/or click on a button, and returns the contents Returns a Boolean value that indicates whether a specified variable has been initialized or not Returns a Boolean value that indicates whether a specified expression contains no valid data (Null) Returns a Boolean value that indicates whether a specified expression can be evaluated as a number Returns a Boolean value that indicates whether the specified expression is an automation object Returns a picture object. Available only on 32-bit platforms Displays a message box, waits for the user to click a button, and returns a value that indicates which button the user clicked Returns a number that represents an RGB color value Rounds a number Returns the scripting language in use
VBSCRIPT
Page - 19

RGB Round ScriptEngine


ADCPM

Module 3

WEB DESIGNING

August 2010 / BLY

ScriptEngineBuild Version ScriptEngineMajor Version ScriptEngineMinor Version TypeName VarType

Returns the build version number of the scripting engine in use Returns the major version number of the scripting engine in use Returns the minor version number of the scripting engine in use Returns the subtype of a specified variable Returns a value that indicates the subtype of a specified variable

Example: Write a program to display the greeting by using Hour (Date/Time) Function. Solution: <html> <head><title> using function procedure</title> <script type="text/vbscript"> function greeting() i=hour(time) if i<12 then alert("Good morning") else alert("Have a nice day") end if end function </script></head> <body onLoad=greeting()> </body></html> Example: Write a program by using Round & Absolute inbuilt function. Solution: <html> <head><title>Stock array</title> <script type="text/VBScript"> dim i,j i=48.565577 j=-18.3333333 </script></head> <body> <script type="text/VBScript"> document.write("Rounding of "&i&" is "& Round(i,1)) document.write("Rounding of "&j&" is "& Round(j,1)) document.write("The absolute value of "&i&" is "& Abs(i)) document.write("The absolute value of "&j&" is "& Abs(j)) </script> </body></html>
Note: If you find any typing or printing error/s, inform immediately to your branch office.
ADCPM

VBSCRIPT

Page - 20