• No results found

VBScript

N/A
N/A
Protected

Academic year: 2021

Share "VBScript"

Copied!
20
0
0

Loading.... (view fulltext now)

Full text

(1)

VBScript Tutorial

VBScript Tutorial

VBScript is a Microsoft scripting language. VBScript is a Microsoft scripting language.

In our VBScript tutorial you will learn how to write VBScript, and how In our VBScript tutorial you will learn how to write VBScript, and how to insert these scripts into your HTML files to make your web pages to insert these scripts into your HTML files to make your web pages more dynamic and interactive.

more dynamic and interactive.

VBScript Introduction

VBScript Introduction

What You Should Already Know

What You Should Already Know

Before you continue you should have a basic understanding of the following: Before you continue you should have a basic understanding of the following:

 WWW, HTML and the basics of building Web pagesWWW, HTML and the basics of building Web pages

What is VBScript?

What is VBScript?

• VBScript is a scripting languageVBScript is a scripting language •

• A scripting language is a lightweight programming languageA scripting language is a lightweight programming language •

• VBScript is a light version of Microsoft's programming language Visual BasicVBScript is a light version of Microsoft's programming language Visual Basic

How Does it Work?

How Does it Work?

When a VBScript is inserted into a HTML document, the Internet browser will read the When a VBScript is inserted into a HTML document, the Internet browser will read the HTML and interpret the VBScript. The VBScript can be executed immediately, or at a HTML and interpret the VBScript. The VBScript can be executed immediately, or at a later event.

later event.

VBScript How To ...

VBScript How To ...

How to Put VBScript Code in an HTML Document

How to Put VBScript Code in an HTML Document

<html> <html> <head> <head> </head> </head>

(2)

<body> <body>

<script type="text/vbscript"> <script type="text/vbscript">

document.write("Hello from VBScript!") document.write("Hello from VBScript!") </script> </script> </body> </body> </html> </html>

And it produces this output: And it produces this output: Hello from VBScript!

Hello from VBScript!

To insert a script in an HTML document, use the <script> tag. Use the type attribute to To insert a script in an HTML document, use the <script> tag. Use the type attribute to define the scripting language.

define the scripting language.

<script type="text/vbscript"> <script type="text/vbscript">

Then comes the VBScript: The command for writing some text on a page is Then comes the VBScript: The command for writing some text on a page is document.write

document.write::

document.write("Hello from VBScript!") document.write("Hello from VBScript!")

The script ends: The script ends:

</script> </script>

How to Handle Older Browsers

How to Handle Older Browsers

Older browsers that do not support scripts will display the script as page content. To Older browsers that do not support scripts will display the script as page content. To prevent them from doing this, you can use the HTML comment tag:

prevent them from doing this, you can use the HTML comment tag:

<script type="text/vbscript"> <script type="text/vbscript"> <!--some statements some statements --> --> </script> </script>

VBScript Where To ...

VBScript Where To ...

Where to Put the VBScript

Where to Put the VBScript

(3)

Scripts in a page will be executed immediately while the page loads into the browser. Scripts in a page will be executed immediately while the page loads into the browser. This is not always what we want. Sometimes we want to execute a script when a page This is not always what we want. Sometimes we want to execute a script when a page loads, other times when a user triggers an event.

loads, other times when a user triggers an event. Scripts in the head section:

Scripts in the head section: Scripts to be executed when they are called or when anScripts to be executed when they are called or when an event is triggered go in the head section. When you place a script in the head section you event is triggered go in the head section. When you place a script in the head section you will assure that the script is loaded before anyone uses it:

will assure that the script is loaded before anyone uses it:

<html> <html> <head> <head> <script type="text/vbscript"> <script type="text/vbscript"> some statements some statements </script> </script> </head> </head>

Scripts in the body section:

Scripts in the body section: Scripts to be executed when the page loads go in the bodyScripts to be executed when the page loads go in the body section. When you place a script in the body section it generates the content of the page: section. When you place a script in the body section it generates the content of the page:

<html> <html> <head> <head> </head> </head> <body> <body> <script type="text/vbscript"> <script type="text/vbscript"> some statements some statements </script> </script> </body> </body>

Scripts in both the body and the head section:

Scripts in both the body and the head section: You can place an unlimited number of You can place an unlimited number of  scripts in your document, so you can have scripts in both the body and the head section. scripts in your document, so you can have scripts in both the body and the head section.

<html> <html> <head> <head> <script type="text/vbscript"> <script type="text/vbscript"> some statements some statements </script> </script> </head> </head> <body> <body> <script type="text/vbscript"> <script type="text/vbscript"> some statements some statements </script> </script> </body> </body>

VBScript Variables

VBScript Variables

What is a Variable?

What is a Variable?

(4)

A variable is a "container" for information you want to store. A variable's value can A variable is a "container" for information you want to store. A variable's value can

change during the script. You can refer to a variable by name to see its value or to change change during the script. You can refer to a variable by name to see its value or to change its value. In VBScript, all variables are of type

its value. In VBScript, all variables are of type variant variant , that can store different types of , that can store different types of 

data. data.

Rules for Variable Names:

Rules for Variable Names:

• Must begin with a letterMust begin with a letter •

• Cannot contain a period (.)Cannot contain a period (.) •

• Cannot exceed 255 charactersCannot exceed 255 characters

Declaring Variables

Declaring Variables

You can declare variables with the Dim, Public or the Private statement. Like this: You can declare variables with the Dim, Public or the Private statement. Like this:

dim name dim name

name=some value name=some value

Now you have created a variable. The name of the variable is "name". Now you have created a variable. The name of the variable is "name". You can also declare variables by using its name in your script. Like this: You can also declare variables by using its name in your script. Like this:

name=some value name=some value

Now you have also created a variable. The name of the variable is "name". Now you have also created a variable. The name of the variable is "name".

However, the last method is not a good practice, because you can misspell the variable However, the last 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. name later in your script, and that can cause strange results when your script is running. This is because when you misspell for example the "name" variable to "nime" the script This is because when you misspell for example the "name" variable to "nime" the script will automatically create a n

will automatically create a new variable calleew variable called "nime". d "nime". To prevent your scTo prevent your script from doingript from doing this you can use the Option Explicit statement. When you use this statement you will have this you can use the Option Explicit statement. When you use this statement you will have to declare all your variables with the dim, public or private statement. Put the Option to declare all your variables with the dim, public or private statement. Put the Option Explicit statemen

Explicit statement on the t on the of your scof your script. Like this:ript. Like this:

option explicit option explicit dim name dim name name=some value name=some value

Assigning Values to Variables

Assigning Values to Variables

You assign a value to a variable like this: You assign a value to a variable like this:

(5)

name="Hege" name="Hege" i=200

i=200

The variable name is on the left side of the expression and the value you want to assign to 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 "name" has the value "Hege".

the variable is on the right. Now the variable "name" has the value "Hege".

Lifetime of Variables

Lifetime of Variables

How long a variable exists is its lifetime. How long a variable exists is its lifetime.

When you declare a variable within a procedure, the variable can only be accessed within 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 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 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. 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 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 it. The lifetime of these variables starts when they are declared, and ends when the page is closed.

closed.

Array Variables

Array Variables

Sometimes you want to assign more than one value to a single variable. Then you can Sometimes you want to assign more than one value to a single variable. Then you can create a variable that can contain a series of values. This is called an array variable. The create a variable that can contain a series of values. This is called an array variable. The declaration of an array variable uses parentheses ( ) following the variable name. In the declaration of an array variable uses parentheses ( ) following the variable name. In the following example, an array containing 3 elements is declared:

following example, an array containing 3 elements is declared:

dim names(2) dim names(2)

The number shown in the parentheses is 2. We start at zero so this array contains 3 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 elements. This is a fixed-size array. You assign data to each of the elements of the array like this: like this: names(0)="Tove" names(0)="Tove" names(1)="Jani" names(1)="Jani" names(2)="Stale" names(2)="Stale"

Similarly, the data can be retrieved from any element using the index of the particular Similarly, the data can be retrieved from any element using the index of the particular array element you want. Like this:

array element you want. Like this:

mother=names(0) mother=names(0)

(6)

You can have up to 60 dimensions in an array. Multiple dimensions are declared by 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 separating the numbers in the parentheses with commas. Here we have a two-dimensional array consisting of 5 rows and 7 columns:

array consisting of 5 rows and 7 columns:

dim table(4, 6) dim table(4, 6)

VBScript Procedures

VBScript Procedures

VBScript Procedures

VBScript Procedures

We have two kinds of procedures: The Sub procedure and the Function procedure. We have two kinds of procedures: The Sub procedure and the Function procedure. A Sub procedure:

A Sub procedure:

• is a series of statements, enclosed by the Sub and End Sub statementsis a series of statements, enclosed by the Sub and End Sub statements •

• can perform actions, butcan perform actions, but does not returndoes not return a valuea value •

• can take arguments that are passed to it by a calling procedurecan take arguments that are passed to it by a calling procedure •

• without arguments, must include an empty set of parentheses ()without arguments, must include an empty set of parentheses ()

Sub mysub() Sub mysub() some statements some statements End Sub End Sub or or Sub mysub(argument1,argument2) Sub mysub(argument1,argument2) some statements some statements End Sub End Sub A Function procedure: A Function procedure: •

• is a series of statements, enclosed by the Function and End Function statementsis a series of statements, enclosed by the Function and End Function statements •

• can perform actions andcan perform actions and can returncan return a valuea value •

• can take arguments that are passed to it by a calling procedurecan take arguments that are passed to it by a calling procedure •

• without arguments, must include an empty set of parentheses ()without arguments, must include an empty set of parentheses () •

• returns a value by assigning a value to its namereturns a value by assigning a value to its name

Function myfunction() Function myfunction() some statements some statements myfunction=some value myfunction=some value End Function End Function

(7)

or or Function myfunction(argument1,argument2) Function myfunction(argument1,argument2) some statements some statements myfunction=some value myfunction=some value End Function End Function

Call a Sub or Function Procedure

Call a Sub or Function Procedure

When you call a Function in your code, you do like this: When you call a Function in your code, you do like this:

name = findname() name = findname()

Here you call a Function called "findname", the Function returns a value that will be Here you call a Function called "findname", the Function returns a value that will be stored in the variable "name".

stored in the variable "name". Or, you can do like this:

Or, you can do like this:

msgbox "Your name is " & findname() msgbox "Your name is " & findname()

Here you also call a Function called "findname", the Function returns a value that will be Here you also call a Function called "findname", the Function returns a value that will be displayed in the message box.

displayed in the message box.

When you call a Sub procedure you can use the Call statement, like this: When you call a Sub procedure you can use the Call statement, like this:

Call MyProc(argument) Call MyProc(argument)

Or, you can omit the Call statement, like this: Or, you can omit the Call statement, like this:

MyProc argument MyProc argument

(8)

VBScript Conditional Statements

VBScript Conditional Statements

Conditional Statements

Conditional Statements

Very often when you write code, you want to perform different actions for different Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do this.

decisions. You can use conditional statements in your code to do this. In VBScript we have four conditional statements:

In VBScript we have four conditional statements:

• if statementif statement - use this statement if you want to execute a set of code when a- use this statement if you want to execute a set of code when a

condition is true condition is true

• if...then...else statementif...then...else statement - use this statement if you want to select one of two sets- use this statement if you want to select one of two sets

of lines to execute of lines to execute

• if...then...elseif statementif...then...elseif statement - use this statement if you want to select one of many- use this statement if you want to select one of many

sets of lines to execute sets of lines to execute

• select case statementselect case statement - use this statement if you want to select one of many sets- use this statement if you want to select one of many sets

of lines to execute of lines to execute

If....Then...Else

If....Then...Else

You should use the If...Then...Else statement if you want to You should use the If...Then...Else statement if you want to

• execute some code if a condition is trueexecute some code if a condition is true •

• select one of two blocks of code to executeselect one of two blocks of code to execute

If you want to execute only

If you want to execute only oneone statement when a condition is true, you can write thestatement when a condition is true, you can write the code on one line:

code on one line:

if i=10 Then msgbox "Hello" if i=10 Then msgbox "Hello"

There is no ..else.. in this syntax. You just tell the code to perform

There is no ..else.. in this syntax. You just tell the code to perform one actionone action if theif the condition is true (in this case if i=10).

condition is true (in this case if i=10). If you want to execute

If you want to execute more than onemore than one statement when a condition is true, you must putstatement when a condition is true, you must put each statement on separate lines and end the statement with the keyword "End If": each statement on separate lines and end the statement with the keyword "End If":

if i=10 Then if i=10 Then msgbox "Hello" msgbox "Hello" i = i+1 i = i+1 end If end If

(9)

There is no ..else.. in this syntax either. You just tell the code to perform

There is no ..else.. in this syntax either. You just tell the code to perform multiple actionsmultiple actions if the condition is true.

if the condition is true.

If you want to execute a statement if a condition is true and execute another statement if  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:

the condition is not true, you must add the "Else" keyword:

if i=10 then if i=10 then msgbox "Hello" msgbox "Hello" else else msgbox "Goodbye" msgbox "Goodbye" end If end If

The first block of code will be executed if the condition is true, and the other block will The first block of code will be executed if the condition is true, and the other block will be executed otherwise (if i is not equal to 10).

be executed otherwise (if i is not equal to 10).

If....Then...Elseif 

If....Then...Elseif 

You can use the if...then...elseif statement if you want to select one of many blocks of  You can use the if...then...elseif statement if you want to select one of many blocks of  code to execute:

code to execute:

if payment="Cash" then if payment="Cash" then

msgbox "You are going to pay cash!" msgbox "You are going to pay cash!" elseif payment="Visa" then

elseif payment="Visa" then

msgbox "You are going to pay with visa." msgbox "You are going to pay with visa." elseif payment="AmEx" then

elseif payment="AmEx" then

msgbox "You are going to pay with American Express." msgbox "You are going to pay with American Express." else

else

msgbox "Unknown method of payment." msgbox "Unknown method of payment." end If

end If

Select Case

Select Case

You can also use the SELECT statement if you want to select one of many blocks of code You can also use the SELECT statement if you want to select one of many blocks of code to execute:

to execute:

select case payment select case payment

case "Cash" case "Cash"

msgbox "You are going to pay cash" msgbox "You are going to pay cash" case "Visa"

case "Visa"

msgbox "You are going to pay with visa" msgbox "You are going to pay with visa" case "AmEx"

case "AmEx"

msgbox "You are going to pay with American Express" msgbox "You are going to pay with American Express" case Else

case Else

msgbox "Unknown method of payment" msgbox "Unknown method of payment" end select

(10)

This is how it works: First we have a single expression (most often a variable), that is 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 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 Case in the structure. If there is a match, the block of code associated with that Case is executed.

(11)

VBScript Looping Statements

VBScript Looping Statements

Looping Statements

Looping Statements

Very often when you write code, you want to allow the same block of code to run a Very often when you write code, you want to allow the same block of code to run a number of times. You can use looping statements in your code to do this.

number of times. You can use looping statements in your code to do this. In VBScript we have four looping statements:

In VBScript we have four looping statements:

• For...Next statementFor...Next statement - runs statements a specified number of times.- runs statements a specified number of times. •

• For Each...Next statementFor Each...Next statement - runs statements for each item in a collection or each- runs statements for each item in a collection or each

element of an array element of an array

• Do...Loop statementDo...Loop statement - loops while or until a condition is true- loops while or until a condition is true •

• While...Wend statementWhile...Wend statement - Do not use it - use the Do...Loop statement instead- Do not use it - use the Do...Loop statement instead

For...Next Loop

For...Next Loop

You can use a

You can use a For...NextFor...Next statement to run a block of code, when you know how manystatement to run a block of code, when you know how many repetitions you want.

repetitions you want.

You can use a counter variable that increases or decreases with each repetition of the You can use a counter variable that increases or decreases with each repetition of the loop, like this:

loop, like this:

For i=1 to 10 For i=1 to 10 some code some code Next Next The

The ForFor statement specifies the counter variable (statement specifies the counter variable (ii) and its start and end values. The) and its start and end values. The NextNext statement increases the counter variable (

statement increases the counter variable ( ii) by one.) by one.

Step Keyword

Step Keyword

Using the

Using the StepStep keyword, you can increase or decrease the counter variable by the valuekeyword, you can increase or decrease the counter variable by the value you specify.

you specify.

In the example below, the counter variable (

In the example below, the counter variable (ii) is increased by two each time the loop) is increased by two each time the loop repeats.

repeats.

For i=2 To 10 Step 2 For i=2 To 10 Step 2

some code some code

(12)

Next Next

To decrease the counter variable, you must use a negative

To decrease the counter variable, you must use a negative StepStep value. You must specifyvalue. You must specify an end value that is less than the start value.

an end value that is less than the start value. In the example below, the counter variable (

In the example below, the counter variable (ii) is decreased by two each time the loop) is decreased by two each time the loop repeats.

repeats.

For i=10 To 2 Step -2 For i=10 To 2 Step -2

some code some code Next Next

Exit a For...Next

Exit a For...Next

You can exit a For...Next statement with the Exit For keyword. You can exit a For...Next statement with the Exit For keyword.

For Each...Next Loop

For Each...Next Loop

A

A For Each...NextFor Each...Next loop repeats a block of code for each item in a collection, or for eachloop repeats a block of code for each item in a collection, or for each element of an array. element of an array. dim cars(2) dim cars(2) cars(0)="Volvo" cars(0)="Volvo" cars(1)="Saab" cars(1)="Saab" cars(2)="BMW" cars(2)="BMW"

For Each x in cars For Each x in cars

document.write(x & "<br />") document.write(x & "<br />") Next Next

Do...Loop

Do...Loop

You can use Do...Loop statements to run a block of code when you do not know how You can use Do...Loop statements to run a block of code when you do not know how many repetitions you want. The block of code is repeated while a condition is true or many repetitions you want. The block of code is repeated while a condition is true or until a condition becomes true.

until a condition becomes true.

Repeating Code While a Condition is True

Repeating Code While a Condition is True

You use the While keyword to check a condition in a Do...Loop statement. You use the While keyword to check a condition in a Do...Loop statement.

Do While i>10 Do While i>10 some code some code Loop Loop

(13)

If 

If ii equals 9, the code inside the loop above will never be executed.equals 9, the code inside the loop above will never be executed.

Do Do

some code some code Loop While i>10 Loop While i>10

The code inside this loop will be executed at least one time, even if 

The code inside this loop will be executed at least one time, even if  ii is less than 10.is less than 10.

Repeating Code Until a Condition Becomes True

Repeating Code Until a Condition Becomes True

You use the Until keyword to check a condition in a Do...Loop statement. You use the Until keyword to check a condition in a Do...Loop statement.

Do Until i=10 Do Until i=10 some code some code Loop Loop If 

If ii equals 10, the code inside the loop will never be executed.equals 10, the code inside the loop will never be executed.

Do Do

some code some code Loop Until i=10 Loop Until i=10

The code inside this loop will be executed at least one time, even if 

The code inside this loop will be executed at least one time, even if  ii is equal to 10.is equal to 10.

Exit a Do...Loop

Exit a Do...Loop

You can exit a Do...Loop statement with the Exit Do keyword. You can exit a Do...Loop statement with the Exit Do keyword.

Do Until i=10 Do Until i=10

i=i-1 i=i-1

If i<10 Then Exit Do If i<10 Then Exit Do Loop

Loop

The code inside this loop will be executed as long as

The code inside this loop will be executed as long as ii is different from 10, and as long asis different from 10, and as long as ii is greater than 10.is greater than 10.

You Have Learned VBScript, Now What?

You Have Learned VBScript, Now What?

VBScript Summary

VBScript Summary

This tutorial has taught you how to add VBScript to your HTML pages, to make your This tutorial has taught you how to add VBScript to your HTML pages, to make your web site more dynamic and interactive.

(14)

You have learned how to create variables and functions, and how to make different You have learned how to create variables and functions, and how to make different scripts run in response to different scenarios.

scripts run in response to different scenarios.

Now You Know VBScript, What's Next?

Now You Know VBScript, What's Next?

The next step is to learn ASP. The next step is to learn ASP.

While scripts in an HTML file are executed on the client (in the browser), scripts in an While scripts in an HTML file are executed on the client (in the browser), scripts in an ASP file are executed on the server.

ASP file are executed on the server.

With ASP you can dynamically edit, change or add any content of a Web page, respond With ASP you can dynamically edit, change or add any content of a Web page, respond to data submitted from HTML forms, access any data or databases and return the results to data submitted from HTML forms, access any data or databases and return the results to a browser, customize a Web page to make it more useful for individual users.

to a browser, customize a Web page to make it more useful for individual users. Since ASP files are returned as plain HTML, they can be viewed in any browser. Since ASP files are returned as plain HTML, they can be viewed in any browser.

(15)

VBScript Functions

VBScript Functions

This page contains all the built-in VBScript functions. The page is divided into following This page contains all the built-in VBScript functions. The page is divided into following sections:

sections:

• Date/Time functionsDate/Time functions •

• Conversion functionsConversion functions

• Format functionsFormat functions

• Math functionsMath functions

• Array functionsArray functions

• String functionsString functions

• Other functionsOther functions

Date/Time Functions

Date/Time Functions

F

Fuunnccttiioon n DDeessccrriippttiioonn CDate

CDate Converts a valid date and time expression to the variant of Converts a valid date and time expression to the variant of  subtype Date

subtype Date Date

Date Returns the current system dateReturns the current system date DateAdd

DateAdd Returns a date to which a specified time interval has beenReturns a date to which a specified time interval has been added

added DateDiff 

DateDiff  Returns the number of intervals between two datesReturns the number of intervals between two dates DatePart

DatePart Returns the specified part of a given dateReturns the specified part of a given date DateSerial

DateSerial Returns the date for a specified year, month, and dayReturns the date for a specified year, month, and day DateValue

DateValue Returns a dateReturns a date Day

Day Returns a number that represents the day of the monthReturns a number that represents the day of the month (between 1 and 31, inclusive)

(between 1 and 31, inclusive) FormatDateTime

FormatDateTime Returns an expression formatted as a date or timeReturns an expression formatted as a date or time Hour

Hour Returns a number that represents the hour of the dayReturns a number that represents the hour of the day (between 0 and 23, inclusive)

(between 0 and 23, inclusive) IsDate

IsDate Returns a Boolean value that indicates if the evaluatedReturns a Boolean value that indicates if the evaluated expression can be converted to a date

expression can be converted to a date Minute

Minute Returns a number that represents the minute of the hourReturns a number that represents the minute of the hour (between 0 and 59, inclusive)

(between 0 and 59, inclusive) Month

Month Returns a number that represents the month of the yearReturns a number that represents the month of the year (between 1 and 12, inclusive)

(between 1 and 12, inclusive) MonthName

MonthName Returns the name of a specified monthReturns the name of a specified month Now

(16)

Second

Second Returns a number that represents the second of the minuteReturns a number that represents the second of the minute (between 0 and 59, inclusive)

(between 0 and 59, inclusive) Time

Time Returns the current system timeReturns the current system time Timer

Timer Returns the number of seconds since 12:00 AMReturns the number of seconds since 12:00 AM TimeSerial

TimeSerial Returns the time for a specific hour, minute, and secondReturns the time for a specific hour, minute, and second TimeValue

TimeValue Returns a timeReturns a time Weekday

Weekday Returns a number that represents the day of the week Returns a number that represents the day of the week  (between 1 and 7, inclusive)

(between 1 and 7, inclusive) WeekdayName

WeekdayName Returns the weekday name of a specified day of the week Returns the weekday name of a specified day of the week  Year

Year Returns a number that represents the yearReturns a number that represents the year

Conversion Functions

Conversion Functions

F

Fuunnccttiioon n DDeessccrriippttiioonn Asc

Asc Converts the first letter in a string to ANSI codeConverts the first letter in a string to ANSI code CBool

CBool Converts an expression to a variant of subtype BooleanConverts an expression to a variant of subtype Boolean CByte

CByte Converts an expression to a variant of subtype ByteConverts an expression to a variant of subtype Byte CCur

CCur Converts an expression to a variant of subtype CurrencyConverts an expression to a variant of subtype Currency CDate

CDate Converts a valid date and time expression to the variant of Converts a valid date and time expression to the variant of  subtype Date

subtype Date CDbl

CDbl Converts an expression to a variant of subtype DoubleConverts an expression to a variant of subtype Double Chr

Chr Converts the specified ANSI code to a characterConverts the specified ANSI code to a character CInt

CInt Converts an expression to a variant of subtype IntegerConverts an expression to a variant of subtype Integer CLng

CLng Converts an expression to a variant of subtype LongConverts an expression to a variant of subtype Long CSng

CSng Converts an expression to a variant of subtype SingleConverts an expression to a variant of subtype Single CStr

CStr Converts an expression to a variant of subtype StringConverts an expression to a variant of subtype String Hex

Hex Returns the hexadecimal value of a specified numberReturns the hexadecimal value of a specified number Oct

Oct Returns the octal value of a specified numberReturns the octal value of a specified number

Format Functions

Format Functions

F

Fuunnccttiioon n DDeessccrriippttiioonn FormatCurrency

FormatCurrency Returns an expression formatted as a currency valueReturns an expression formatted as a currency value FormatDateTime

FormatDateTime Returns an expression formatted as a date or timeReturns an expression formatted as a date or time FormatNumber

(17)

FormatPercent

FormatPercent Returns an expression formatted as a percentageReturns an expression formatted as a percentage

Math Functions

Math Functions

F

Fuunnccttiioon n DDeessccrriippttiioonn Abs

Abs Returns the absolute value of a specified numberReturns the absolute value of a specified number Atn

Atn Returns the arctangent of a specified numberReturns the arctangent of a specified number Cos

Cos Returns the cosine of a specified number (angle)Returns the cosine of a specified number (angle) Exp

Exp ReturnsReturnsee raised to a powerraised to a power

Hex

Hex Returns the hexadecimal value of a specified numberReturns the hexadecimal value of a specified number Int

Int Returns the integer part of a specified numberReturns the integer part of a specified number Fix

Fix Returns the integer part of a specified numberReturns the integer part of a specified number Log

Log Returns the natural logarithm of a specified numberReturns the natural logarithm of a specified number Oct

Oct Returns the octal value of a specified numberReturns the octal value of a specified number Rnd

Rnd Returns a random number less than 1 but greater or equal to 0Returns a random number less than 1 but greater or equal to 0 Sgn

Sgn Returns an integer that indicates the sign of a specifiedReturns an integer that indicates the sign of a specified number

number Sin

Sin Returns the sine of a specified number (angle)Returns the sine of a specified number (angle) Sqr

Sqr Returns the square root of a specified numberReturns the square root of a specified number Tan

Tan Returns the tangent of a specified number (angle)Returns the tangent of a specified number (angle)

Array Functions

Array Functions

F

Fuunnccttiioon n DDeessccrriippttiioonn Array

Array Returns a variant containing an arrayReturns a variant containing an array Filter

Filter Returns a zero-based array that contains a subset of a stringReturns a zero-based array that contains a subset of a string array based on a filter criteria

array based on a filter criteria IsArray

IsArray Returns a Boolean value that indicates whether a specifiedReturns a Boolean value that indicates whether a specified variable is an array

variable is an array Join

Join Returns a string that consists of a number of substrings in anReturns a string that consists of a number of substrings in an array

array LBound

LBound Returns the smallest subscript for the indicated dimension of Returns the smallest subscript for the indicated dimension of  an array

an array Split

Split Returns a zero-based, one-dimensional array that contains aReturns a zero-based, one-dimensional array that contains a specified number of substrings

specified number of substrings UBound

(18)

array array

String Functions

String Functions

F

Fuunnccttiioon n DDeessccrriippttiioonn InStr

InStr Returns the position of the first occurrence of one stringReturns the position of the first occurrence of one string within another. The search begins at the first character of the within another. The search begins at the first character of the string

string InStrRev

InStrRev Returns the position of the first occurrence of one stringReturns the position of the first occurrence of one string within another. The search begins at the last character of the within another. The search begins at the last character of the string

string LCase

LCase Converts a specified string to lowercaseConverts a specified string to lowercase Left

Left Returns a specified number of characters from the left side of Returns a specified number of characters from the left side of  a string

a string Len

Len Returns the number of characters in a stringReturns the number of characters in a string LTrim

LTrim Removes spaces on the left side of a stringRemoves spaces on the left side of a string RTrim

RTrim Removes spaces on the right side of a stringRemoves spaces on the right side of a string Trim

Trim Removes spaces on both the left and the right side of a stringRemoves spaces on both the left and the right side of a string Mid

Mid Returns a specified number of characters from a stringReturns a specified number of characters from a string Replace

Replace Replaces a specified part of a string with another string aReplaces a specified part of a string with another string a specified number of times

specified number of times Right

Right Returns a specified number of characters from the right sideReturns a specified number of characters from the right side of a string

of a string Space

Space Returns a string that consists of a specified number of spacesReturns a string that consists of a specified number of spaces StrComp

StrComp Compares two strings and returns a value that represents theCompares two strings and returns a value that represents the result of the comparison

result of the comparison String

String Returns a string that contains a repeating character of aReturns a string that contains a repeating character of a specified length

specified length StrReverse

StrReverse Reverses a stringReverses a string UCase

UCase Converts a specified string to uppercaseConverts a specified string to uppercase

Other Functions

Other Functions

F

Fuunnccttiioon n DDeessccrriippttiioonn CreateObject

CreateObject Creates an object of a specified typeCreates an object of a specified type E

(19)

GetLocale

GetLocale Returns the current locale IDReturns the current locale ID GetObject

GetObject Returns a reference to an automation object from a fileReturns a reference to an automation object from a file GetRef 

GetRef  Allows you to connect a VBScript procedure to a DHTMLAllows you to connect a VBScript procedure to a DHTML event on your pages

event on your pages InputBox

InputBox Displays a dialog box, where the user can write some inputDisplays a dialog box, where the user can write some input and/or click on a button, and returns the contents

and/or click on a button, and returns the contents IsEmpty

IsEmpty Returns a Boolean value that indicates whether a specifiedReturns a Boolean value that indicates whether a specified variable has been initialized or not

variable has been initialized or not IsNull

IsNull Returns a Boolean value that indicates whether a specifiedReturns a Boolean value that indicates whether a specified expression contains no valid data (Null)

expression contains no valid data (Null) IsNumeric

IsNumeric Returns a Boolean value that indicates whether a specifiedReturns a Boolean value that indicates whether a specified expression can be evaluated as a number

expression can be evaluated as a number IsObject

IsObject Returns a Boolean value that indicates whether the specifiedReturns a Boolean value that indicates whether the specified expression is an automation object

expression is an automation object LoadPicture

LoadPicture Returns a picture object. Available only on 32-bit platformsReturns a picture object. Available only on 32-bit platforms MsgBox

MsgBox Displays a message box, waits for the user to click a button,Displays a message box, waits for the user to click a button, and returns a value that indicates which button the user and returns a value that indicates which button the user clicked

clicked RGB

RGB Returns a number that represents an RGB color valueReturns a number that represents an RGB color value Round

Round Rounds a numberRounds a number ScriptEngine

ScriptEngine Returns the scripting language in useReturns the scripting language in use ScriptEngineBuildVersion

ScriptEngineBuildVersion Returns the build version number of the scripting engine inReturns the build version number of the scripting engine in use

use ScriptEngineMajorVersion

ScriptEngineMajorVersion Returns the major version number of the scripting engine inReturns the major version number of the scripting engine in use

use ScriptEngineMinorVersion

ScriptEngineMinorVersion Returns the minor version number of the scripting engine inReturns the minor version number of the scripting engine in use

use SetLocale

SetLocale Sets the locale ID and returns the previous locale IDSets the locale ID and returns the previous locale ID TypeName

TypeName Returns the subtype of a specified variableReturns the subtype of a specified variable VarType

VarType Returns a value that indicates the subtype of a specifiedReturns a value that indicates the subtype of a specified variable

variable

VBScript Keywords

VBScript Keywords

K

Keeyywwoorrd d DDeessccrriippttiioonn

(20)

is uninitialized when it is first created and no value is assigned to is uninitialized when it is first created and no value is assigned to it, or when a variable value is explicitly set to empty.

it, or when a variable value is explicitly set to empty. Example:

Example: dim

dim x x 'the 'the variable variable x x is is uninitialized!uninitialized! x="ff"

x="ff" 'the va'the variable x riable x is Nis NOT uninitiaOT uninitialized alized anymorenymore x=empty

x=empty 'the 'the variable variable x x is is uninitialized!uninitialized! Note:

Note: This is not the same as Null!!This is not the same as Null!! iissEEmmpptty y UUsseed d tto o tteesst t iif f a a vvaarriiaabblle e iis s uunniinniittiiaalliizzeedd..

Example: If (isEmpty(x)) 'is x uninitialized? Example: If (isEmpty(x)) 'is x uninitialized? n

notothhining g UUsesed d to to ininddicicatate e an an ununininititiaialilizzeed d obobjeject ct vvalaluuee, , oor r to to didissasassosocciaiatete an object variable from an object to release system resources. an object variable from an object to release system resources. Example: set myObject=nothing

Example: set myObject=nothing is

is nonoththining g UUsesed d to to tetest st if if a a vvaalulue e is is aan n ininititiaialilizzeed d obobjejecct.t. Example: If (myObject Is Nothing) 'is it unset? Example: If (myObject Is Nothing) 'is it unset? Note:

Note: If you compare a value to Nothing, you will not get theIf you compare a value to Nothing, you will not get the right result! Example: If (myObject = Nothing) 'always false! right result! Example: If (myObject = Nothing) 'always false! n

nuulll l UUsseed d tto o iinnddiiccaatte e tthhaat t a a vvaarriiaabblle e ccoonnttaaiinns s nno o vvaalliid d ddaattaa..

One way to think of Null is that someone has explicitly set the One way to think of Null is that someone has explicitly set the value to "invalid", unlike Empty where the value is "not set". value to "invalid", unlike Empty where the value is "not set". Note:

Note: This is not the same as Empty or Nothing!!This is not the same as Empty or Nothing!! Example: x=Null 'x contains no valid data

Example: x=Null 'x contains no valid data iissNNuulll l UUsseed d tto o tteesst t iif f a a vvaalluue e ccoonnttaaiinns s iinnvvaalliid d ddaattaa..

Example: if (isNull(x)) 'is x invalid? Example: if (isNull(x)) 'is x invalid?

ttrruue e UUsseed d tto o iinnddiiccaatte e a a BBoooolleeaan n ccoonnddiittiioon n tthhaat t iis s ccoorrrreecct t ((ttrruue e hhaas s aa value of -1)

value of -1)

ffaallsse e UUsseed d tto o iinnddiiccaatte e a a BBoooolleeaan n ccoonnddiittiioon n tthhaat t iis s nnoot t ccoorrrerecct t ((ffaallsse e hhaass a value of 0)

References

Related documents

 Primerden akan akım sıfır olur  Olay sonucunda primer sargıya normalinden çok daha yüksek bir gerilim düşer  Trafo doyar  Sekonder gerilimi yükselir

Here simulation will be done for prototype and performance of settling basin will be investigated with different respects such as Hydraulic performance, flow distribution,

Welcome from Dr Peter Baxter, Consultant Paediatric Neurologist, Sheffield 11.00 – 12.15 Session 1: Epilepsy oral presentations?. Chairs: Dr Chris Rittey &amp; Dr

Product mix is shifting towards Google and new customer sales have declined dramatically Product mix is shifting towards Google and new customer sales have declined dramatically

z All projects can be divided into phases z Project Life Cycle is all phases together z Each phase marked by Deliverables. z Same for software

While significant interactive coefficients display signs that are similar to those obtained using straight retail categories (i.e., positive for higher order goods and negative

First, we study social and economic impact at the household level, classifying households according to the needs for care of older residents at the time of the baseline and

 Starting-point 1: Comparison of the standardized ileal amino acid digestibility for well-studied feedstuffs in broilers (=SIDC-broilers) with the standardized ileal amino