You are on page 1of 167

Abs function

Returns the absolute value.

Abs (number)
The number argument can be any valid numeric expression. If number contains Null, return
Null; if it is an uninitialized variable, zero is returned.

Explain
The absolute value is its unsigned magnitude. For example, Abs (-1) and Abs (1) returns 1.

The following example uses the Abs function to compute the absolute value of:

Dim MyNumber
MyNumber = Abs (50.3) 'returns 50.3.
MyNumber = Abs (-50.3) 'returns 50.3.
Returns an array of Variant.

Array (arglist)
arglist argument is assigned to a Variant containing the array elements in a list of values
(separated by commas). If you do not specify this parameter, you will create a zero-length
array.

Explain
Used to refer to array elements of said symbol, followed by the composition of the variable
name in brackets, braces indicate required elements included in the index. In the following
example, the first statement creates a variable named A. The second statement assigns an
array variable A. The last statement will be included in the second array element value is
assigned to another variable.

Dim A
A = Array (10,20,30)
B = A (2) 'B is now 30.
Note that the variable is not declared as an array can still contain an array. Although a Variant
variable containing an array with array variable containing Variant elements are conceptually
different, but the access array elements are the same.
Requirements
Version 2

Asc function
Please refer to the
Chr function
Requirements
Version 1
Returns a string corresponding to the first letter of the ANSI character code.
Asc (string)
string argument is any valid string expression. If the string contains no characters, a runtime
error occurs.

Explain
The following example, Asc returns a string first letter of each ANSI character code:

Dim MyNumber
MyNumber = Asc ("A") 'Return 65.
MyNumber = Asc ("a") 'Return 97.
MyNumber = Asc ("Apple") 'Return 65.
Note AscB function and contains the byte data strings. AscB not return the first character of
the character code, but returns the first byte. AscW use Unicode characters for 32-bit
platforms available. It returns the Unicode (wide) character code, thereby avoiding the code
from ANSI to Unicode conversion.
Requirements
Version 1
Atn function

Returns the arctangent of the value.

Atn (number)

The number argument can be any valid numeric expression.

Explain
Atn function calculating the ratio of two sides of a right triangle (number) and returns the
corresponding angle in radians. This ratio is the length and angle on the edge of the adjacent
side length ratio. The results range from-pi / 2 to pi / 2 radians.

Transformed into the angle of curvature of the arc is multiplied by pi/180. On the contrary,
changing the angle in radians is the angle multiplied by 180/pi.

The following example uses Atn to calculate the value of pi:

Dim pi
pi = 4 * Atn (1) 'calculate the value of pi.
Note Atn is Tan (angle as a parameter to return the ratio of both sides of a right triangle) the
inverse trigonometric functions. Do not confuse Atn with the cotangent (tangent of the
reciprocal (1/tangent)) function.
Requirements
Version 1
Pass control to a Sub or Function procedure.

 [Call] name [argumentlist]


Parameter
Call
Optional keyword. If you specify this keyword, you must use parentheses to enclose
argumentlist. For example:
Call MyProc (0)

name
Required. To invoke the procedure name.
argumentlist
Available options. Passed to the process variable, array or list of expressions, each separated
by a comma.
Explain
When calling a procedure, do not use the Call keyword. However, if the request parameters
using the Call keyword to call the process, you must use parentheses to enclose argumentlist.
If you omit the Call keyword, you must also omit the parentheses around argumentlist
parameters. Use Call syntax to call an internal function or user-defined function, the function
return value is discarded.

Call MyFunction ("Hello World")


Function MyFunction (text)
   MsgBox text
End Function
Requirements
Version 1
Returns an expression that has been converted to Boolean subtype Variant.

CBool (expression)
expression is any valid expression.

Explain
If expression is zero, then return False; otherwise returns True. If the expression can not be
interpreted as a value, then a runtime error occurs.

The following example uses the CBool function to an expression into a Boolean type. If the
expression calculated value is nonzero, then the CBool function returns True; otherwise it
returns False.

Dim A, B, Check
A = 5: B = 5 'Initialize variables.
Check = CBool (A = B) 'check box is set to True.
A = 0 'define variables.
Check = CBool (A) 'check box is set to False.
Requirements
Version 1
CByte (expression)
expression argument is any valid expression.

Explain
Typically, you can use to write code type conversion functions to show the result of some
operation should be expressed as a specific data type, instead of the default type. For
example, where currency, single, double, or integer arithmetic cases, the use CByte enforce
byte operations.

CByte function used for other data types to a Byte from the sub-types of the internationally
recognized format. For example, different decimal separators (such as thousand separators)
are properly recognized depending on the locale settings.

If the Byte subtype expression in the acceptable range, the error occurs. The following
example uses the CByte function to convert expression byte:

Dim MyDouble, MyByte


MyDouble = 125.5678 'MyDouble is a double value.
MyByte = CByte (MyDouble) 'MyByte contains 126.
Requirements
Version 1
CCur (expression)
expression argument is any valid expression.

Explain
Typically, you can use the subtype conversion functions to write code to display the result of
some operation should be expressed as a particular data type rather than the default data
type. For example, in the case of integer arithmetic, use CCur to force currency arithmetic.

CCur function from any other data type to a Currency subtype of the internationally recognized
format. For example, different decimal separators and thousands separators are properly
recognized depending on the locale settings.

The following example uses the CCur function to convert an expression Currency type:

Dim MyDouble, MyCurr


MyDouble = 543.214588 'MyDouble is double precision.
MyCurr = CCur (MyDouble * 2) 'to MyDouble * 2 (1086.429176) the result is converted to
Currency (1086.4292).
Requirements
Version 1
Returns an expression that has been converted to a Date subtype Variant.

CDate (date)
date argument is any valid date expression.
Explain
IsDate function to determine if date can be converted to a date or time. CDate recognizes date
literals and time literals as well as some dates in the acceptable range of numbers. In the
digital conversion to date, the integer portion is converted to date, from the fractional part is
converted to the time since midnight.

Depending on the system locale CDate recognizes date formats. If the data set the date format
can not be identified, it can not determine the year, month, day of the correct order. In
addition, if the long date format string that contains the day of the week, it can not be
identified.

The following example uses the CDate function to convert strings into date type. Generally not
recommended to use hardware decode dates and times as strings (example below is
reflected). The use of time and date text (such as # 10/19/1962 #, # 4:45:23 PM #).

MyDate = "October 19, 1962" 'defined date.


MyShortDate = CDate (MyDate) 'into a date data type.
MyTime = "4:35:47 PM" 'definition of time.
MyShortTime = CDate (MyTime) 'into a date data type.
Requirements
Version 1
Returns an expression that has been converted to a Double subtype of Variant.

CDbl (expression)
expression argument is any valid expression.

Explain
Typically, you can use the subtype conversion functions to write code to display the result of
some operation should be expressed as a particular data type rather than the default data
type. For example, where currency or integer arithmetic in the case, use CDbl or CSng function
to force double-precision or single-precision arithmetic.

CDbl function is used to from other data type to Double subtype of internationally recognized
format. For example, decimal separators and thousands separators are properly recognized
depending on the locale settings.

The following example uses the CDbl function to convert expression to a Double.

Dim MyCurr, MyDouble


MyCurr = CCur (234.456784) 'MyCurr the Currency type (234.4567).
MyDouble = CDbl (MyCurr * 8.2 * 0.01) 'the result is converted to type Double (19.2254576).
Requirements
Version 1
Returns the specified ANSI character code corresponding to the characters.
Chr (charcode)
charcode parameter is the number of characters can be identified.

Explain
From 0 to 31 numerical standard is not printable ASCII code. For example, Chr (10) return line
feed.

The following example uses the Chr function returns the character code specified by the
corresponding characters:

Dim MyChar
MyChar = Chr (65) 'Return A.
MyChar = Chr (97) 'returns a.
MyChar = Chr (62) 'return>.
MyChar = Chr (37) 'return.
Note ChrB function and contained in a string of bytes of data together. ChrB not return one or
two-byte characters, but always returns a single byte characters. ChrW is to use Unicode
characters in the 32-bit platforms. Its argument is a Unicode (wide character) character code,
thereby avoiding the ANSI into Unicode characters.
Requirements
Version 1
Returns an expression that has been converted to an Integer subtype of Variant.

CInt (expression)
expression argument is any valid expression.

Explain
Typically, you can use to write code type conversion functions to show the result of some
operation should be expressed as a specific data type, instead of the default type. For
example, in the event of currency, single-precision or double precision arithmetic in the case,
use CInt or CLng to force integer arithmetic.

CInt function to provide from other data type to an Integer subtype of an internationally
recognized format. For example, different decimal separators (such as thousand separators)
are properly recognized depending on the locale settings.

If the Integer subtype expression outside the acceptable range, an error occurs.

The following example uses the CInt function to convert the value to Integer:

Dim MyDouble, MyInt


MyDouble = 2345.5678 'MyDouble is Double.
MyInt = CInt (MyDouble) 'MyInt contains 2346.
Note CInt differs from the Fix and Int functions remove the fractional part of value, instead of
using the rounding mode. When the fractional part is exactly equal to 0.5, CInt always be
rounded to the nearest even number. For example, 0.5 rounds to 0, and 1.5 rounds to 2.
Requirements
Version 1
Declare a class name, and the composition of the class variable, properties and methods
defined.

Class name
    statements
End Class
Parameter
name
Required. Class names; follow standard variable naming rules.
statements
Required. One or more statements, the definition of Class variables, properties and methods.
Explain
In the Class block, members through its corresponding opening statement is declared as
Private or Public. Is declared as Private will only be visible within the Class block. Be declared
as Public, not only in Class is visible within the block of code outside the Class block is visible.
Private or Public is not used by default explicitly declared as Public. Within the class block the
process of being declared as Public (Sub or Function) will become the class. Public variables will
be the class of property, with the use of Property Get, Property Let and Property Set explicit
statement of the same attributes. The default class properties and methods are part of their
statement specified with the Default keyword. On how to use the keyword, refer to a separate
declaration statement topics.

Requirements
Version 5
Returns an expression that has been converted to a Long subtype of Variant.

CLng (expression)
expression argument is any valid expression.

Explain
Typically, you can use the subtype conversion functions to write code to display the result of
some operation should be expressed as a particular data type rather than the default data
type. For example, in the event of currency operations, single-or double-precision arithmetic in
the case, use CInt or CLng to force integer arithmetic functions.

CLng function used for other data types from the Long subtype of the internationally
recognized format. For example, different decimal separators and thousands separators are
properly recognized depending on the locale settings.

If the value is not in Long subtype expression within the allowed range, an error occurs.

The following example uses the CLng function to convert the value of Long:
Dim MyVal1, MyVal2, MyLong1, MyLong2
MyVal1 = 25427.45: MyVal2 = 25427.55 'MyVal1, MyVal2 is double-precision values.
MyLong1 = CLng (MyVal1) 'MyLong1 25427.
MyLong2 = CLng (MyVal2) 'MyLong2 include 25428.
Note CLng differs from the Fix and Int functions remove the fractional part, but a rounded way.
When the fractional part is exactly equal to 0.5, CLng function always be the number rounded
to the nearest even number. For example, 0.5 rounds to 0, and 1.5 rounds to 2.
Requirements
Version 1
Declaration for a constant value instead of text.

 [Public | Private] Const constname = expression


Parameter
Public
Available options. This keyword is used to declare in the Script class can be used for all
procedures in all scripts constant. Not allowed to use in the process.
Private
Available options. This keyword is used in the script level to declare the statement can only be
used where the script constant. Not allowed to use in the process.
constname
Required. Constant name, according to the standard variable naming conventions.
expression
Required. Text or other constant, or include in addition to outside Is all arithmetic operators
and logical operators in any combination.
Explain
By default, constants are shared. The proprietary process is always constant, and its visibility
can not be changed. Script, the script can be used to change the Private keyword-class
constant visibility of the default values.

In the same line to declare several constants, can be a comma separate each constant
assignment. When declaring a constant in this way, if you use a Public or Private keyword, the
keyword of the line all the constants are valid.

Constant declaration can not use variables, user-defined function or VBScript internal
functions (such as Chr). By definition, they can not be constant. Also do not contain operators
from creating a constant expression, that is only allowed to use a simple constant. In the Sub
or Function statement during the process of constant local constant. Constant in the process is
declared outside the declaration where the script global constants. Can be used in any place
with a constant expression. The following code illustrates how to use the Const statement:

Const MyVar = 459 'constant default to the public.


Private Const MyString = "HELP" 'definition of private constant.
Const MyStr = "Hello", MyNumber = 3.4567 'define multiple constants on a single line.
Note his constant support and easy to make script changes. Unlike variables, the script is
running, a constant can not be accidentally modified.
Requirements
Version 5
Transfer function
Asc function

CBool function

CByte function

CCur to

CDate function

CDbl function

Chr function

CInt function

CLng function

CSng function

CStr function

Hex function

Oct function
The Cos function
Returns the cosine of an angle.

Cos (number)
The number argument can be any angle in radians to a valid numeric expression.

Explain
The Cos function to take an angle and returns the ratio of both sides of a right triangle. This
ratio is a right triangle in the corner of the adjacent side length ratio of the length of the
hypotenuse. The results range from -1 to 1.

Angle into radians method is to use the angle multiplied by pi/180. On the contrary, the angle
into radians is radians multiplied by 180/pi.

The following example uses the Cos function returns the cosine of an angle:
Dim MyAngle, MySecant
MyAngle = 1.3 'definition of an angle in radians.
MySecant = 1 / Cos (MyAngle) 'calculated secant.
Creates and returns a reference to the Automation object.

CreateObject (servername.typename [, location])


Parameter
servername
Required. Application providing the object name.
typename
Required. To create an object type or class.
location
Available options. Network server where the object will be created.
Explain
Automation servers provide at least one type of object. For example, word processing
applications can provide an application object, document object and tool bar object.

To create an Automation object, use the CreateObject function returns the object is assigned
to an object variable:

Dim ExcelSheet
Set ExcelSheet = CreateObject ("Excel.Sheet")
The code starts to create the object (in this instance, is a Microsoft Excel spreadsheet)
application. Object is created, you can use the code defined in the object variable referencing
this object. In the following example, you can use the object variable, ExcelSheet and other
Excel objects, including the Application object and the Cells collection to access the new
object's properties and methods. For example:

'Throughout the Excel Application object are visible.


ExcelSheet.Application.Visible = True
'Some text into the first worksheet cell.
ExcelSheet.ActiveSheet.Cells (1,1). Value = "This is column A, row 1"
'Save the worksheet.
ExcelSheet.SaveAs "C: \ DOCS \ TEST.XLS"
'Close Excel, the Quit method in the Application object.
ExcelSheet.Application.Quit
'Release the object variable.
Set ExcelSheet = Nothing
On the remote server to create an object, when only complete Internet security is turned off.
By passing the computer name to CreateObject server name parameter, can create objects on
the remote network. The name of the share as part of the machine name. For example, name
the network share: "\ \ myserver \ public", servername is "myserver". In addition, only specify
servername using DNS format or an IP address.

The following code returns a run-in named "myserver" on the remote network computer
version of an instance of Excel:

Function GetVersion
   Dim XLApp
   Set XLApp = CreateObject ("Excel.Application", "MyServer")
   GetVersion = XLApp.Version
End Function
Error occurred on the specified remote server does not exist or can not be found.

Requirements
Version 2
Returns an expression that has been converted to a Single subtype of Variant.

CSng (expression)
expression argument is any valid expression.

Explain
Typically, you can use to write code type conversion functions to show the result of some
operation should be expressed as a specific data type, instead of the default type. For
example, in the event of currency or integer arithmetic in the case, use CDbl or CSng to force
double-precision or single precision arithmetic.

CSng function used for the data type to a Single from the other sub-types of the internationally
recognized format. For example, the decimal separator (such as thousand separators)
identification depending on the locale settings.

If the expression in the Single subtype of range, the error occurs.

The following example uses the CSng function to convert the value Single:

Dim MyDouble1, MyDouble2, MySingle1, MySingle2 'MyDouble1, MyDouble2 is double-


precision values.
MyDouble1 = 75.3421115: MyDouble2 = 75.3421555
MySingle1 = CSng (MyDouble1) 'MySingle1 contains 75.34211.
MySingle2 = CSng (MyDouble2) 'MySingle2 contains 75.34216.
Requirements
Version 1
Returns the current system date.

Date
Explain
The following example uses the Date function returns the current system date:

Dim MyDate
MyDate = Date 'MyDate contains the current system date.
Requirements
Version 1
Returns the specified time interval has been added the date.

DateAdd (interval, number, date)


Parameter
interval
Required. A string expression that you want to add time interval. For values, see "Settings"
section.
number
Required. Numeric expression that you want to add the number of time intervals. Numeric
expression can be positive (to get dates in the future) or negative (to get dates in the past).
date
Required. Variant or interval of that date to add text.
Set up
The interval argument can have the following values:

Setting Description
yyyy Year
q quarter
m Month
y number of days a year
d day
w the number of days a week
ww Week
h hours
n minutes
s seconds

Explain
DateAdd function can be used to add or subtract from the date specified time interval. For
example, you can use the DateAdd date 30 days from the day after the date or the date from
now after a 45 minute time. Adding to the date of "day" as the unit time interval, use the
"number of days a year" ("y"), "Day" ("d") or "week days" ("w").

The DateAdd function will not return an invalid date. In the following example will be 95
January 31 plus one month:

NewDate = DateAdd ("m", 1, "31-Jan-95")


In this case, DateAdd returns 28 February 1995, not 95 February 31, 2007. If the date is
January 31, 1996, returned February 29, 1996, because 1996 is a leap year.

If the calculation date is before the year AD 100, an error occurs.

If the number is not a Long value, then the calculation before rounding to the nearest integer.
Requirements
Version 2
Returns the time interval between two dates.

DateDiff (interval, date1, date2 [, firstdayofweek [, firstweekofyear]])


DateDiff function syntax has the following parameters:

Parameter
interval
Required. A string expression that is used to calculate the time between date1 and date2
interval. For values, see "Settings" section.
date1, date2
Required. Date expression. Used to calculate the two dates.
Firstdayofweek
Available options. The first day of the week specified constant. If not specified, the default is
Sunday. For values, see "Settings" section.
Firstweekofyear
Available options. The first week of the year specified constant. If not specified, the default is
January 1, where the week. For values, see "Settings" section.
Set up
The interval argument can have the following values:

Setting Description
yyyy Year
q quarter
n months
y number of days a year
d day
w the number of days a week
ww Week
h hours
m minutes
s seconds

firstdayofweek argument can have the following values:

Constant Value Description


vbUseSystemDayOfWeek 0 Use National Language Support (NLS) API setting.
vbSunday 1 Sunday (default)
vbMonday 2 Monday
vbTuesday 3 Tuesday
vbWednesday 4 Wednesday
vbThursday 5 Thursday
vbFriday 6 Friday
vbSaturday 7 Saturday

firstweekofyear parameter can have the following values:

Constant Value Description


vbUseSystem 0 Use National Language Support (NLS) API setting.
vbFirstJan1 1 by the January 1 the week of the beginning (the default).
vbFirstFourDays 2 by the New Year in at least four days in the first week.
vbFirstFullWeek 3 in the new year by the first full week.

Explain
DateDiff function is used to determine between the two dates specified number of time
intervals. For example, you can use the DateDiff calculate the number of days difference
between two dates, or the day of the year the number of weeks between the last day.

To calculate the difference between date1 and date2 number of days, you can use the
"number of days a year" ("y") or "day" ("d"). When the interval is "week days" ("w") when,
DateDiff returns the number of weeks between two dates. If date1 is Monday, DateDiff to
calculate the number of Mondays until date2. This result contains date2 not contain date1. If
the interval is the "week" ("ww"), the DateDiff function returns the calendar the number of
weeks between two dates. Function calculated on Sundays between date1 and date2 number.
If date2 is Sunday, DateDiff to calculate date2, but even if date1 is a Sunday, it will not count
date1.

If date1 is later than date2, the DateDiff function returns a negative number.

firstdayofweek argument will use the "w" and "ww" interval symbols impact.

If date1 or date2 is a date literal, the specified date of the year will become a fixed part.
However, if date1 or date2 is enclosed in quotation marks ("") and is omitted in the year,
calculated in the code each time date1 or date2 expression, it will insert the current year. This
can apply to different years of writing code.

In the interval for the "year" ("yyyy"), the more the coming year, December 31 and January 1,
although in practice only a difference of one day, DateDiff returns 1 for almost a year.

The following example uses the DateDiff function to display today with a given number of days
between the date:

Function DiffADate (theDate)


   DiffADate = "number of days from the day:" & DateDiff ("d", Now, theDate)
End Function
Returns the specified part of the given date.

DatePart (interval, date [, firstdayofweek [, firstweekofyear]])


Arguments
interval
Required. String expression that you want to return time interval. For values, see "Settings"
section.
Date
Required. To calculate the date expression.
firstdayof week
Available options. The first day of the week specified constant. If not specified, the default is
Sunday. For values, see "Settings" section.
Firstweekofyear
Available options. The first week of the year specified constant. If not specified, the default is
January 1, where the week. For values, see "Settings" section.
Set up
The interval argument can have the following values:

Setting Description
yyyy Year
q quarter
m Month
y number of days a year
d day
w the number of days a week
ww Week
h hours
n minutes
s seconds

firstdayofweek argument can have the following values:

Constant Value Description


vbUseSystemDayOfWeek 0 Use National Language Support (NLS) API setting.
vbSunday 1 Sunday (default)
vbMonday 2 Monday
vbTuesday 3 Tuesday
vbWednesday 4 Wednesday
vbThursday 5 Thursday
vbFriday 6 Friday
vbSaturday 7 Saturday

firstweekofyear parameter can have the following values:

Constant Value Description


vbUseSystem 0 Use National Language Support (NLS) API setting.
vbFirstJan1 1 by the January 1 the week of the beginning (the default).
vbFirstFourDays 2 by the New Year in at least four days in the first week.
vbFirstFullWeek 3 in the new year by the first full week (not multi-year) started.

Explain
DatePart function is used to calculate dates and return the specified time interval. For
example, use DatePart to calculate the day of the week or the current time.

firstdayofweek argument affects use "w" and "ww" interval symbols.

If the date is a date literal, the specified date of the year will become a fixed part. However, if
date is enclosed in quotation marks (""), and the year is omitted, then the code each time the
date expression, it will insert the current year. This can apply to different years of writing code.
.

The following example uses the DatePart function to get the date and displays the date where
the season.

Function GetQuarter (TheDate)


   GetQuarter = DatePart ("q", TheDate)
End Function
For the specified year, month, day, returns a Date subtype Variant.

DateSerial (year, month, day)


Arguments
Year
From 100 to 9999 numeric or numeric expression.
Month
Any numeric expression.
Day
Any numeric expression.
Explain
To specify a date, such as the December 31, 1991, DateSerial function in the range of each
parameter should be acceptable; today's value should be between 1 and 31, the value should
be 1 month and 12 between. However, you can use that one day before or after the year,
month, day number of the numeric expression specified for each parameter relative to the
date.

The following example uses numeric expressions instead of absolute date. Here, DateSerial
function returns the August 1, 1990 before the decade (1990 - 10) and two months (8 - 2) day
(1 - 1) the date: the May 31, 1980.

Dim MyDate1, MyDate2


MyDate1 = DateSerial (1970, 1, 1) 'returns January 1, 1970.
MyDate2 = DateSerial (1990 - 10, 8 - 2, 1 - 1) 'returns May 31, 1980.
For the year argument, if the range is from 0 to 99, is interpreted as 1900 to 1999. For this year
outside the parameters, use four-digit year (eg 1800).
When any parameter value outside the acceptable range will be appropriate to carry to the
next larger unit of time. For example, if you specify 35 days, then this is interpreted as the
number of days a month plus the extra days, extra days depending on the year and month.
However, if the argument is outside the range -32,768 to 32,767, or specified by the three
parameters (either directly or through an expression specified) the date falls outside the
acceptable range of dates, an error occurs.

Requirements
Version 1
Return Date subtype Variant.

DateValue (date)
The date argument is a string expression, that 100 years from January 1 to December 31, 9999,
a Japan-date. However, date can also be said that within the scope of the above date, time,
date and time, or any expression.

Explain
If the date argument includes time information, DateValue does not return time information.
However, if date includes invalid time information (such as "89:98"), an error occurs.

If the date is a string that includes only the valid date separator separated, DateValue will be
based on the system short date format specified identification month, day and year order.
DateValue also recognizes that contain month names (either full name or initials) of the
specific date. For example, in addition to recognizing 12/30/1991 and 12/30/91, DateValue
also recognizes December 30, 1991 and Dec 30, 1991.

If the year part of date is omitted, DateValue uses the computer system date in the current
year.

The following example uses the DateValue function to convert a string into a date. You can also
use date literals to directly assign a date Variant variables, such as, MyDate = # 9/11/63 #.

Dim MyDate
MyDate = DateValue ("September 11, 1963") 'return date.
Requirements
Version 1
Return 1 to 31 of an integer (including 1 and 31), on behalf of a mid-day.

Day (date)
Is any expression that can represent a date. If date contains Null, returns Null.

The following example uses the Day function to get a date on a given number of days:

Dim MyDay
MyDay = Day ("October 19, 1962") 'MyDay contains 19.
Requirements
Version 1
The following is a mathematical function derived from the inherent non-intrinsic math
functions:

Function derived from the equivalent formula


Secant (secant) Sec (X) = 1 / Cos (X)
Cosecant (cosecant) Cosec (X) = 1 / Sin (X)
Cotangent (cotangent) Cotan (X) = 1 / Tan (X)
Inverse Sine (Arcsine) Arcsin (X) = Atn (X / Sqr (-X * X + 1))
Inverse Cosine (inverse cosine) Arccos (X) = Atn (-X / Sqr (-X * X + 1)) + 2 * Atn (1)
Inverse Secant (cut anyway) Arcsec (X) = Atn (X / Sqr (X * X - 1)) + Sgn ((X) -1) * (2 * Atn (1))
Inverse Cosecant (anti-cosecant) Arccosec (X) = Atn (X / Sqr (X * X - 1)) + (Sgn (X) - 1) * (2 * Atn
(1))
Inverse Cotangent (anti-cotangent) Arccotan (X) = Atn (X) + 2 * Atn (1)
Hyperbolic Sine (hyperbolic sine) HSin (X) = (Exp (X) - Exp (-X)) / 2
Hyperbolic Cosine (hyperbolic cosine) HCos (X) = (Exp (X) + Exp (-X)) / 2
Hyperbolic Tangent (hyperbolic tangent) HTan (X) = (Exp (X) - Exp (-X)) / (Exp (X) + Exp (-X))
Hyperbolic Secant (hyperbolic secant) HSec (X) = 2 / (Exp (X) + Exp (-X))
Hyperbolic Cosecant (hyperbolic cosecant) HCosec (X) = 2 / (Exp (X) - Exp (-X))
Hyperbolic Cotangent (hyperbolic cotangent) HCotan (X) = (Exp (X) + Exp (-X)) / (Exp (X) - Exp (-
X))
Inverse Hyperbolic Sine (inverse hyperbolic sine) HArcsin (X) = Log (X + Sqr (X * X + 1))
Inverse Hyperbolic Cosine (inverse hyperbolic cosine) HArccos (X) = Log (X + Sqr (X * X - 1))
Inverse Hyperbolic Tangent (inverse hyperbolic tangent) HArctan (X) = Log ((1 + X) / (1 - X)) / 2
Inverse Hyperbolic Secant (inverse hyperbolic secant) HArcsec (X) = Log ((Sqr (-X * X + 1) + 1) /
X)
Inverse Hyperbolic Cosecant (inverse hyperbolic cosecant) HArccosec (X) = Log ((Sgn (X) * Sqr
(X * X + 1) +1) / X)
Inverse Hyperbolic Cotangent (inverse hyperbolic cotangent) HArccotan (X) = Log ((X + 1) / (X -
1)) / 2
To N is the logarithm
Declare variables and allocate storage space.

Dim varname [([subscripts ])][, varname [([subscripts])]]...


Parameter
varname
Name of the variable standard variable naming rules.
subscripts
The dimension of an array variable, you can declare up to 60-dimensional arrays. The
subscripts argument uses the following syntax:
upperbound [, upperbound]...

Lower bound of the array is always 0.


Explain
Dim statement with the Script-level variables can be used to script all of the process,
procedure-level variable can only be used for the process.

Also used the Dim statement with empty parentheses to declare a dynamic array. After
declaring a dynamic array, you can use the ReDim statement within a procedure to define the
dimension of the array and the elements. If you try to redefine in a Dim statement has been
explicitly specified dimension of the array, an error occurs.

Note that in the process, use the Dim statement, usually on the Dim statement at the
beginning of the process.
The following example illustrates how to use the Dim statement:

Dim Names (9) 'Declare an array with 10 elements.


Dim Names () 'declare a dynamic array.
Dim MyVar, MyNum 'declare two variables.
Requirements
Version 1
When the condition is True or until a condition becomes True repeat a statement block.

Do [{While | Until} condition]


[Statements]
[Exit Do]
[Statements]
Loop
You can also use the following syntax:

Do
[Statements]
[Exit Do]
[Statements]
Loop [{While | Until} condition]
Parameter
condition
Numeric or string expression that evaluates to True or False. If condition is Null, condition is
treated as False.
statements
When the condition is True is repeated one or more commands.
Explain
Exit Do can only be used in the Do ... Loop control statements, provide another way to exit the
Do ... Loop. Do ... Loop statement can be in any place to put any number of Exit Do. Exit Do is
usually conditional statement (such as If ... Then) together, followed by passing control to the
statement following the Loop statement.
When used in nested Do ... Loop when, Exit Do transfers control to the loop on the floor in
their nesting cycle.

The following example illustrates how to use the Do ... Loop statement:

Do Until DefResp = vbNo


   MyNum = Int (6 * Rnd + 1) 'between 1 and 6 generated random number.
   DefResp = MsgBox (MyNum & "the number you want another?", VbYesNo)
Loop

Dim Check, Counter


Check = True: Counter = 0 'initialize the variable.
Do 'outer loop.
  Do While Counter <20 'inner circle.
    Counter = Counter + 1 'increment the counter.
    If Counter = 10 Then 'If condition is True ...
      Check = False 'set flag value is set to False.
      Exit Do 'to terminate the inner loop.
    End If
  Loop
Loop Until Check = False 'immediate termination of the outer loop.
Requirements
Version 1
Re-initialize the fixed-size array of elements, and release dynamic array of storage space.

Erase array
The array parameter is an array variable to clear the name.

Explain
Determine the array is an array of fixed length (conventional) or dynamic array is very
important, because according to Erase an array of different types of operations. Erase without
the need for fixed-size array to restore the memory. Erase the following table to set a fixed
array of elements:

Type of the array Erase array elements on the fixed effects


Fixed value to each element array is set to 0.
Fixed array of strings each element is set to zero-length string ("").
Each element of the array object to the special value Nothing.

Erase releases the memory used by dynamic arrays. In the program refer to the dynamic array
again, you must use the ReDim statement to redefine the dimensions of the array variable.

The following example illustrates how to use the Erase statement.

Dim NumArray (9)


Dim DynamicArray ()
ReDim DynamicArray (9) 'allocate storage space.
Erase NumArray 'Each element is reinitialized.
Erase DynamicArray 'release the memory array.
Requirements
Version 1
Eval Function
Calculate the value of an expression and returns the result.

[Result =] Eval (expression)


Parameter
result
Available options. Is a variable, for receiving the returned results. If not specified, the results
should be considered instead of using the Execute statement.
expression
Required. VBScript can contain any valid string expression.
Explain
In VBScript, x = y can be interpreted two ways. The first is an assignment statement, the value
of y given x. The second explanation is that x and y is equal to the test. If equal, result is True;
otherwise result to False. Eval method always uses the second interpretation, the Execute
statement always uses the first.

Note that in Microsoft? JScript? Does not exist in comparison with the assignment of this
confusion, because the assignment operator (=) with a comparison operator (==) is different.
The following example illustrates the usage of the Eval function:

Sub GuessANumber
   Dim Guess, RndNum
   RndNum = Int ((100) * Rnd (1) + 1)
   Guess = CInt (InputBox ("Enter your guess:",, 0))
   Do
      If Eval ("Guess = RndNum") Then
         MsgBox "Congratulations! Guessed it!"
         Exit Sub
      Else
         Guess = CInt (InputBox ("I'm sorry, please try again", 0))
      End If
   Loop Until Guess = 0
End Sub
Perform one or more specified statements.

Execute statements
The required statements parameter is a string expression that contains one or more
statements to execute. If you want the statements parameter contains multiple statements,
you should use a semicolon or embedded in its separate branches.
Explain
In VBScript, x = y can be interpreted two ways. First, as an assignment statement, the value of
y given x. Second, as an expression to test whether the value of x and y are equal. If equal, the
result is True; otherwise, result is False. Execute statement always uses the first interpretation,
whereas the Eval method always uses the second.

Note that in Microsoft? JScript? Does not exist confusion between assignment and
comparison, because the assignment operator (=) with a comparison operator (==) is different.

Call the Execute statement identifies the context can be used to run the object code and
variables. Scope of the objects and variables is the Execute statement can be used to run the
code. However, we must understand is that if the code is executed to create a process, then
the process will not inherit it in the process scope.

And other similar process, new process scope is global, it inherits the global scope of all things.
Different from other processes, it is not the context of global scope, so it can only occur within
the course of the Execute statement executes in the context. However, if the same Execute
statement is outside the process (for example in the global scope) the scope is called, it will
not only inherit everything in global scope, and it can be called anywhere, because its context
is global. The following example illustrates this feature:

Dim X 'in the global scope statement X.


X = "Global" 'to the global X assignment.
Sub Proc1 'declaration process.
   Dim X 'in the local scope statement X.
   X = "Local" 'on the local X-assignment.
            'Execute statement here established a process,
            'In the procedure is called it will print X.
            'It will be a global print X, because Proc2
            'Inherits everything in global scope.
   Execute "Sub Proc2: Print X: End Sub"
   Print Eval ("X") 'Print the local X.
   Proc2 'Proc1 the scope of a call in Proc2.
End Sub
Proc2 'Bank will result in an error because
        'Proc2 outside Proc1 is not in use.
Proc1 'call Proc1.
   Execute "Sub Proc2: Print X: End Sub"
Proc2 'This sentence can be successful, because Proc2
        'It is globally available.
The following example shows how to rewrite the Execute statement, from the whole process
in quotes:

S = "Sub Proc2" & vbCrLf


S = S & "Print X" & vbCrLf
S = S & "End Sub"
Execute S
Requirements
Version 1
Successful implementation of a more global namespace in the script specified in the
statement.

ExecuteGlobal statement
argument is a statement of one or more executable statements containing the string
expression. In the statement parameter can contain multiple statements, use a colon to
separate.

Explain
In VBScript, x = y, there are two interpretation. The first is as an assignment statement assigns
the value of y x. The second method is as an expression to test whether x and y have the same
value. If they are equal, then the result is True; if they are not equal, the result of
False.ExecuteGlobal statement always uses the first method, whereas the Eval method always
uses the second method.

Note that in Microsoft? JScript?, The assignment and comparison, there is no mixing between
the consumer, because the assignment operator (=) is different from the comparison.
In the script's global namespace, ExecuteGlobal all the statements are executable. Therefore,
allow you to add code to the program, so that any process can access it. For example, a
VBScript Class statement at run-time execution. Subsequently function to create a new
instance of this class.

Add in the run-time process and the class is very useful, but may also lead to run-time
coverage in the existing global variables and functions. Because this procedure may lead to
very serious problems, so when using ExecuteGlobal statement must be very cautious. If you
do not have access outside of the process variable or function, it is best to use the Execute
statement, because it only affects the calling function's name space.

The following example illustrates the use of ExecuteGlobal statement.

Dim X 'X is a global variable declaration.


X = "Global" 'to the global variable X assignment.
Sub Proc1 'declaration process.
  Dim X 'in the local variable declaration X.
  X = "Local" 'to the local variable X is assigned.
         'Here's an executable statement
         'Create a process, when called, print X.
         'Here to print a global value of variable X, because Proc2
         'Inherits all the global variables.
  ExecuteGlobal "Sub Proc2: Print X: End Sub"
  Print Eval ("X") 'Print the local X.
  Proc2 'role in the global zone called Proc2
             'Will print "Global".
End Sub
Proc2 'This line causes an error
             'Because Proc2 outside Proc1 is not available.
Proc1 'call Proc1.
  Execute "Sub Proc2: Print X: End Sub"
Proc2 'This line is called success, because Proc2
         'Role in the global zone is available.
The following example demonstrates ExecuteGlobal statement can be rewritten, so you do not
need the whole process of the following are included in the reference tags.

S = "Sub Proc2" & vbCrLf


S = S & "Print X" & vbCrLf
S = S & "End Sub"
ExecuteGlobal S
Requirements
Version 1
Exit Do ... Loop, For ... Next, Function, or Sub code block.

Exit Do
Exit For
Exit Function
Exit Property
Exit Sub
Exit statement syntax has the following form:

Statement describes the


Exit Do Exit Do ... Loop provides a statement of the method. Only in the Do ... Loop statements.
Exit Do transfers control to the statement following the Loop statement. In the nested Do ...
Loop statement, when used, Exit Do transfers control to the loop on the location of a layer of
nested loops.
Exit For providing a way to exit a For loop. Only in the For ... Next or For Each ... Next loop. Exit
For transfers control to the statement following Next. For the nested loop used, Exit For
transfers control to the loop on the location of a layer of nested loops.
Exit Function immediately withdraw from the occurrence of the Function procedure. Continue
to call the Function of the statement following the statement.
Exit Property where the Property immediately from the process to exit. Continue with the
following statement that called the Property procedure.
Exit Sub immediately withdraw from the occurrence of the Sub procedure, continue to call the
Sub statement following the statement.

The following example illustrates how to use the Exit statement:


Sub RandomLoop
   Dim I, MyNum
   Do 'to set loop.
      For I = 1 To 1000 '1000 cycles.
         MyNum = Int (Rnd * 100) 'generate random numbers.
         Select Case MyNum 'find the value of random numbers.
            Case 17: MsgBox "Case 17"
              Exit For 'If it is 17, out of For ... Next.
            Case 29: MsgBox "Case 29"
              Exit Do 'If it is 29, out of Do ... Loop.
            Case 54: MsgBox "Case 54"
              Exit Sub 'If it is 54, out of a Sub procedure.
         End Select
      Next
   Loop
End Sub
Requirements
Version 1
Exp function
Returns e (natural logarithms) powers of two.

Exp (number)
The number argument can be any valid numeric expression.

Explain
If number is more than 709.782712893, an error occurs. The constant e is approximately
2.718282.

Note The Exp function to complete the anti-Log function operation, and sometimes referred to
as opposed to the number of forms.
The following example uses the Exp function returns e to a power:

Dim MyAngle, MyHSin 'definition of angle in radians.


MyAngle = 1.3 'calculation of hyperbolic sine.
MyHSin = (Exp (MyAngle) - Exp (-1 * MyAngle)) / 2
Return subscript zero-based array, which contains a specific filter string based on a subset of
the array.

Filter (InputStrings, Value [, Include [, Compare]])


Parameter
InputStrings
Required. One-dimensional array, in which the search string.
Value
Required. String to search.
Include
Available options. Boolean value that specifies whether to return substrings that include Value.
If Include is True, Filter returns an array containing substrings Value subset. If Include is False,
Filter returns the substring Value does not contain a subset of the array.
Compare
Available options. Numeric value that type of string comparison to use. Please refer to the
value part.
Set up
Compare argument can have the following values:

Constant Value Description


vbBinaryCompare 0 Perform a binary comparison.
vbTextCompare 1 Performs a textual comparison.

Explain
If not found within InputStrings match with the value of Value, Filter returns an empty array. If
InputStrings is Null or is not a one-dimensional array, an error occurs.

The array returned by the Filter function contains only enough to match the number of
elements included.

The following example uses the Filter function returns containing the search terms "Mon"
array:

Dim MyIndex
Dim MyArray (3)
MyArray (0) = "Sunday"
MyArray (1) = "Monday"
MyArray (2) = "Tuesday"
MyIndex = Filter (MyArray, "Mon") 'MyIndex (0) contains "Monday".
Requirements
Version 2
Returns the integer part.

Int (number)
Fix (number)
The number argument can be any valid numeric expression. If number contains Null, returns
Null.

Explain
Int and Fix remove the fractional part of the number argument and returns an integer result.

The difference between Int and Fix is that if the number parameter is negative, Int returns the
first number is less than or equal to a negative integer, and Fix function returns the number is
greater than or equal to the first negative integer parameters. For example, Int converts -8.4 to
-9, and Fix converts -8.4 to -8 function.
Fix (number) is equivalent to:

Sgn (number) * Int (Abs (number))


The following example illustrates how the Int and Fix functions return integer portions of
numbers:

MyNumber = Int (99.8) 'Return 99.


MyNumber = Fix (99.2) 'Return 99.
MyNumber = Int (-99.8) 'returns -100.
MyNumber = Fix (-99.8) 'return -99.
MyNumber = Int (-99.2) 'returns -100.
MyNumber = Fix (-99.2) 'return -99.
Requirements
Version 1
The array or collection each element a group of statements repeatedly.

For Each element In group


[Statements]
[Exit For]
[Statements]
Next [element]
Parameter
element
Used to enumerate all the elements of the collection or array variables. For the collection,
element may be a Variant variable, a generic Object variable or any of the specified
Automation object variable. For arrays, element can only be a Variant variable.
group
Object collection or array name.
statements
For each group in an implementation of one or more statements.
Explain
If the group has at least one element, it will enter the For Each block is executed. Once in
circulation, will be the first element of the first group all the statements in the loop. As long as
there are other elements in the group, will perform on each element of statements in the loop.
When the group is no other element in the loop is exited, then the statement following the
Next statement continues.

Exit For can only be used For Each ... Next or For ... Next control structure to provide an
alternate way to exit the method. Can be placed anywhere in the loop any number of Exit For
statement. Exit For is often used with conditional statements (such as If ... Then), and
immediately transfers control to the statement following Next.

Can be a For Each ... Next loop placed within another form nested For Each ... Next loop.
However, each loop element must be unique.
Note If you omit the Next statement element, the program will still be the same as it has been
included to continue. If the Next statement before its corresponding For statement appears,
an error occurs.
The following example illustrates how to use the For Each ... Next statement:

Function ShowFolderList (folderspec)


   Dim fso, f, f1, fc, s
   Set fso = CreateObject ("Scripting.FileSystemObject")
   Set f = fso.GetFolder (folderspec)
   Set fc = f.Files
   For Each f1 in fc
      s = s & f1.name
      s = s & "<BR>"
   Next
  ShowFolderList = s
End Function
Requirements
Version 2
To specify the number of times a group of statements repeatedly.

For counter = start To end [Step step]


[Statements]
[Exit For]
[Statements]
Next
Parameter
counter
Used as the value of loop counter variable. This variable can not be array elements or user-
defined types of elements.
start
counter initial value.
end
The final counter value.
step
the step counter. If not specified, step defaults to 1.
statements
Between For and Next that one or more statements are executed the specified number of
times.
Explain
step argument can be positive or negative. the value of the step argument determines loop
implementation, as follows:

Value of the loop if ...


Positive number or 0 counter <= end
Negative counter> = end

When the loop starts and all statements in the loop are executed, step value is added to the
counter in. At this time, or statements in the loop execute again (based on the loop starts
executing the same test), or exit the loop and the statement following the statement from
Next to continue.

Note that changes in the body of the loop counter value, the program code will make it more
difficult to read and debug.
Exit For can only be used For Each ... Next or For ... Next structure to provide an alternate way
to exit the method. In the statement can be placed anywhere in any number of Exit For
statement. Exit For is often used with conditional statements (such as If ... Then), and
immediately transfers control to the statement following Next.

You can put a For ... Next loop within another For ... Next loop, composed of nested loops.
Each cycle counter to use a different variable name. The following construction is correct:

For I = 1 To 10
      For J = 1 To 10
            For K = 1 To 10
            ...
            Next
      Next
Next
Requirements
Version 1
Returns an expression formatted as a currency value (defined using the system control panel
currency symbol).

FormatCurrency (
   expression [, NumDigitsAfterDecimal [, IncludeLeadingDigit [, UseParensForNegativeNumbers
[, GroupDigits]]]]
)
Parameter
Expression
Required. Expression to be formatted.
NumDigitsAfterDecimal
Available options. Instructions displayed right of the decimal digit value. The default value is -1,
which indicates that the computer's regional settings.
IncludeLeadingDigit
Available options. Tristate constant that indicates whether to display fractional values of zero.
For values, see "Settings" section.
UseParensForNegativeNumbers
Available options. Tristate constant that indicates whether the negative values within
parentheses. For values, see "Settings" section.
GroupDigits
Available options. Tristate constant that indicates whether to use the computer's regional
settings digit grouping symbol specified in the digital group. For values, see "Settings" section.
Set up
IncludeLeadingDigit, UseParensForNegativeNumbers and GroupDigits parameter can have the
following values:

Constant Value Description


TristateTrue -1 True
TristateFalse 0 False
TristateUseDefault -2 using the computer's regional settings in the settings.

Explain
When you omit one or more optional parameters, provided by the computer's regional
settings are omitted parameter. Monetary value associated with the currency symbol position
by the system's regional settings.

Note that in addition to "Display the start of the zero" to set the locale from the "number" tab,
all other settings information comes from the locale of the "currency" tab.
The following example uses FormatCurrency function to expression formatted as a currency
and assigned to MyCurrency:

Dim MyCurrency
MyCurrency = FormatCurrency (1000) 'MyCurrency contains $ 1000.00.
Requirements
Version 2

Returns an expression formatted as a date or time.

FormatDateTime (Date [, NamedFormat])


Parameter
Date
Required. Date expression to be formatted.
NamedFormat
Available options. That indicates the date / time format value, if omitted, the vbGeneralDate.
Set up
NamedFormat parameter can have the following values:

Constant Value Description


vbGeneralDate 0 shows the date and / or time. If there is a date part, the part is shown as the
short date format. If you have time part, the part is shown as a long format. If there is, it shows
all the parts.
vbLongDate 1 computer regional settings in the long date format specified date.
vbShortDate 2 using the computer's regional settings in the short date format specified date.
vbLongTime 3 using the computer's regional settings time format specified time.
vbShortTime 4 24-hour format (hh: mm) display the time.

Explain
The following example uses the FormatDateTime function to an expression formatted as long
date and assign it to type MyDateTime:

Function GetCurrentDate
   'FormatDateTime the date type format for long dates.
   GetCurrentDate = FormatDateTime (Date, 1)
End Function
Requirements
Version 2
Returns an expression formatted as a value.

FormatNumber (
   expression [, NumDigitsAfterDecimal [, IncludeLeadingDigit [, UseParensForNegativeNumbers
[, GroupDigits]]]]
)
Arguments
Expression
Required. Expression to be formatted.
NumDigitsAfterDecimal
Available options. Instructions displayed right of the decimal digit value. The default value is -1,
which indicates that the computer's regional settings.
IncludeLeadingDigit
Available options. Tristate constant that indicates whether to display fractional values of zero.
For values, see "Settings" section.
UseParensForNegativeNumbers
Available options. Tristate constant that indicates whether the negative values within
parentheses. For values, see "Settings" section.
GroupDigits
Available options. Tristate constant that indicates whether to use the computer's regional
settings digit grouping symbol specified in the digital group. For values, see "Settings" section.
Set up
IncludeLeadingDigit, UseParensForNegativeNumbers and GroupDigits parameter can have the
following values:

Constant Value Description


TristateTrue -1 True
TristateFalse 0 False
TristateUseDefault -2 using the computer's regional settings in the settings.

Explain
When you omit one or more optional parameters, provided by the computer's regional
settings are omitted parameter.
Note All settings information comes from the locale of the "digital" tab.
The following example uses the FormatNumber function to format the value with four decimal
point:

Function FormatNumberDemo
   Dim MyAngle, MySecant, MyNumber
   MyAngle = 1.3 'definition of angle in radians.
   MySecant = 1 / Cos (MyAngle) 'calculate the secant value.
   FormatNumberDemo = FormatNumber (MySecant, 4) 'to MySecant formatted with four
decimal point.
End Function
Requirements
Version 2
Returns an expression formatted as a% symbol is followed by a percentage (multiplied by 100).

FormatPercent (expression [, NumDigitsAfterDecimal [, IncludeLeadingDigit [,


UseParensForNegativeNumbers [, GroupDigits ]]]])
FormatPercent function syntax has the following parameters:

Parameter
Expression
Required. Expression to be formatted.
NumDigitsAfterDecimal
Available options. Instructions displayed right of the decimal digit value. The default value is -1,
which indicates that the computer's regional settings.
IncludeLeadingDigit
Available options. Tristate constant that indicates whether to display fractional values of zero.
For values, see "Settings" section.
UseParensForNegativeNumbers
Available options. Tristate constant that indicates whether the negative values within
parentheses. For values, see "Settings" section.
GroupDigits
Available options. Tristate constant that indicates whether to use the computer's regional
settings digit grouping symbol specified in the digital group. For values, see "Settings" section.
Set up
IncludeLeadingDigit, UseParensForNegativeNumbers and GroupDigits parameter can have the
following values:

Constant Value Description


TristateTrue -1 True
TristateFalse 0 False
TristateUseDefault -2 using the computer's regional settings in the settings.
Explain
When you omit one or more optional parameters, provided by the computer's regional
settings are omitted parameter.

Note All settings information comes from the locale of the "digital" tab.
The following example uses FormatPercent function to format the expression as a percentage:

Dim MyPercent
MyPercent = FormatPercent (2 / 32) 'MyPercent contains 6.25%.
Requirements
Version 2

Statement Function procedure name, parameters, and form the body of the code.

 [Public [Default] | Private] Function name [(


   arglist
)]
[Statements]
[Name = expression]
[Exit Function]
[Statements]
[Name = expression]
End Function
Parameter
Public
Function procedure can be that all the scripts access to all other procedures.
Default
Only with the Public keyword in a Class block used to represent the class Function procedure is
the default method. If a class is more than one Default procedure is specified, there is an error.

Private
Function procedure that it can only be declared in the script or other process to access data if
the function is a class, then the class Function procedure can only be accessed in the other
process.
name
Function names follow the standard variable naming rules.
arglist
Behalf of the calling process when the parameter passed to the Function list of variables.
Multiple variables separated by commas.
statements
In the Function procedure to execute any of the main group of statements.
expression
Function return value.
arglist argument has the following syntax and parts:
[ByVal | ByRef] varname [()]

Parameter
ByVal
Indicates that the parameter is passed by value mode.
ByRef
Indicates that the argument passed by reference.
varname
The name of the variable representing the argument; follows standard variable naming rules.
Explain
If not explicitly specified using either Public or Private, Function procedures are public by
default, that is, they script all of the other processes is visible. Function values of local variables
in the call in process is not preserved.

Not in any other process (for example, Sub, or Property Get) Function procedure is defined.

Use Exit Function statement can immediately withdraw from the Function procedure. Program
execution continues with the process that called the Function statement following the
statement. Function procedure can appear anywhere in any number of Exit Function
statements.

Similar to a Sub procedure, Function procedure can take arguments, perform a series of
statements and change the parameter values of the independent process. And the difference
between a Sub procedure is: when to use the value returned by the function, you can use the
expression on the right Function procedure, which is used as the internal functions, such as
Sqr, Cos, or Chr.

In the expression, you can use the function name, and then the corresponding parameters are
given in parentheses, the list to call Function procedures. For more information call a Function
procedure, see the Call statement.

Warning Function procedure can be recursive, that is, the process can call their own to
complete a given task. However, recursion can lead to stack overflow.
From the function returns a value, simply assign a value to the function name. Anywhere in the
process can be of arbitrary assignment like this. If no name assigned, then the process will
return a default value: the value the function returns 0, the string function returns a zero-
length string (""). If there are no objects in the Function reference is assigned to name (using
Set), then the function returns an object reference returns Nothing.

The following example shows how to assign a function named BinarySearch return value. In
this sample, False is assigned to the function name, that did not find a certain value.

Function BinarySearch (...)


      ...
      'This value is not found. Return value of False.
      If lower> upper Then
          BinarySearch = False
          Exit Function
      End If
      ...
End Function
Function used in the process variable is divided into two categories: one is in the process that
are explicitly declared, and the other is not. In the process variables are explicitly declared
(using Dim or the equivalent) is always the process of local variables. Used but not in the
process variable is explicitly declared local variables, unless a higher level outside the
procedure are explicitly declare them.

Warning procedure can use in the process variables are explicitly declared, but as long as there
is no script-level name defined with the same name, will have a name conflict. If the process
referenced undeclared variables and other processes, constant or variable with the same
name, it is assumed that the process is referenced in the script-level name. To avoid such
conflicts, use the Option Explicit statement to force explicit declaration of variables.
Warning VBScript may rearrange arithmetic expressions to increase internal efficiency. When
the Function procedure to modify the value of a variable mathematical expressions should be
avoided in the same expression to use this function.
Requirements
Version 1
Returns the current locale ID value.

GetLocale ()
Explain
User locale is a collection of reference information, and user's language, country / region and
cultural tradition. locale determine the keyboard layout, alphabetic sort order and the date,
time, number and currency formats.

Return value can be any 32 - bit values, such as Locale ID below:

The following are examples GetLocale function usage. To use this code, copy the standard
HTML file, everything between <BODY> signs.

Enter Date in UK format: <input type="text" id="UKDate" size="20"> <p>


Here's the US equivalent: <input type="text" id="USdate" size="20"> <p>
<input type="button" value="Convert" id="button1"> <p>
Enter a price in German: <input type="text" id="GermanNumber" size="20">
<p>
Here's the UK equivalent: <input type="text" id="USNumber" size="20"> <p>
<input type="button" value="Convert" id="button2"> <p>

<script language="vbscript">
Dim currentLocale
'Get the current locale
currentLocale = GetLocale

Sub Button1_onclick
  Dim original
  original = SetLocale ("en-gb")
  mydate = CDate (UKDate.value)
  'IE has always been the locale is set to "U.S. English",
  'So please use currentLocale variable locale is set to "U.S. English."
  original = SetLocale (currentLocale)
  USDate.value = FormatDateTime (mydate, vbShortDate)
End Sub

Sub button2_onclick
  Dim original
  original = SetLocale ("de")
  myvalue = CCur (GermanNumber.value)
  original = SetLocale ("en-gb")
  USNumber.value = FormatCurrency (myvalue)
End Sub

</ Script>
Return to the file reference to an Automation object.

GetObject ([pathname] [, class])


Parameter
Pathname
Available options. A string that contains the object to retrieve the full path and file name. If
you omit the pathname must have class.
Class
Available options. String, the object's class.
class parameter syntax is appname.objectype, which includes the following components:

Parameter
appname
Required. String name of the application providing the object.
objectype
Required. String, to create the object type or class.
Explain
Use the GetObject function to access files in the Automation object, and the object can be
assigned to an object variable. Use the Set statement to assign the object returned by
GetObject to the object variable. For example:

Dim CADObject
Set CADObject = GetObject ("C: \ CAD \ SCHEMA.CAD")
In the implementation of the code, it will start with the specified path name associated
applications, while the objects in the specified file is activated. If pathname is a zero-length
string (""), GetObject returns a new object instance of the specified type. If the pathname
argument is omitted, GetObject returns a currently active object of the specified type. If you
do not specify the type of object, an error occurs.

Some applications allow you to activate only part of the file, the file name is added after an
exclamation point (!) And used to identify the files you want to activate part of the string. For
more information on creating this string, see the application object is created the
documentation.

For example, in a drawing application, a map stored in the file may have multiple layers. You
can use the following code to activate a layer in Figure SCHEMA.CAD:

Set LayerObject = GetObject ("C: \ CAD \ SCHEMA.CAD! Layer3")


If you do not specify the object's class, Automation will be provided according to the file name
to determine the application to start and to activate the object. However, some files may
support multiple object classes. For example, the figure might support three different types of
objects: Application Objects, Drawing Object, and a Toolbar object, all of which are part of the
same file. Use the class option parameter to specify the file you want to activate the object.
For example:

Dim MyObject
Set MyObject = GetObject ("C: \ DRAWINGS \ SAMPLE.DRW", "FIGMENT.DRAWING")
In the above example, FIGMENT is the name of a drawing application, and DRAWING is one of
the object types it supports. Object is activated, you can use the code defined in the object
variable to reference it. In the previous example, you can use the object variable MyObject
access the new object's properties and methods. For example:

MyObject.Line 9, 90
MyObject.InsertText 9, 100, "Hi, hello!"
MyObject.SaveAs "C: \ DRAWINGS \ SAMPLE.DRW"
Note that there is a current instance of the object, or use the loaded object file is created, use
the GetObject function. If there is no current instance, and not ready to start using the object
file has been loaded, use the CreateObject function.
If the object has been registered as a single instance of the object, no matter how many times
the implementation of CreateObject, can only create an instance of the object. If you use a
single instance of the object, when using zero-length string ("") syntax called, GetObject always
returns the same instance, and if the pathname argument is omitted, an error occurs.

Requirements
Version 5

GetRef returns a pointer to a reference process, this process can be bound to an event.
Set object.eventname = GetRef (procname)
Parameter
object
Required. Events associated with the name of the object.
eventname
Required. Bind with the function name of the event.
procname
Required. The string contains the name of the Sub or Function procedure, the process
associated with the event.
Explain
GetRef function can be used to VBScript procedure (Function or Sub) and DHTML (Dynamic
HTML) pages that are available in any event together. DHTML object model provides objects
for different events with a variety of available information.

Scripting and programming in other languages, GetRef provided function is called function
pointer, that is, it points to the specified event occurs when the address of a procedure to be
performed.

The following example illustrates the use of the function GetRef:

<SCRIPT LANGUAGE="VBScript">

Function GetRefTest ()
   Dim Splash
   Splash = "GetRefTest Version 1.0" & vbCrLf
   Splash = Splash & Chr (169) & "YourCompany 1999"
   MsgBox Splash
End Function

Set Window.Onload = GetRef ("GetRefTest")


</ SCRIPT>
Requirements
Version 5

Returns the value of the string of hexadecimal digits.

Hex (number)
The number argument is any valid expression.

Explain
If number is not an integer, before being evaluated to rounding to the nearest integer.

If the number is Hex returns


Null Null.
Empty zero (0).
Several other up to eight hexadecimal characters.

You can add a prefix in front of the number & H to represent a hexadecimal number. For
example, in hexadecimal notation, & H10 represents decimal number 16.

The following example uses the Hex function to return a hexadecimal number:

Dim MyHex
MyHex = Hex (5) 'returned 5.
MyHex = Hex (10) 'Return A.
MyHex = Hex (459) 'returned 1CB.
Requirements
Version 1
Returns a 0 to 23 integer (including 0 and 23), on behalf of one hour of the day.

Hour (time)
The time argument is any expression that can represent a time. If time contains Null, returns
Null.

The following example uses the Hour function to obtain the current time of the hour:

Dim MyTime, MyHour


MyTime = Now
MyHour = Hour (MyTime) 'MyHour contains
                        'Value representing the current time.
Requirements
Version 1
According to the value of expression a group of statements conditionally.

If condition Then statements [Else elsestatements]


Or, use the block form syntax:

If condition Then
[Statements]
[ElseIf condition-n Then
[Elseifstatements]]...
[Else
[Elsestatements]]
End If
Parameter
condition
One or more of the following two types of expressions:
Numeric or string expression that the result is True or False. If condition is Null, then the
condition is treated as False.
If TypeOf objectname Is objecttype form of expression. The objectname is any object reference
and objecttype is any valid object type. If specified by objecttype objectname is an object type,
the expression is True; otherwise False.

Statements
If the condition is True, the implementation of one or more (separated by colons) statement.
condition-n
The same condition.
elseifstatements
If the associated condition-n is True, the implementation of one or more statements.
elsestatements
If you have not condition or condition-n expression is True, the implementation of one or more
statements.
Explain
For short, simple tests, you can use single-line form (first syntax). However, the block form
(second syntax) provides more than the single form of structure and flexibility, easier to read,
maintain, and debug.

Note that in single-line syntax, you can execute multiple statements as a result of If ... Then to
judge, but all statements must be on the same line and separated by colons, such as the
following statement:
If A> 10 Then A = A + 1: B = B + A: C = C + B
When the program runs to block If (second syntax), the test condition. If the condition is True,
then the execution Then after the statement. If condition is False, each ElseIf part of the
conditional (if any) will be calculated and in turn be tested. When a True condition is found,
then the relevant statement after the Then is executed. If none of the ElseIf statement is True
(or no ElseIf clauses), then the statements following Else are executed. Execute the statement
after the Then or Else later, will continue after the End If statement.

Else and ElseIf clauses are available options. If block can be placed in any number of ElseIf
clauses, but must be before the Else clause. If block statements can be nested, that is,
contained in another block If statement into.

To determine whether a statement is an If block to check what follows the Then keyword.
Then the same if there are other non-comment line after the content, this statement is the
single-line If statement.

If a line block statement must be the first statement, and must end with End If statement.

Requirements
Version 1
In the dialog box displays a prompt waiting for user input text or click the button, and returns
the text box contents.

InputBox (prompt [, title] [, default] [, xpos] [, ypos] [, helpfile, context])


Parameter
prompt
String expression displayed as the message in the dialog box. maximum length of prompt is
approximately 1024 characters, depending on the width of the characters used. If prompt
consists of more than one line, you can separate the lines using a carriage return (Chr (13)),
line feed (Chr (10)) or carriage return-linefeed character combination (Chr (13) & Chr (10) ) to
separate each line.
Title
Displayed in the dialog title bar string expression. If you omit title, the application name will
appear in the title bar.
Default
Display the string expression in the text box, in the absence of other input values as the default
response. If you omit default, the text box is empty.
Xpos
Numeric expression that specifies the left edge of the dialog box with the left edge of the
screen, the horizontal distance (in twips). If you omit xpos, the dialog box is horizontally
centered.
Ypos
Numeric expression that specifies the dialog box on the edge of the screen on the edge of the
vertical distance (in twips). If you omit ypos, the dialog box is displayed on the screen vertically
positioned approximately one-third.
Helpfile
String expression that identifies the dialog box to help provide context-sensitive help file. If you
have provided helpfile, you must provide the context.
Context
Numeric expression that identifies the Help file specified by the author to a help topic context
number. If you have to provide context, you must provide the helpfile.
Explain
If both helpfile and context, will be automatically added in the dialog box "Help" button.

If the user clicks OK or presses ENTER, the InputBox function returns the text box contents. If
the user clicks Cancel, the function returns a zero-length string ("").

The following example uses the InputBox function to display an input box and assign the string
to the input variables:

Dim Input
Input = InputBox ("Enter name")
MsgBox ("Input:" & Input)
Requirements
Version 1
Returns a string in another string of the first occurrence.

InStr ([start,] string1, string2 [, compare])


Parameter
start
Available options. Numeric expression that sets the starting position for each search. If
omitted, the first character position to start the search. If start contains Null, an error occurs. If
the specified compare, you must have a start parameter.
string1
Required. String expression being searched.
string2
Required. To search for the string expression.
compare
Available options. Instructions used in the calculation of the comparison sub-string type values.
For values, see "Settings" section. If omitted, a binary comparison.
Set up
The compare argument can have the following values:

Constant Value Description


vbBinaryCompare 0 Perform a binary comparison.
vbTextCompare 1 Performs a textual comparison.

Return value
The InStr function returns the following values:

If InStr returns
string1 is zero length 0
string1 is Null Null
zero-length start string2
string2 is Null Null
string2 is not found 0
Found in string1 string2 string matching to find the location of
start> Len (string2) 0

Explain
The following example uses the InStr search string:

Dim SearchString, SearchChar, MyPos


SearchString = "XXpXXpXXPXXP" 'string to search.
SearchChar = "P" 'Search for "P".
MyPos = Instr (4, SearchString, SearchChar, 1) 'in position 4, text-comparison. Back 6.
MyPos = Instr (1, SearchString, SearchChar, 0) 'in position 1 for the binary comparison. Back 9.
MyPos = Instr (SearchString, SearchChar) 'By default, a binary comparison is carried out (the
final argument is omitted). Back 9.
MyPos = Instr (1, SearchString, "W") 'in position 1 for the binary comparison. Return 0 (could
not find "W").
Note InStrB function that contains the data bytes in the string, so InStrB not return a string
within another string of characters appeared in the first place, but the byte position.
Requirements
Version 1

Returns a string in another string, counting from the emergence from the end position.

InStrRev (string1, string2 [, start [, compare]])


Parameter
string1
Required. String expression being searched.
string2
Required. The search string expression.
Start
Available options. Numeric expression that sets the starting position for each search. If
omitted, the default value of -1 means the last character position to start the search. If start
contains Null, an error
compare
Available options. In calculating the sub-string that indicates the type of comparison to use the
value. If omitted, a binary comparison. For values, see "Settings" section.
Set up
The compare argument can have the following values:

Constant Value Description


vbBinaryCompare 0 Perform a binary comparison.
vbDatabaseCompare 2 implementation based on contained in the database (in this database
to perform comparisons) in the comparison of the information.

Return value
InStrRev returns the following values:

If InStrRev returns
string1 is zero length 0
string1 is Null Null
zero-length start string2
string2 is Null Null
string2 is not found 0
Found in string1 string2 string matching to find the location of
start> Len (string2) 0

Explain
The following example uses the InStrRev function to search string:

Dim SearchString, SearchChar, MyPos


SearchString = "XXpXXpXXPXXP" 'string to search.
SearchChar = "P" 'Search for "P".
MyPos = InstrRev (SearchString, SearchChar, 10, 0) 'in position 10 for the binary comparison.
Back 9.
MyPos = InstrRev (SearchString, SearchChar, -1, 1) 'in the final position of the text comparison.
Back 12.
MyPos = InstrRev (SearchString, SearchChar, 8) 'by default, for the binary comparison (omit the
last parameter). Return 0.
Note InStrRev function InStr function syntax and grammar are not the same.
Requirements
Version 2

Returns the integer part.

Int (number)
Fix (number)
The number argument can be any valid numeric expression. If number contains Null, returns
Null.

Explain
Int and Fix remove the fractional part of the number argument and returns an integer result.

The difference between Int and Fix is that if the number parameter is negative, Int returns the
first number is less than or equal to a negative integer, and Fix function returns the number is
greater than or equal to the first negative integer parameters. For example, Int converts -8.4 to
-9, and Fix converts -8.4 to -8 function.

Fix (number) is equivalent to:

Sgn (number) * Int (Abs (number))


The following example illustrates how the Int and Fix functions return integer portions of
numbers:

MyNumber = Int (99.8) 'Return 99.


MyNumber = Fix (99.2) 'Return 99.
MyNumber = Int (-99.8) 'returns -100.
MyNumber = Fix (-99.8) 'return -99.
MyNumber = Int (-99.2) 'returns -100.
MyNumber = Fix (-99.2) 'return -99.
Requirements
Version 1
Returns Boolean value that indicates whether a variable array.

IsArray (varname)
varname argument can be any variable.

Explain
If the variable is an array, IsArray function returns True; otherwise, it returns False. When the
variable contains an array, use the IsArray function is very effective.
The following example uses the IsArray function to verify whether MyVariable an array:

Dim MyVariable
Dim MyArray (3)
MyArray (0) = "Sunday"
MyArray (1) = "Monday"
MyArray (2) = "Tuesday"
MyVariable = IsArray (MyArray) 'MyVariable contains "True".
Requirements
Version 1
Returns a Boolean value that indicates whether an expression can be converted to date.

IsDate (expression)
Parameters can be any expression that can be identified as the date and time of the date
expression or string expression.

Explain
If the expression is a date, or may lawfully be translated into effective date, the IsDate function
returns True; otherwise it returns False. In the Microsoft Windows operating system, the
effective date range AD 100 to AD on January 1, 9999 December 31; valid date range varies
with the operating system.

The following example uses the IsDate function to determine whether an expression can be
converted to a date type:

Dim MyDate, YourDate, NoDate, MyCheck


MyDate = "October 19, 1962": YourDate = # 10/19/62 #: NoDate = "Hello"
MyCheck = IsDate (MyDate) 'returns True.
MyCheck = IsDate (YourDate) 'returns True.
MyCheck = IsDate (NoDate) 'returns False.
Requirements
Version 1
Returns Boolean value that indicates whether a variable has been initialized.

IsEmpty (expression)
expression argument can be any expression. However, because IsEmpty is used to determine
whether a variable has been initialized, so the expression parameter is often a variable name.

Explain
If the variable is not initialized or explicitly set to Empty, then the function IsEmpty returns
True; otherwise it returns False. If expression contains more than one variable, the total
returns False.

The following example uses the IsEmpty function to determine whether a variable can be
initialized:

Dim MyVar, MyCheck


MyCheck = IsEmpty (MyVar) 'returns True.
MyVar = Null 'assigned to Null.
MyCheck = IsEmpty (MyVar) 'returns False.
MyVar = Empty 'Fu is Empty.
MyCheck = IsEmpty (MyVar) 'returns True.
Requirements
Version 1

See returns a Boolean value indicating whether an expression contains no valid data (Null).

IsNull (expression)
expression argument can be any expression.

Explain
If expression is Null, IsNull returns True, that expression does not contain valid data, or IsNull
returns False. If the expression formed by a number of variables, expressions composed of
variables in any Null will cause the entire expression returns True.

Null value indicates that the variable does not contain valid data. Null and Empty, which
pointed out that the variable was not initialized. Null and zero-length string ("") are also
different, often refers to the zero-length string is an empty string.

Warning Use the IsNull function to determine whether an expression contains a Null value. In
some cases, like the expression evaluates to True, such IfVar = Null and IfVar <> Null, but they
usually always False. This is because any expression containing a Null is itself Null, so the result
of the expression is False.
The following example uses the IsNull function to determine whether a variable contains Null:

Dim MyVar, MyCheck


MyCheck = IsNull (MyVar) 'returns False.
MyVar = Null 'assigned to Null.
MyCheck = IsNull (MyVar) 'returns True.
MyVar = Empty 'Fu is Empty.
MyCheck = IsNull (MyVar) 'returns False.
Requirements
Version 1
Returns Boolean value that indicates whether the value of the expression number.

IsNumeric (expression)
expression argument can be any expression.

Explain
If the entire expression is recognized as a digital, IsNumeric function returns True; otherwise it
returns False. If expression is a date expression, IsNumeric function returns False.

The following example uses the IsNumeric function to determine whether a variable can be
used as values:

Dim MyVar, MyCheck


MyVar = 53 'assignment.
MyCheck = IsNumeric (MyVar) 'returns True.
MyVar = "459.95" 'assignment.
MyCheck = IsNumeric (MyVar) 'returns True.
MyVar = "45 Help" 'assignment.
MyCheck = IsNumeric (MyVar) 'returns False.
Requirements
Version 1
Returns Boolean value that indicates whether an expression references a valid Automation
object.

IsObject (expression)
expression argument can be any expression.

Explain
If expression is a subtype of Object variables or user-defined object, IsObject returns True;
otherwise it returns False.

The following example uses the IsObject function to determine whether an identifier
representative of the object variable:

Dim MyInt, MyCheck, MyObject


Set MyObject = Me
MyCheck = IsObject (MyObject) 'returns True.
MyCheck = IsObject (MyInt) 'returns False.
Requirements
Version 1
Returns a string, this string is included in the array by the number of sub-string concatenation
to create.

Join (list [, delimiter])


Parameter
list
Required. Contains the substring you want to connect one-dimensional array.
Delimiter
Available options. In the returned string used to separate sub-strings of characters. If omitted,
the space character (""). If delimiter is a zero-length string, then all items listed in the same list,
there is no delimiter.
Explain
The following example uses the Join function MyArray joint sub-string:

Dim MyString
Dim MyArray (3)
MyArray (0) = "Mr."
MyArray (1) = "John"
MyArray (2) = "Doe"
MyArray (3) = "III"
MyString = Join (MyArray) 'MyString contains "Mr. John Doe III".
Requirements
Version 2
Returns the specified array dimension of the smallest available subscript.

LBound (arrayname [, dimension])


Parameter
arrayname
Array variable name follows standard variable naming rules.
Dimension
Indicate which dimension to return to the lower bound of the integer. Use 1 for the first
dimension, 2 for the second, and so on. If dimension is omitted, the default value of 1.
Explain
The LBound function is used together with the UBound function to determine the size of the
array. Use the UBound function to find the upper bound of an array dimension.

Renyi Wei's lower bound is 0.

Requirements
Version 1
Returns a string lowercase.

LCase (string)
string argument is any valid string expression. If string contains Null, returns Null.

Explain
Only uppercase letters are converted to lowercase; all lowercase letters and non-alphabetic
characters remain unchanged.

The following example uses the LCase function to convert uppercase letters to lowercase
letters:

Dim MyString
Dim LCaseString
MyString = "VBSCript"
LCaseString = LCase (MyString) 'LCaseString contains "vbscript".
Requirements
Version 1
Returns a specified number of counting from the left side of the string of characters.

Left (string, length)


Parameter
string
String expression, the leftmost characters are returned. If string contains Null, returns Null.
Length
Numeric expression indicating the number of characters to return. If it is 0, returns a zero-
length string (""); if greater than or equal to the total number of characters in the string
argument, returns the entire string.
Explain
Can use the Len function to determine the number of characters in the string parameter.

The following example uses the Left function to return MyString left three letters:

Dim MyString, LeftString


MyString = "VBSCript"
LeftString = Left (MyString, 3) 'LeftString contains "VBS".
Note LeftB function with byte data contained in a string together. returns the string length is
not specified the number of bytes instead.
Requirements
Version 1
Returns the number of characters within a string, or store a variable number of bytes required.

Len (string | varname)


Parameter
string
Any valid string expression. If string contains Null, returns Null.
Varname
Any valid variable name. If varname argument contains Null, returns Null.
Explain
The following example uses the Len function returns the number of characters in the string:

Dim MyString
MyString = Len ("VBSCRIPT") 'MyString contains 8.
Note LenB function with byte string containing the data used. LenB not return the number of
characters in the string, but returns the number of bytes used to represent strings.
Requirements
Version 1
Return to image objects.

LoadPicture (picturename)
picturename argument is a string expression that indicates the need to load the picture file
name.

Explain
Recognized by LoadPicture bitmap graphics file format (. Bmp), icon files (. Ico), length
encoded files (. Rle), Metafile (. Wmf), Enhanced Metafile (. Emf), GIF (. gif) files and JPEG (.
jpg) file.

Log function requires


Returns the natural logarithm of the number.

Log (number)
The number argument is any valid numeric expression greater than 0.

Explain
Is the natural logarithm base e logarithm. The constant e is approximately 2.718282.

With n addition to the natural logarithm natural logarithm of x, you can get to the bottom of
the x n is the logarithm. As follows:

Logn (x) = Log (x) / Log (n)


The following example is a custom Function procedure, the process of calculating the base 10
logarithm:

Function Log10 (X)


   Log10 = Log (X) / Log (10)
End Function
Returns without leading spaces (LTrim), trailing spaces (RTrim), or leading and trailing spaces
(Trim) a copy of the string.

LTrim (string)
RTrim (string)
Trim (string)
string argument is any valid string expression. If string contains Null, returns Null.

Explain
The following example uses LTrim, RTrim, and Trim functions are used to remove the
beginning of the string space, trailing space, the beginning and trailing spaces:

Dim MyVar
MyVar = LTrim ("vbscript") 'MyVar contains "vbscript".
MyVar = RTrim ("vbscript") 'MyVar contains "vbscript".
MyVar = Trim ("vbscript") 'MyVar contains "vbscript".
Requirements
Version 1
Returns the natural logarithm of the number.

Log (number)
The number argument is any valid numeric expression greater than 0.

Explain
Is the natural logarithm base e logarithm. The constant e is approximately 2.718282.

With n addition to the natural logarithm natural logarithm of x, you can get to the bottom of
the x n is the logarithm. As follows:

Logn (x) = Log (x) / Log (n)


The following example is a custom Function procedure, the process of calculating the base 10
logarithm:

Function Log10 (X)


   Log10 = Log (X) / Log (10)
End Function
Requirements
Version 1
Returns a specified number from a string of characters.

Mid (string, start [, length])


Parameter
string
String expression from which characters are returned. If string contains Null, returns Null.
Start
the character string extracted in part by the start position. If you start more than the number
of characters in string, Mid returns a zero-length string ("").
Length
The number of characters to return. If omitted or text length exceeds the number of
characters (including the character at the start), will return the string to the end of the string
from the start all the characters.
Explain
To determine the number of characters in string, use the Len function.

The following example uses the Mid function returns the character string starting from the
fourth of six characters:

Dim MyVar
MyVar = Mid ("VB Script is fun!", 4, 6) 'MyVar contains "Script".
Note MidB function and contained in a string of bytes of data together. The parameter is not
specified number of characters, but the number of bytes.
Requirements
Version 1
Returns a 0 to 59 integer (including 0 and 59), on behalf of one hour of a minute.

Minute (time)
The time argument is any expression that can represent a time. If time contains Null, returns
Null.

Explain
The following example uses the Minute function returns the number of minutes hours:

Dim MyVar
MyVar = Minute (Now)
Requirements
Version 1
Return 1 to 12 of an integer (including 1 and 12), on behalf of a year.

Month (date)
date argument is any expression that can represent a date. If date contains Null, returns Null.

Explain
The following example uses the Month function returns the current month:

Dim MyVar
MyVar = Month (Now) 'MyVar contains
                   'The number that corresponds with the current month.
Requirements
Version 1
Returns a string that specifies the month.

MonthName (month [, abbreviate])


Parameter
month
Required. The numeric month. For example, January 1, February is 2, and so on.
Abbreviate
Available options. Boolean value that indicates whether the abbreviated month names. If
omitted, the default is False, that is, not abbreviated month name.
Explain
The following example uses MonthName function returns the date of the month abbreviated
expression:

Dim MyVar
MyVar = MonthName (10, True) 'MyVar contains "Oct".
Requirements
Version 2
In the dialog box displays the message, wait for the user clicks the button, and returns a value
indicating the user clicks the button.
MsgBox (prompt [, buttons] [, title] [, helpfile, context])
Parameter
prompt
As the message displayed in the dialog string expression. maximum length of prompt is
approximately 1024 characters, depending on the width of the characters used. If prompt
consists of more than one line, you can separate the lines using a carriage return (Chr (13)),
line feed (Chr (10)) or carriage return-linefeed character combination (Chr (13) & Chr (10) )
between each line.
Buttons
Numeric expression, is that the specified number and type of buttons to display, use the icon
style, the default button style logo and message box the sum of the values. For values, see
"Settings" section. If omitted, the default value for buttons is 0.
Title
Displayed in the dialog title bar string expression. If you omit title, the name will be displayed
in the application's title bar.
Helpfile
String expression that identifies the dialog box to help provide context-sensitive help file. If you
have provided helpfile, you must provide the context. In the 16-bit system platforms available.
Context
Numeric expression that identifies the Help file specified by the author to a help topic context
number. If you have to provide context, you must provide the helpfile. In the 16-bit system
platforms available.
Set up
buttons argument can have the following values:

Constant Value Description


vbOKOnly 0 OK button only.
vbOKCancel 1 displays OK and Cancel buttons.
vbAbortRetryIgnore 2 Show Abort, Retry and Ignore buttons.
vbYesNoCancel 3 shows Yes, No, and Cancel buttons.
vbYesNo 4 Display Yes and No buttons.
vbRetryCancel 5 Show Retry and Cancel buttons.
vbCritical 16 Critical message icon is displayed.
vbQuestion 32 Display Warning Query icon.
vbExclamation 48 displays a warning message icon.
vbInformation 64 display information messages icon.
vbDefaultButton1 0 First button is default.
vbDefaultButton2 256 Second button is default.
vbDefaultButton3 512 Third button is default.
vbDefaultButton4 768 Fourth button is default.
vbApplicationModal 0 Application Mode: The user must respond to the message box before
continuing work in the current application.
vbSystemModal 4096 System mode: the user response to the message box, all applications are
suspended.
The first group (0 - 5) used to describe the type of buttons displayed in the dialog box with the
number; the second group (16, 32, 48, 64) describes the icon style; the third group (0, 256 ,
512) is used to determine the default button; and the fourth group (0, 4096) determines the
style of message box. In these numbers to create buttons parameter values, each value can
only be drawn from a number.

Return value
The MsgBox function returns the following values:

Constant value of the button


vbOK 1 to determine the
vbCancel 2 canceled
vbAbort 3 to give
vbRetry 4 retries
vbIgnore 5 ignored
vbYes 6 is
vbNo 7 No

Explain
If both helpfile and context, the user can press the F1 key to view context-sensitive help topic
that corresponds to.

If the dialog box displayed Cancel button, pressing the ESC key and the same effect as clicking
Cancel. If the dialog box contains the Help button, the dialog box is promising to provide
context-sensitive help. However, click the other button, it will not return any value.

When MicroSoft Internet Explorer to use the MsgBox function, the title of any dialog box
always contains "VBScript", in order to facilitate the distinction between the standard dialog
box.

The following example demonstrates the use of the MsgBox function:

Dim MyVar
MyVar = MsgBox ("Hello World!", 65, "MsgBox Example")
   'MyVar contains 1 or 2, depending on which button is clicked.
Requirements
Version 1
According to the computer system to set the date and time to return the current date and time
values.

Now
Explain
The following example uses the Now function returns the current date and time:
Dim MyVar
MyVar = Now 'MyVar contains the current date and time.
Requirements
Version 1
Returns the octal value of the number string.

Oct (number)
The number argument is any valid expression.

Explain
If number is not an integer, before being evaluated, its rounded to the nearest integer.

If the number is back Oct


Null Null.
Empty zero (0).
Any other digital maximum to 11 octal characters.

Users can also directly be added before the number of octal & O said. For example, & O10 is
the octal 8 decimal notation.

The following example uses the Oct function returns the value of the octal number:

Dim MyOct
MyOct = Oct (4) 'returned 4.
MyOct = Oct (8) 'Return 10.
MyOct = Oct (459) 'returned 713.
Requirements
Version 1
Enable or disable the error handler.

On Error Resume Next


On Error GoTo 0
Explain
If your code does not use On Error Resume Next statement, run-time error occurred error
message is displayed at the same time, the code execution is terminated. But the decision to
run code of the host specific operations. Host can sometimes have a choice to handle all kinds
of errors. In some cases, it can be activated in the wrong place the script debugger. In other
cases, the host can not notify the user, so the error occurred is not clearly stated. As for how to
handle the error function depends entirely on the host.

In any particular process, as long as the call stack in place to enable the error handler, the error
occurred is generally not fatal. If the process is not enabled in a local error handler when an
error occurs, control is transferred through the call stack until it finds an error handler in the
process, and in the wrong place to handle the error. If in the course of the call stack error
handler is not found, then an error message the wrong place, at the same time terminate code
execution, or by the host to correctly handle the error.

On Error Resume Next causes the program to follow a false statement following the statement
continued, or according to a recent call by the process (the process containing the On Error
Resume Next statement) in the statement continues. This statement can be run regardless of
when the error and continue execution, after which you can process established within the
error handling routine. Another procedure is called, On Error Resume Next statement becomes
inactive. So, if you want to conduct an internal error handling routine, you should call the
routine in each run On Error Resume Next statement.

When you call another procedure, prohibit the use of On Error Resume Next statement, so if
you want to embed error handler routine, you need to call the routine should perform each On
Error Resume Next statement. When a process exits, the error handler to resume it before
entering the state of the exit process.

If you have enabled the On Error Resume Next error handler, you can use On Error GoTo 0
disables error-handling procedures.

The following example illustrates how to use the On Error Resume Next statement:

On Error Resume Next


Err.Raise 6 'lead to overflow errors.
MsgBox ("Error #" & CStr (Err.Number) & "" & Err.Description)
Err.Clear 'clear the error.
Requirements
Version 1
Mandatory explicit declaration of all variables in the script.

Option Explicit
Explain
If you use Option Explicit, the statement must appear in the script before any other
statements.

Use the Option Explicit statement, you must use the Dim, Private, Public, or ReDim statement
to explicitly declare all variables. If you try to use undeclared variable name, an error occurs.

Tips can be used Option Explicit to avoid incorrectly typing the variable name already exists.
Clear scope for a variable, use this statement to avoid confusion.
The following example illustrates how to use the Option Explicit statement:

Option Explicit 'force the declaration of variables.


Dim MyVar 'declare the variable.
MyInt = 10 'undeclared variable error.
MyVar = 10 'declare the variable does not produce an error.
Requirements
Version 1
Define private variables and allocates storage space. In the Class block to define private
variables.

Private varname [([subscripts ])][, varname [([subscripts])]]...


Parameter
varname
The name of the variable; follows standard variable naming rules.
subscripts
The dimension of an array variable, you can declare up to 60-dimensional arrays. The
subscripts argument uses the following syntax:
upper [, upper]...

Lower bound of the array is always 0.

Explain
Private statement variables can be declared the variable in the script to use.

In reference to the object variable using, you must use the Set statement assigned an existing
object of this variable. Until it is assigned, the declared object variable is initialized Empty.

Also used the Private statement with empty parentheses to declare dynamic arrays. After
declaring a dynamic array, you can use the ReDim statement within a procedure to define the
dimension of the array and the elements. If the Private, Public, or Dim statement has explicitly
assigned array size, is trying to re-declare the array dimension, an error occurs.

Note that in the process use the Private statement, usually on the Private statement at the
beginning of the process.
The following example illustrates how to use the Private statement:

Private MyNumber 'private Variant variables.


Private MyArray (9) 'private array variable.
   'Variant variable number of private declarations.
Private MyNumber, MyVar, YourNumber
Requirements
Version 1
In the Class block, the declaration form used to get (back) property values Property name of
the principal process, parameters, and code.

 [Public [Default] | Private] Property Get name [(arglist)]


    [Statements]
    [[Set] name = expression]
    [Exit Property]
    [Statements]
    [[Set] name = expression]
End Property
Parameter
Public
Property Get procedure that can be used by all the other scripts in the process of access.
Default
Only used in conjunction with the Public keyword, indicating that the Property Get procedure
of attributes defined in the default properties for the class.
Private
Property Get procedure is that it is defined only for the Class block other process can access.
name
Property Get procedure name; to comply with the standard variable naming conventions, the
only difference is that it can block with the same Class of Property Let or Property Set
procedure.
arglist
The list of variables representing the Property Get procedure is called a parameter passed to it.
Multiple parameters separated by commas. Property Get procedure name of each parameter
in the Property Let procedure must be with the corresponding parameters in the same (if any).

statements
Arbitrary set of statements, in the main body of a Property Get procedure performed.
Set
In the object as the return value of the Property Get procedure using keywords.
expression
Property Get procedure return values.
Explain
If you do not use Public or Private explicitly stated, the Property Get procedure is the default
for the public, that they are for all the other scripts in the process are visible. Property Get
procedure the values of local variables in different processes is not preserved between calls.

In any other process (eg Function or Property Let) can not be defined within the Property Get
procedure.

Exit Property statement causes an immediate exit from a Property Get procedure. Program will
continue to implement the Property Get procedure is called the statement following the
procedure. Exit Property statements can appear in the Property Get procedure anywhere in
the number of times.

Sub and Property Let procedure with a similar, Property Get procedure is able to accept the
parameters of the process, you can perform a series of statements, and change parameter
values. However, a Sub and Property Let The difference is, Property Get procedure can be used
in an expression on the right, with the use of Function or property with the same name as a
way to return value of the property.

Requirements
Version 5
In the Class block, the statement name, parameters and codes, which constitute the process of
setting property values of the Property the subject.

 [Public | Private] Property Let name (


   [Arglist,] value
)
    [Statement]
    [Exit Property]
    [Statement]
End Property
Parameter
Public
Property Let procedure that can be used by all scripts in all the other processes to access.
Private
Property Let procedure that can only be defined within the Class block access to other
processes.
name
Property Let procedure name; to comply with the standard variable naming conventions, the
only difference lies in the name of the same Class block with a Property Get or Property Set
procedure is the same.
arglist
The list represents the variable is passed in the call to the Property Let procedure parameters.
Multiple parameters separated by commas. Property Let procedure must match the name of
each parameter in the corresponding Property Get procedure parameters the same. In
addition, Property Let procedure parameters than the corresponding Property Get procedure
is always one more. This parameter is given for the value of the property.
value
This variable contains the value of the property must be given. When the process is called, the
parameter will appear in the call to the right of expression.
statement
Arbitrary set of statements, in the Property Let procedure will be executed within the main
body.
Explain
If you do not explicitly be specified using either Public or Private, Property Let procedure is
defaulted to the public, that they are for the script to all other processes are visible. Property
Let procedure in the values of local variables between calls to the different processes is not to
be saved.

In any other process (eg Function or Property Get) can not define the internal Property Let
procedure.

Exit Property statement causes an immediate exit from the Property Let procedure. Property
Let procedure, the program will call the point after the statement continued. Exit Property
statements can appear in the Property Let procedure anywhere in the number of times.
Note that each of the Property Let statement must define at least one defined process
parameters. This parameter (multiple parameters in the last parameter) when the Property Let
statement contains is called to give the value of the property. This parameter is called in front
of the syntax value.
Function and Property Get procedure with a similar, Property Let procedure is a separate
process, which can accept parameters, perform a series of statements, you can also change
the value of the parameter. However, unlike a Function and Property Get procedure is
different is that they both return a value, and Property Let procedure, only the left side of an
assignment for the property.

Requirements
Version 5
In the Class block, the statement name, parameters, and code, which constitute the reference
set to the main object of the Property procedure.

 [Public | Private] Property Set name (


   [Arglist,] reference
)
    [Statement]
    [Exit Property]
    [Statement]
End Property
Parameter
Public
Property Set procedure can be that all the scripts in the process of access to all other.
Private
Property Set procedure that can only be declared of the same Class block access to other
processes.
name
Property Set procedure name; to comply with the standard variable naming conventions, but
with the same name can block a Class Property Get or Property Let procedure, the same.
arglist
List of variables, representing the Property Set procedure is called a parameter passed to it.
Multiple parameters separated by commas. In addition, Property Set procedure is always
better than its corresponding Property Get procedure is more than one parameter. The extra
parameters are given attributes of the object.
reference
Variable, which contains the object reference is used to assign the right side of the object
reference.
statement
In the Property Set procedure will be performed in any one of the main group of statements.
Explain
Public or Private unless explicitly specified, or a Property Set procedure is set to the default of
the public model in which all the other scripts in the process are visible. In a different
procedure call, Property Set in the process of local variables are not saved.
In any other process (eg Function or Property Let) in the Property Set procedure is not to
define.

Exit Property statement causes an immediate exit from a Property Set procedure. The program
will continue after the Property Set procedure call statements.

Requirements
Version 5

Parameter
varname

subscripts

Explain

After declaring a dynamic array, you can use the ReDim statement within a procedure to
define the dimension of the array and the elements.

   

Requirements
Version 1
Explain

   
   
   
Loop
Requirements
Version 1

Parameter

varname

subscripts

Explain

...

Requirements
Version 1

Or

Explain

Requirements
Version 1

Parameter
expression
Required.

Required.

Required.

Available options.

Available options.
Compare
Available options. For values, see "Settings" section.
Set up

Constant Value Description


vbBinaryCompare 0 Perform a binary comparison.
vbTextCompare 1 Performs a textual comparison.
Explain

Requirements
Version 2

Parameter

Required.

Required.

Required.
Explain

   
End Function

Requirements
Parameter

Explain

Requirements
Version 2

The number argument can be any valid numeric expression.

Explain
Parameter
Expression
Required.

Available options.
Explain

Requirements
Version 2

string argument is any valid string expression.

Explain

Requirements
Version 1

Explain
   
   
   
   
   
   
   
End Function
Requirements
Version 2

Explain

   
   
   
   
   
   
   
End Function
Requirements
Version 2

Explain

   
   
   
   
   
   
   
End Function
Requirements
Version 2

Explain

   
   
   
   
   
   
   
End Function
Requirements
Version 2

The time argument is any expression that can represent a time. If time contains Null, returns
Null.

Explain

   
Requirements
Version 2

End Select
Parameter

Explain

   
   
      
      
      
      
   End Select
End Sub
Requirements
Version 1

Set object.eventname = GetRef (procname)


Parameter
Available options.
object
Required.

Required.
procname
Required.
Explain

   
   Set fso = CreateObject ("Scripting.FileSystemObject")
   
   
   
   
   
   
End Function

Requirements
Version 1

Explain

To use this code, copy the standard HTML file, everything between <BODY> signs.

Enter Date in UK format: <input type="text" id="UKDate" size="20"> <p>


Here's the US equivalent: <input type="text" id="USdate" size="20"> <p>
<input type="button" value="Convert" id="button1"> <p>
Enter a price in German: <input type="text" id="GermanNumber" size="20">
<p>
Here's the UK equivalent: <input type="text" id="USNumber" size="20"> <p>
<input type="button" value="Convert" id="button2"> <p>

<script language="vbscript">
Dim currentLocale
'Get the current locale
currentLocale = GetLocale

Sub Button1_onclick
  Dim original
  original = SetLocale ("en-gb")
  mydate = CDate (UKDate.value)
  'IE has always been the locale is set to "U.S. English",
  'So please use currentLocale variable locale is set to "U.S. English."
  original = SetLocale (currentLocale)
  USDate.value = FormatDateTime (mydate, vbShortDate)
End Sub

Sub button2_onclick
  Dim original
  original = SetLocale ("de")
  myvalue = CCur (GermanNumber.value)
  original = SetLocale ("en-gb")
  USNumber.value = FormatCurrency (myvalue)
End Sub

</ Script>

The number argument can be any valid numeric expression.

Explain
The number argument can be any angle in radians to a valid numeric expression.

Explain

Explain

Requirements
Version 1

Parameter
expression
Required.
Available options.

Available options.
Compare
Available options. For values, see "Settings" section.
Set up

Constant Value Description


vbBinaryCompare 0 Perform a binary comparison.
vbTextCompare 1 Performs a textual comparison.

Explain

Requirements
Version 2

Explain

Parameter
Required.

Required.
Compare
Available options. For values, see "Settings" section.
Set up

Constant Value Description


vbBinaryCompare 0 Perform a binary comparison.
vbTextCompare 1 Performs a textual comparison.

Explain

Requirements
Version 1

Parameter
number
If number contains Null, returns Null.

Explain
Requirements
Version 1

   [Statements]
   
   [Statements]
End Sub
Parameter
Public

Default

Private

name

arglist
Multiple variables separated by commas.
statements

arglist argument has the following syntax and parts:

[ByVal | ByRef] varname [()]


Parameter
ByVal

ByRef

varname

Explain
Warning procedure can use in the process variables are explicitly declared, but as long as there
is no script-level name defined with the same name, will have a name conflict. If the process
referenced undeclared variables and other processes, constant or variable with the same
name, it is assumed that the process is referenced in the script-level name. To avoid such
conflicts, use the Option Explicit statement to force explicit declaration of variables.
Requirements
Version 1

The number argument can be any angle in radians to a valid numeric expression.

Explain

Explain

Requirements
Version 1

Explain
   
   
   
   Next
   
   
End Function
Requirements
Version 5

Parameter

Any numeric expression.

Any numeric expression.


Explain

Requirements
Version 1

Explain

Requirements
Version 1
string argument is any valid string expression.

Explain

Requirements
Version 1

Explain
Requirements
Version 2

Parameter

Required.

Available options.
Explain

Requirements
Version 1

string argument is any valid string expression.

Explain

Requirements
Version 1
Constant Value Description

Explain

Requirements
Version 1
Do
Date
Space

Parameter
date
If date contains Null, returns Null.
Firstdayofweek
The first day of the week specified constant.
Set up

Constant Value Description


vbUseSystemDayOfWeek 0 Use National Language Support (NLS) API setting.

vbMonday 2 Monday
vbTuesday 3 Tuesday
vbWednesday 4 Wednesday
vbThursday 5 Thursday
vbFriday 6 Friday
vbSaturday 7 Saturday

Constant Value Description


vbMonday 2 Monday
vbTuesday 3 Tuesday
vbWednesday 4 Wednesday
vbThursday 5 Thursday
vbFriday 6 Friday
vbSaturday 7 Saturday

Explain

Requirements
Version 1

Parameter

Required.

Available options.
Firstdayofweek
Available options.
Set up

Constant Value Description


vbUseSystemDayOfWeek 0 Use National Language Support (NLS) API setting.
vbSunday 1 Sunday (default)
vbMonday 2 Monday
vbTuesday 3 Tuesday
vbWednesday 4 Wednesday
vbThursday 5 Thursday
vbFriday 6 Friday
vbSaturday 7 Saturday

Explain

Dim MyDate

Requirements
Version 2

Please refer to the

Parameter
condition
If condition is Null, condition is treated as False.
statements

Explain

   Counter = Counter + 1 'increment the counter.


   

Requirements
Version 1

    statements

Parameter
object

statements

Explain

   
   
   
Requirements
Version 1

If date contains Null, returns Null.

Explain

Requirements
Version 1
The Abs function
Returns the absolute value.

Abs (number)
The number argument can be any valid numeric expression. If number contains Null, return
Null; if it is an uninitialized variable, zero is returned.

Explain
The absolute value is its unsigned magnitude. For example, Abs (-1) and Abs (1) returns 1.

The following example uses the Abs function to compute the absolute value of:

Dim MyNumber
MyNumber = Abs (50.3) 'returns 50.3.
MyNumber = Abs (-50.3) 'returns 50.3.
Returns an array of Variant.

Array (arglist)
arglist argument is assigned to a Variant containing the array elements in a list of values
(separated by commas). If you do not specify this parameter, you will create a zero-length
array.
Explain
Used to refer to array elements of said symbol, followed by the composition of the variable
name in brackets, braces indicate required elements included in the index. In the following
example, the first statement creates a variable named A. The second statement assigns an
array variable A. The last statement will be included in the second array element value is
assigned to another variable.

Dim A
A = Array (10,20,30)
B = A (2) 'B is now 30.
Note that the variable is not declared as an array can still contain an array. Although a Variant
variable containing an array with array variable containing Variant elements are conceptually
different, but the access array elements are the same.
Requirements
Version 2

Asc function
Please refer to the
Chr function
Requirements
Version 1
Returns a string corresponding to the first letter of the ANSI character code.

Asc (string)
string argument is any valid string expression. If the string contains no characters, a runtime
error occurs.

Explain
The following example, Asc returns a string first letter of each ANSI character code:

Dim MyNumber
MyNumber = Asc ("A") 'Return 65.
MyNumber = Asc ("a") 'Return 97.
MyNumber = Asc ("Apple") 'Return 65.
Note AscB function and contains the byte data strings. AscB not return the first character of
the character code, but returns the first byte. AscW use Unicode characters for 32-bit
platforms available. It returns the Unicode (wide) character code, thereby avoiding the code
from ANSI to Unicode conversion.
Requirements
Version 1
Atn function

Returns the arctangent of the value.

Atn (number)
The number argument can be any valid numeric expression.

Explain
Atn function calculating the ratio of two sides of a right triangle (number) and returns the
corresponding angle in radians. This ratio is the length and angle on the edge of the adjacent
side length ratio. The results range from-pi / 2 to pi / 2 radians.

Transformed into the angle of curvature of the arc is multiplied by pi/180. On the contrary,
changing the angle in radians is the angle multiplied by 180/pi.

The following example uses Atn to calculate the value of pi:

Dim pi
pi = 4 * Atn (1) 'calculate the value of pi.
Note Atn is Tan (angle as a parameter to return the ratio of both sides of a right triangle) the
inverse trigonometric functions. Do not confuse Atn with the cotangent (tangent of the
reciprocal (1/tangent)) function.
Requirements
Version 1
Pass control to a Sub or Function procedure.

 [Call] name [argumentlist]


Parameter
Call
Optional keyword. If you specify this keyword, you must use parentheses to enclose
argumentlist. For example:
Call MyProc (0)

name
Required. To invoke the procedure name.
argumentlist
Available options. Passed to the process variable, array or list of expressions, each separated
by a comma.
Explain
When calling a procedure, do not use the Call keyword. However, if the request parameters
using the Call keyword to call the process, you must use parentheses to enclose argumentlist.
If you omit the Call keyword, you must also omit the parentheses around argumentlist
parameters. Use Call syntax to call an internal function or user-defined function, the function
return value is discarded.

Call MyFunction ("Hello World")


Function MyFunction (text)
   MsgBox text
End Function
Requirements
Version 1
Returns an expression that has been converted to Boolean subtype Variant.

CBool (expression)
expression is any valid expression.

Explain
If expression is zero, then return False; otherwise returns True. If the expression can not be
interpreted as a value, then a runtime error occurs.

The following example uses the CBool function to an expression into a Boolean type. If the
expression calculated value is nonzero, then the CBool function returns True; otherwise it
returns False.

Dim A, B, Check
A = 5: B = 5 'Initialize variables.
Check = CBool (A = B) 'check box is set to True.
A = 0 'define variables.
Check = CBool (A) 'check box is set to False.
Requirements
Version 1
CByte (expression)
expression argument is any valid expression.

Explain
Typically, you can use to write code type conversion functions to show the result of some
operation should be expressed as a specific data type, instead of the default type. For
example, where currency, single, double, or integer arithmetic cases, the use CByte enforce
byte operations.

CByte function used for other data types to a Byte from the sub-types of the internationally
recognized format. For example, different decimal separators (such as thousand separators)
are properly recognized depending on the locale settings.

If the Byte subtype expression in the acceptable range, the error occurs. The following
example uses the CByte function to convert expression byte:

Dim MyDouble, MyByte


MyDouble = 125.5678 'MyDouble is a double value.
MyByte = CByte (MyDouble) 'MyByte contains 126.
Requirements
Version 1
CCur (expression)
expression argument is any valid expression.
Explain
Typically, you can use the subtype conversion functions to write code to display the result of
some operation should be expressed as a particular data type rather than the default data
type. For example, in the case of integer arithmetic, use CCur to force currency arithmetic.

CCur function from any other data type to a Currency subtype of the internationally recognized
format. For example, different decimal separators and thousands separators are properly
recognized depending on the locale settings.

The following example uses the CCur function to convert an expression Currency type:

Dim MyDouble, MyCurr


MyDouble = 543.214588 'MyDouble is double precision.
MyCurr = CCur (MyDouble * 2) 'to MyDouble * 2 (1086.429176) the result is converted to
Currency (1086.4292).
Requirements
Version 1
Returns an expression that has been converted to a Date subtype Variant.

CDate (date)
date argument is any valid date expression.

Explain
IsDate function to determine if date can be converted to a date or time. CDate recognizes date
literals and time literals as well as some dates in the acceptable range of numbers. In the
digital conversion to date, the integer portion is converted to date, from the fractional part is
converted to the time since midnight.

Depending on the system locale CDate recognizes date formats. If the data set the date format
can not be identified, it can not determine the year, month, day of the correct order. In
addition, if the long date format string that contains the day of the week, it can not be
identified.

The following example uses the CDate function to convert strings into date type. Generally not
recommended to use hardware decode dates and times as strings (example below is
reflected). The use of time and date text (such as # 10/19/1962 #, # 4:45:23 PM #).

MyDate = "October 19, 1962" 'defined date.


MyShortDate = CDate (MyDate) 'into a date data type.
MyTime = "4:35:47 PM" 'definition of time.
MyShortTime = CDate (MyTime) 'into a date data type.
Requirements
Version 1
Returns an expression that has been converted to a Double subtype of Variant.
CDbl (expression)
expression argument is any valid expression.

Explain
Typically, you can use the subtype conversion functions to write code to display the result of
some operation should be expressed as a particular data type rather than the default data
type. For example, where currency or integer arithmetic in the case, use CDbl or CSng function
to force double-precision or single-precision arithmetic.

CDbl function is used to from other data type to Double subtype of internationally recognized
format. For example, decimal separators and thousands separators are properly recognized
depending on the locale settings.

The following example uses the CDbl function to convert expression to a Double.

Dim MyCurr, MyDouble


MyCurr = CCur (234.456784) 'MyCurr the Currency type (234.4567).
MyDouble = CDbl (MyCurr * 8.2 * 0.01) 'the result is converted to type Double (19.2254576).
Requirements
Version 1
Returns the specified ANSI character code corresponding to the characters.

Chr (charcode)
charcode parameter is the number of characters can be identified.

Explain
From 0 to 31 numerical standard is not printable ASCII code. For example, Chr (10) return line
feed.

The following example uses the Chr function returns the character code specified by the
corresponding characters:

Dim MyChar
MyChar = Chr (65) 'Return A.
MyChar = Chr (97) 'returns a.
MyChar = Chr (62) 'return>.
MyChar = Chr (37) 'return.
Note ChrB function and contained in a string of bytes of data together. ChrB not return one or
two-byte characters, but always returns a single byte characters. ChrW is to use Unicode
characters in the 32-bit platforms. Its argument is a Unicode (wide character) character code,
thereby avoiding the ANSI into Unicode characters.
Requirements
Version 1
Returns an expression that has been converted to an Integer subtype of Variant.
CInt (expression)
expression argument is any valid expression.

Explain
Typically, you can use to write code type conversion functions to show the result of some
operation should be expressed as a specific data type, instead of the default type. For
example, in the event of currency, single-precision or double precision arithmetic in the case,
use CInt or CLng to force integer arithmetic.

CInt function to provide from other data type to an Integer subtype of an internationally
recognized format. For example, different decimal separators (such as thousand separators)
are properly recognized depending on the locale settings.

If the Integer subtype expression outside the acceptable range, an error occurs.

The following example uses the CInt function to convert the value to Integer:

Dim MyDouble, MyInt


MyDouble = 2345.5678 'MyDouble is Double.
MyInt = CInt (MyDouble) 'MyInt contains 2346.
Note CInt differs from the Fix and Int functions remove the fractional part of value, instead of
using the rounding mode. When the fractional part is exactly equal to 0.5, CInt always be
rounded to the nearest even number. For example, 0.5 rounds to 0, and 1.5 rounds to 2.
Requirements
Version 1
Declare a class name, and the composition of the class variable, properties and methods
defined.

Class name
    statements
End Class
Parameter
name
Required. Class names; follow standard variable naming rules.
statements
Required. One or more statements, the definition of Class variables, properties and methods.
Explain
In the Class block, members through its corresponding opening statement is declared as
Private or Public. Is declared as Private will only be visible within the Class block. Be declared
as Public, not only in Class is visible within the block of code outside the Class block is visible.
Private or Public is not used by default explicitly declared as Public. Within the class block the
process of being declared as Public (Sub or Function) will become the class. Public variables will
be the class of property, with the use of Property Get, Property Let and Property Set explicit
statement of the same attributes. The default class properties and methods are part of their
statement specified with the Default keyword. On how to use the keyword, refer to a separate
declaration statement topics.

Requirements
Version 5
Returns an expression that has been converted to a Long subtype of Variant.

CLng (expression)
expression argument is any valid expression.

Explain
Typically, you can use the subtype conversion functions to write code to display the result of
some operation should be expressed as a particular data type rather than the default data
type. For example, in the event of currency operations, single-or double-precision arithmetic in
the case, use CInt or CLng to force integer arithmetic functions.

CLng function used for other data types from the Long subtype of the internationally
recognized format. For example, different decimal separators and thousands separators are
properly recognized depending on the locale settings.

If the value is not in Long subtype expression within the allowed range, an error occurs.

The following example uses the CLng function to convert the value of Long:

Dim MyVal1, MyVal2, MyLong1, MyLong2


MyVal1 = 25427.45: MyVal2 = 25427.55 'MyVal1, MyVal2 is double-precision values.
MyLong1 = CLng (MyVal1) 'MyLong1 25427.
MyLong2 = CLng (MyVal2) 'MyLong2 include 25428.
Note CLng differs from the Fix and Int functions remove the fractional part, but a rounded way.
When the fractional part is exactly equal to 0.5, CLng function always be the number rounded
to the nearest even number. For example, 0.5 rounds to 0, and 1.5 rounds to 2.
Requirements
Version 1
Declaration for a constant value instead of text.

 [Public | Private] Const constname = expression


Parameter
Public
Available options. This keyword is used to declare in the Script class can be used for all
procedures in all scripts constant. Not allowed to use in the process.
Private
Available options. This keyword is used in the script level to declare the statement can only be
used where the script constant. Not allowed to use in the process.
constname
Required. Constant name, according to the standard variable naming conventions.
expression
Required. Text or other constant, or include in addition to outside Is all arithmetic operators
and logical operators in any combination.
Explain
By default, constants are shared. The proprietary process is always constant, and its visibility
can not be changed. Script, the script can be used to change the Private keyword-class
constant visibility of the default values.

In the same line to declare several constants, can be a comma separate each constant
assignment. When declaring a constant in this way, if you use a Public or Private keyword, the
keyword of the line all the constants are valid.

Constant declaration can not use variables, user-defined function or VBScript internal
functions (such as Chr). By definition, they can not be constant. Also do not contain operators
from creating a constant expression, that is only allowed to use a simple constant. In the Sub
or Function statement during the process of constant local constant. Constant in the process is
declared outside the declaration where the script global constants. Can be used in any place
with a constant expression. The following code illustrates how to use the Const statement:

Const MyVar = 459 'constant default to the public.


Private Const MyString = "HELP" 'definition of private constant.
Const MyStr = "Hello", MyNumber = 3.4567 'define multiple constants on a single line.
Note his constant support and easy to make script changes. Unlike variables, the script is
running, a constant can not be accidentally modified.
Requirements
Version 5
Transfer function
Asc function

CBool function

CByte function

CCur to

CDate function

CDbl function

Chr function

CInt function

CLng function
CSng function

CStr function

Hex function

Oct function
The Cos function
Returns the cosine of an angle.

Cos (number)
The number argument can be any angle in radians to a valid numeric expression.

Explain
The Cos function to take an angle and returns the ratio of both sides of a right triangle. This
ratio is a right triangle in the corner of the adjacent side length ratio of the length of the
hypotenuse. The results range from -1 to 1.

Angle into radians method is to use the angle multiplied by pi/180. On the contrary, the angle
into radians is radians multiplied by 180/pi.

The following example uses the Cos function returns the cosine of an angle:

Dim MyAngle, MySecant


MyAngle = 1.3 'definition of an angle in radians.
MySecant = 1 / Cos (MyAngle) 'calculated secant.
Creates and returns a reference to the Automation object.

CreateObject (servername.typename [, location])


Parameter
servername
Required. Application providing the object name.
typename
Required. To create an object type or class.
location
Available options. Network server where the object will be created.
Explain
Automation servers provide at least one type of object. For example, word processing
applications can provide an application object, document object and tool bar object.

To create an Automation object, use the CreateObject function returns the object is assigned
to an object variable:

Dim ExcelSheet
Set ExcelSheet = CreateObject ("Excel.Sheet")
The code starts to create the object (in this instance, is a Microsoft Excel spreadsheet)
application. Object is created, you can use the code defined in the object variable referencing
this object. In the following example, you can use the object variable, ExcelSheet and other
Excel objects, including the Application object and the Cells collection to access the new
object's properties and methods. For example:

'Throughout the Excel Application object are visible.


ExcelSheet.Application.Visible = True
'Some text into the first worksheet cell.
ExcelSheet.ActiveSheet.Cells (1,1). Value = "This is column A, row 1"
'Save the worksheet.
ExcelSheet.SaveAs "C: \ DOCS \ TEST.XLS"
'Close Excel, the Quit method in the Application object.
ExcelSheet.Application.Quit
'Release the object variable.
Set ExcelSheet = Nothing
On the remote server to create an object, when only complete Internet security is turned off.
By passing the computer name to CreateObject server name parameter, can create objects on
the remote network. The name of the share as part of the machine name. For example, name
the network share: "\ \ myserver \ public", servername is "myserver". In addition, only specify
servername using DNS format or an IP address.

The following code returns a run-in named "myserver" on the remote network computer
version of an instance of Excel:

Function GetVersion
   Dim XLApp
   Set XLApp = CreateObject ("Excel.Application", "MyServer")
   GetVersion = XLApp.Version
End Function
Error occurred on the specified remote server does not exist or can not be found.

Requirements
Version 2
Returns an expression that has been converted to a Single subtype of Variant.

CSng (expression)
expression argument is any valid expression.

Explain
Typically, you can use to write code type conversion functions to show the result of some
operation should be expressed as a specific data type, instead of the default type. For
example, in the event of currency or integer arithmetic in the case, use CDbl or CSng to force
double-precision or single precision arithmetic.
CSng function used for the data type to a Single from the other sub-types of the internationally
recognized format. For example, the decimal separator (such as thousand separators)
identification depending on the locale settings.

If the expression in the Single subtype of range, the error occurs.

The following example uses the CSng function to convert the value Single:

Dim MyDouble1, MyDouble2, MySingle1, MySingle2 'MyDouble1, MyDouble2 is double-


precision values.
MyDouble1 = 75.3421115: MyDouble2 = 75.3421555
MySingle1 = CSng (MyDouble1) 'MySingle1 contains 75.34211.
MySingle2 = CSng (MyDouble2) 'MySingle2 contains 75.34216.
Requirements
Version 1
Returns the current system date.

Date
Explain
The following example uses the Date function returns the current system date:

Dim MyDate
MyDate = Date 'MyDate contains the current system date.
Requirements
Version 1
Returns the specified time interval has been added the date.

DateAdd (interval, number, date)


Parameter
interval
Required. A string expression that you want to add time interval. For values, see "Settings"
section.
number
Required. Numeric expression that you want to add the number of time intervals. Numeric
expression can be positive (to get dates in the future) or negative (to get dates in the past).
date
Required. Variant or interval of that date to add text.
Set up
The interval argument can have the following values:

Setting Description
yyyy Year
q quarter
m Month
y number of days a year
d day
w the number of days a week
ww Week
h hours
n minutes
s seconds

Explain
DateAdd function can be used to add or subtract from the date specified time interval. For
example, you can use the DateAdd date 30 days from the day after the date or the date from
now after a 45 minute time. Adding to the date of "day" as the unit time interval, use the
"number of days a year" ("y"), "Day" ("d") or "week days" ("w").

The DateAdd function will not return an invalid date. In the following example will be 95
January 31 plus one month:

NewDate = DateAdd ("m", 1, "31-Jan-95")


In this case, DateAdd returns 28 February 1995, not 95 February 31, 2007. If the date is
January 31, 1996, returned February 29, 1996, because 1996 is a leap year.

If the calculation date is before the year AD 100, an error occurs.

If the number is not a Long value, then the calculation before rounding to the nearest integer.

Requirements
Version 2
Returns the time interval between two dates.

DateDiff (interval, date1, date2 [, firstdayofweek [, firstweekofyear]])


DateDiff function syntax has the following parameters:

Parameter
interval
Required. A string expression that is used to calculate the time between date1 and date2
interval. For values, see "Settings" section.
date1, date2
Required. Date expression. Used to calculate the two dates.
Firstdayofweek
Available options. The first day of the week specified constant. If not specified, the default is
Sunday. For values, see "Settings" section.
Firstweekofyear
Available options. The first week of the year specified constant. If not specified, the default is
January 1, where the week. For values, see "Settings" section.
Set up
The interval argument can have the following values:
Setting Description
yyyy Year
q quarter
n months
y number of days a year
d day
w the number of days a week
ww Week
h hours
m minutes
s seconds

firstdayofweek argument can have the following values:

Constant Value Description


vbUseSystemDayOfWeek 0 Use National Language Support (NLS) API setting.
vbSunday 1 Sunday (default)
vbMonday 2 Monday
vbTuesday 3 Tuesday
vbWednesday 4 Wednesday
vbThursday 5 Thursday
vbFriday 6 Friday
vbSaturday 7 Saturday

firstweekofyear parameter can have the following values:

Constant Value Description


vbUseSystem 0 Use National Language Support (NLS) API setting.
vbFirstJan1 1 by the January 1 the week of the beginning (the default).
vbFirstFourDays 2 by the New Year in at least four days in the first week.
vbFirstFullWeek 3 in the new year by the first full week.

Explain
DateDiff function is used to determine between the two dates specified number of time
intervals. For example, you can use the DateDiff calculate the number of days difference
between two dates, or the day of the year the number of weeks between the last day.

To calculate the difference between date1 and date2 number of days, you can use the
"number of days a year" ("y") or "day" ("d"). When the interval is "week days" ("w") when,
DateDiff returns the number of weeks between two dates. If date1 is Monday, DateDiff to
calculate the number of Mondays until date2. This result contains date2 not contain date1. If
the interval is the "week" ("ww"), the DateDiff function returns the calendar the number of
weeks between two dates. Function calculated on Sundays between date1 and date2 number.
If date2 is Sunday, DateDiff to calculate date2, but even if date1 is a Sunday, it will not count
date1.

If date1 is later than date2, the DateDiff function returns a negative number.

firstdayofweek argument will use the "w" and "ww" interval symbols impact.

If date1 or date2 is a date literal, the specified date of the year will become a fixed part.
However, if date1 or date2 is enclosed in quotation marks ("") and is omitted in the year,
calculated in the code each time date1 or date2 expression, it will insert the current year. This
can apply to different years of writing code.

In the interval for the "year" ("yyyy"), the more the coming year, December 31 and January 1,
although in practice only a difference of one day, DateDiff returns 1 for almost a year.

The following example uses the DateDiff function to display today with a given number of days
between the date:

Function DiffADate (theDate)


   DiffADate = "number of days from the day:" & DateDiff ("d", Now, theDate)
End Function
Returns the specified part of the given date.

DatePart (interval, date [, firstdayofweek [, firstweekofyear]])


Arguments
interval
Required. String expression that you want to return time interval. For values, see "Settings"
section.
Date
Required. To calculate the date expression.
firstdayof week
Available options. The first day of the week specified constant. If not specified, the default is
Sunday. For values, see "Settings" section.
Firstweekofyear
Available options. The first week of the year specified constant. If not specified, the default is
January 1, where the week. For values, see "Settings" section.
Set up
The interval argument can have the following values:

Setting Description
yyyy Year
q quarter
m Month
y number of days a year
d day
w the number of days a week
ww Week
h hours
n minutes
s seconds

firstdayofweek argument can have the following values:

Constant Value Description


vbUseSystemDayOfWeek 0 Use National Language Support (NLS) API setting.
vbSunday 1 Sunday (default)
vbMonday 2 Monday
vbTuesday 3 Tuesday
vbWednesday 4 Wednesday
vbThursday 5 Thursday
vbFriday 6 Friday
vbSaturday 7 Saturday

firstweekofyear parameter can have the following values:

Constant Value Description


vbUseSystem 0 Use National Language Support (NLS) API setting.
vbFirstJan1 1 by the January 1 the week of the beginning (the default).
vbFirstFourDays 2 by the New Year in at least four days in the first week.
vbFirstFullWeek 3 in the new year by the first full week (not multi-year) started.

Explain
DatePart function is used to calculate dates and return the specified time interval. For
example, use DatePart to calculate the day of the week or the current time.

firstdayofweek argument affects use "w" and "ww" interval symbols.

If the date is a date literal, the specified date of the year will become a fixed part. However, if
date is enclosed in quotation marks (""), and the year is omitted, then the code each time the
date expression, it will insert the current year. This can apply to different years of writing code.
.

The following example uses the DatePart function to get the date and displays the date where
the season.

Function GetQuarter (TheDate)


   GetQuarter = DatePart ("q", TheDate)
End Function
For the specified year, month, day, returns a Date subtype Variant.

DateSerial (year, month, day)


Arguments
Year
From 100 to 9999 numeric or numeric expression.
Month
Any numeric expression.
Day
Any numeric expression.
Explain
To specify a date, such as the December 31, 1991, DateSerial function in the range of each
parameter should be acceptable; today's value should be between 1 and 31, the value should
be 1 month and 12 between. However, you can use that one day before or after the year,
month, day number of the numeric expression specified for each parameter relative to the
date.

The following example uses numeric expressions instead of absolute date. Here, DateSerial
function returns the August 1, 1990 before the decade (1990 - 10) and two months (8 - 2) day
(1 - 1) the date: the May 31, 1980.

Dim MyDate1, MyDate2


MyDate1 = DateSerial (1970, 1, 1) 'returns January 1, 1970.
MyDate2 = DateSerial (1990 - 10, 8 - 2, 1 - 1) 'returns May 31, 1980.
For the year argument, if the range is from 0 to 99, is interpreted as 1900 to 1999. For this year
outside the parameters, use four-digit year (eg 1800).

When any parameter value outside the acceptable range will be appropriate to carry to the
next larger unit of time. For example, if you specify 35 days, then this is interpreted as the
number of days a month plus the extra days, extra days depending on the year and month.
However, if the argument is outside the range -32,768 to 32,767, or specified by the three
parameters (either directly or through an expression specified) the date falls outside the
acceptable range of dates, an error occurs.

Requirements
Version 1
Return Date subtype Variant.

DateValue (date)
The date argument is a string expression, that 100 years from January 1 to December 31, 9999,
a Japan-date. However, date can also be said that within the scope of the above date, time,
date and time, or any expression.

Explain
If the date argument includes time information, DateValue does not return time information.
However, if date includes invalid time information (such as "89:98"), an error occurs.

If the date is a string that includes only the valid date separator separated, DateValue will be
based on the system short date format specified identification month, day and year order.
DateValue also recognizes that contain month names (either full name or initials) of the
specific date. For example, in addition to recognizing 12/30/1991 and 12/30/91, DateValue
also recognizes December 30, 1991 and Dec 30, 1991.

If the year part of date is omitted, DateValue uses the computer system date in the current
year.

The following example uses the DateValue function to convert a string into a date. You can also
use date literals to directly assign a date Variant variables, such as, MyDate = # 9/11/63 #.

Dim MyDate
MyDate = DateValue ("September 11, 1963") 'return date.
Requirements
Version 1
Return 1 to 31 of an integer (including 1 and 31), on behalf of a mid-day.

Day (date)
Is any expression that can represent a date. If date contains Null, returns Null.

The following example uses the Day function to get a date on a given number of days:

Dim MyDay
MyDay = Day ("October 19, 1962") 'MyDay contains 19.
Requirements
Version 1
The following is a mathematical function derived from the inherent non-intrinsic math
functions:

Function derived from the equivalent formula


Secant (secant) Sec (X) = 1 / Cos (X)
Cosecant (cosecant) Cosec (X) = 1 / Sin (X)
Cotangent (cotangent) Cotan (X) = 1 / Tan (X)
Inverse Sine (Arcsine) Arcsin (X) = Atn (X / Sqr (-X * X + 1))
Inverse Cosine (inverse cosine) Arccos (X) = Atn (-X / Sqr (-X * X + 1)) + 2 * Atn (1)
Inverse Secant (cut anyway) Arcsec (X) = Atn (X / Sqr (X * X - 1)) + Sgn ((X) -1) * (2 * Atn (1))
Inverse Cosecant (anti-cosecant) Arccosec (X) = Atn (X / Sqr (X * X - 1)) + (Sgn (X) - 1) * (2 * Atn
(1))
Inverse Cotangent (anti-cotangent) Arccotan (X) = Atn (X) + 2 * Atn (1)
Hyperbolic Sine (hyperbolic sine) HSin (X) = (Exp (X) - Exp (-X)) / 2
Hyperbolic Cosine (hyperbolic cosine) HCos (X) = (Exp (X) + Exp (-X)) / 2
Hyperbolic Tangent (hyperbolic tangent) HTan (X) = (Exp (X) - Exp (-X)) / (Exp (X) + Exp (-X))
Hyperbolic Secant (hyperbolic secant) HSec (X) = 2 / (Exp (X) + Exp (-X))
Hyperbolic Cosecant (hyperbolic cosecant) HCosec (X) = 2 / (Exp (X) - Exp (-X))
Hyperbolic Cotangent (hyperbolic cotangent) HCotan (X) = (Exp (X) + Exp (-X)) / (Exp (X) - Exp (-
X))
Inverse Hyperbolic Sine (inverse hyperbolic sine) HArcsin (X) = Log (X + Sqr (X * X + 1))
Inverse Hyperbolic Cosine (inverse hyperbolic cosine) HArccos (X) = Log (X + Sqr (X * X - 1))
Inverse Hyperbolic Tangent (inverse hyperbolic tangent) HArctan (X) = Log ((1 + X) / (1 - X)) / 2
Inverse Hyperbolic Secant (inverse hyperbolic secant) HArcsec (X) = Log ((Sqr (-X * X + 1) + 1) /
X)
Inverse Hyperbolic Cosecant (inverse hyperbolic cosecant) HArccosec (X) = Log ((Sgn (X) * Sqr
(X * X + 1) +1) / X)
Inverse Hyperbolic Cotangent (inverse hyperbolic cotangent) HArccotan (X) = Log ((X + 1) / (X -
1)) / 2
To N is the logarithm
Declare variables and allocate storage space.

Dim varname [([subscripts ])][, varname [([subscripts])]]...


Parameter
varname
Name of the variable standard variable naming rules.
subscripts
The dimension of an array variable, you can declare up to 60-dimensional arrays. The
subscripts argument uses the following syntax:
upperbound [, upperbound]...

Lower bound of the array is always 0.

Explain
Dim statement with the Script-level variables can be used to script all of the process,
procedure-level variable can only be used for the process.

Also used the Dim statement with empty parentheses to declare a dynamic array. After
declaring a dynamic array, you can use the ReDim statement within a procedure to define the
dimension of the array and the elements. If you try to redefine in a Dim statement has been
explicitly specified dimension of the array, an error occurs.

Note that in the process, use the Dim statement, usually on the Dim statement at the
beginning of the process.
The following example illustrates how to use the Dim statement:

Dim Names (9) 'Declare an array with 10 elements.


Dim Names () 'declare a dynamic array.
Dim MyVar, MyNum 'declare two variables.
Requirements
Version 1
When the condition is True or until a condition becomes True repeat a statement block.

Do [{While | Until} condition]


[Statements]
[Exit Do]
[Statements]
Loop
You can also use the following syntax:

Do
[Statements]
[Exit Do]
[Statements]
Loop [{While | Until} condition]
Parameter
condition
Numeric or string expression that evaluates to True or False. If condition is Null, condition is
treated as False.
statements
When the condition is True is repeated one or more commands.
Explain
Exit Do can only be used in the Do ... Loop control statements, provide another way to exit the
Do ... Loop. Do ... Loop statement can be in any place to put any number of Exit Do. Exit Do is
usually conditional statement (such as If ... Then) together, followed by passing control to the
statement following the Loop statement.

When used in nested Do ... Loop when, Exit Do transfers control to the loop on the floor in
their nesting cycle.

The following example illustrates how to use the Do ... Loop statement:

Do Until DefResp = vbNo


   MyNum = Int (6 * Rnd + 1) 'between 1 and 6 generated random number.
   DefResp = MsgBox (MyNum & "the number you want another?", VbYesNo)
Loop

Dim Check, Counter


Check = True: Counter = 0 'initialize the variable.
Do 'outer loop.
  Do While Counter <20 'inner circle.
    Counter = Counter + 1 'increment the counter.
    If Counter = 10 Then 'If condition is True ...
      Check = False 'set flag value is set to False.
      Exit Do 'to terminate the inner loop.
    End If
  Loop
Loop Until Check = False 'immediate termination of the outer loop.
Requirements
Version 1
Re-initialize the fixed-size array of elements, and release dynamic array of storage space.

Erase array
The array parameter is an array variable to clear the name.

Explain
Determine the array is an array of fixed length (conventional) or dynamic array is very
important, because according to Erase an array of different types of operations. Erase without
the need for fixed-size array to restore the memory. Erase the following table to set a fixed
array of elements:

Type of the array Erase array elements on the fixed effects


Fixed value to each element array is set to 0.
Fixed array of strings each element is set to zero-length string ("").
Each element of the array object to the special value Nothing.

Erase releases the memory used by dynamic arrays. In the program refer to the dynamic array
again, you must use the ReDim statement to redefine the dimensions of the array variable.

The following example illustrates how to use the Erase statement.

Dim NumArray (9)


Dim DynamicArray ()
ReDim DynamicArray (9) 'allocate storage space.
Erase NumArray 'Each element is reinitialized.
Erase DynamicArray 'release the memory array.
Requirements
Version 1
Eval Function
Calculate the value of an expression and returns the result.

[Result =] Eval (expression)


Parameter
result
Available options. Is a variable, for receiving the returned results. If not specified, the results
should be considered instead of using the Execute statement.
expression
Required. VBScript can contain any valid string expression.
Explain
In VBScript, x = y can be interpreted two ways. The first is an assignment statement, the value
of y given x. The second explanation is that x and y is equal to the test. If equal, result is True;
otherwise result to False. Eval method always uses the second interpretation, the Execute
statement always uses the first.
Note that in Microsoft? JScript? Does not exist in comparison with the assignment of this
confusion, because the assignment operator (=) with a comparison operator (==) is different.
The following example illustrates the usage of the Eval function:

Sub GuessANumber
   Dim Guess, RndNum
   RndNum = Int ((100) * Rnd (1) + 1)
   Guess = CInt (InputBox ("Enter your guess:",, 0))
   Do
      If Eval ("Guess = RndNum") Then
         MsgBox "Congratulations! Guessed it!"
         Exit Sub
      Else
         Guess = CInt (InputBox ("I'm sorry, please try again", 0))
      End If
   Loop Until Guess = 0
End Sub
Perform one or more specified statements.

Execute statements
The required statements parameter is a string expression that contains one or more
statements to execute. If you want the statements parameter contains multiple statements,
you should use a semicolon or embedded in its separate branches.

Explain
In VBScript, x = y can be interpreted two ways. First, as an assignment statement, the value of
y given x. Second, as an expression to test whether the value of x and y are equal. If equal, the
result is True; otherwise, result is False. Execute statement always uses the first interpretation,
whereas the Eval method always uses the second.

Note that in Microsoft? JScript? Does not exist confusion between assignment and
comparison, because the assignment operator (=) with a comparison operator (==) is different.

Call the Execute statement identifies the context can be used to run the object code and
variables. Scope of the objects and variables is the Execute statement can be used to run the
code. However, we must understand is that if the code is executed to create a process, then
the process will not inherit it in the process scope.

And other similar process, new process scope is global, it inherits the global scope of all things.
Different from other processes, it is not the context of global scope, so it can only occur within
the course of the Execute statement executes in the context. However, if the same Execute
statement is outside the process (for example in the global scope) the scope is called, it will
not only inherit everything in global scope, and it can be called anywhere, because its context
is global. The following example illustrates this feature:
Dim X 'in the global scope statement X.
X = "Global" 'to the global X assignment.
Sub Proc1 'declaration process.
   Dim X 'in the local scope statement X.
   X = "Local" 'on the local X-assignment.
            'Execute statement here established a process,
            'In the procedure is called it will print X.
            'It will be a global print X, because Proc2
            'Inherits everything in global scope.
   Execute "Sub Proc2: Print X: End Sub"
   Print Eval ("X") 'Print the local X.
   Proc2 'Proc1 the scope of a call in Proc2.
End Sub
Proc2 'Bank will result in an error because
        'Proc2 outside Proc1 is not in use.
Proc1 'call Proc1.
   Execute "Sub Proc2: Print X: End Sub"
Proc2 'This sentence can be successful, because Proc2
        'It is globally available.
The following example shows how to rewrite the Execute statement, from the whole process
in quotes:

S = "Sub Proc2" & vbCrLf


S = S & "Print X" & vbCrLf
S = S & "End Sub"
Execute S
Requirements
Version 1
Successful implementation of a more global namespace in the script specified in the
statement.

ExecuteGlobal statement
argument is a statement of one or more executable statements containing the string
expression. In the statement parameter can contain multiple statements, use a colon to
separate.

Explain
In VBScript, x = y, there are two interpretation. The first is as an assignment statement assigns
the value of y x. The second method is as an expression to test whether x and y have the same
value. If they are equal, then the result is True; if they are not equal, the result of
False.ExecuteGlobal statement always uses the first method, whereas the Eval method always
uses the second method.

Note that in Microsoft? JScript?, The assignment and comparison, there is no mixing between
the consumer, because the assignment operator (=) is different from the comparison.
In the script's global namespace, ExecuteGlobal all the statements are executable. Therefore,
allow you to add code to the program, so that any process can access it. For example, a
VBScript Class statement at run-time execution. Subsequently function to create a new
instance of this class.

Add in the run-time process and the class is very useful, but may also lead to run-time
coverage in the existing global variables and functions. Because this procedure may lead to
very serious problems, so when using ExecuteGlobal statement must be very cautious. If you
do not have access outside of the process variable or function, it is best to use the Execute
statement, because it only affects the calling function's name space.

The following example illustrates the use of ExecuteGlobal statement.

Dim X 'X is a global variable declaration.


X = "Global" 'to the global variable X assignment.
Sub Proc1 'declaration process.
  Dim X 'in the local variable declaration X.
  X = "Local" 'to the local variable X is assigned.
         'Here's an executable statement
         'Create a process, when called, print X.
         'Here to print a global value of variable X, because Proc2
         'Inherits all the global variables.
  ExecuteGlobal "Sub Proc2: Print X: End Sub"
  Print Eval ("X") 'Print the local X.
  Proc2 'role in the global zone called Proc2
             'Will print "Global".
End Sub
Proc2 'This line causes an error
             'Because Proc2 outside Proc1 is not available.
Proc1 'call Proc1.
  Execute "Sub Proc2: Print X: End Sub"
Proc2 'This line is called success, because Proc2
         'Role in the global zone is available.
The following example demonstrates ExecuteGlobal statement can be rewritten, so you do not
need the whole process of the following are included in the reference tags.

S = "Sub Proc2" & vbCrLf


S = S & "Print X" & vbCrLf
S = S & "End Sub"
ExecuteGlobal S
Requirements
Version 1
Exit Do ... Loop, For ... Next, Function, or Sub code block.

Exit Do
Exit For
Exit Function
Exit Property
Exit Sub
Exit statement syntax has the following form:

Statement describes the


Exit Do Exit Do ... Loop provides a statement of the method. Only in the Do ... Loop statements.
Exit Do transfers control to the statement following the Loop statement. In the nested Do ...
Loop statement, when used, Exit Do transfers control to the loop on the location of a layer of
nested loops.
Exit For providing a way to exit a For loop. Only in the For ... Next or For Each ... Next loop. Exit
For transfers control to the statement following Next. For the nested loop used, Exit For
transfers control to the loop on the location of a layer of nested loops.
Exit Function immediately withdraw from the occurrence of the Function procedure. Continue
to call the Function of the statement following the statement.
Exit Property where the Property immediately from the process to exit. Continue with the
following statement that called the Property procedure.
Exit Sub immediately withdraw from the occurrence of the Sub procedure, continue to call the
Sub statement following the statement.

The following example illustrates how to use the Exit statement:

Sub RandomLoop
   Dim I, MyNum
   Do 'to set loop.
      For I = 1 To 1000 '1000 cycles.
         MyNum = Int (Rnd * 100) 'generate random numbers.
         Select Case MyNum 'find the value of random numbers.
            Case 17: MsgBox "Case 17"
              Exit For 'If it is 17, out of For ... Next.
            Case 29: MsgBox "Case 29"
              Exit Do 'If it is 29, out of Do ... Loop.
            Case 54: MsgBox "Case 54"
              Exit Sub 'If it is 54, out of a Sub procedure.
         End Select
      Next
   Loop
End Sub
Requirements
Version 1
Exp function
Returns e (natural logarithms) powers of two.

Exp (number)
The number argument can be any valid numeric expression.

Explain
If number is more than 709.782712893, an error occurs. The constant e is approximately
2.718282.

Note The Exp function to complete the anti-Log function operation, and sometimes referred to
as opposed to the number of forms.
The following example uses the Exp function returns e to a power:

Dim MyAngle, MyHSin 'definition of angle in radians.


MyAngle = 1.3 'calculation of hyperbolic sine.
MyHSin = (Exp (MyAngle) - Exp (-1 * MyAngle)) / 2
Return subscript zero-based array, which contains a specific filter string based on a subset of
the array.

Filter (InputStrings, Value [, Include [, Compare]])


Parameter
InputStrings
Required. One-dimensional array, in which the search string.
Value
Required. String to search.
Include
Available options. Boolean value that specifies whether to return substrings that include Value.
If Include is True, Filter returns an array containing substrings Value subset. If Include is False,
Filter returns the substring Value does not contain a subset of the array.
Compare
Available options. Numeric value that type of string comparison to use. Please refer to the
value part.
Set up
Compare argument can have the following values:

Constant Value Description


vbBinaryCompare 0 Perform a binary comparison.
vbTextCompare 1 Performs a textual comparison.

Explain
If not found within InputStrings match with the value of Value, Filter returns an empty array. If
InputStrings is Null or is not a one-dimensional array, an error occurs.

The array returned by the Filter function contains only enough to match the number of
elements included.

The following example uses the Filter function returns containing the search terms "Mon"
array:
Dim MyIndex
Dim MyArray (3)
MyArray (0) = "Sunday"
MyArray (1) = "Monday"
MyArray (2) = "Tuesday"
MyIndex = Filter (MyArray, "Mon") 'MyIndex (0) contains "Monday".
Requirements
Version 2
Returns the integer part.

Int (number)
Fix (number)
The number argument can be any valid numeric expression. If number contains Null, returns
Null.

Explain
Int and Fix remove the fractional part of the number argument and returns an integer result.

The difference between Int and Fix is that if the number parameter is negative, Int returns the
first number is less than or equal to a negative integer, and Fix function returns the number is
greater than or equal to the first negative integer parameters. For example, Int converts -8.4 to
-9, and Fix converts -8.4 to -8 function.

Fix (number) is equivalent to:

Sgn (number) * Int (Abs (number))


The following example illustrates how the Int and Fix functions return integer portions of
numbers:

MyNumber = Int (99.8) 'Return 99.


MyNumber = Fix (99.2) 'Return 99.
MyNumber = Int (-99.8) 'returns -100.
MyNumber = Fix (-99.8) 'return -99.
MyNumber = Int (-99.2) 'returns -100.
MyNumber = Fix (-99.2) 'return -99.
Requirements
Version 1
The array or collection each element a group of statements repeatedly.

For Each element In group


[Statements]
[Exit For]
[Statements]
Next [element]
Parameter
element
Used to enumerate all the elements of the collection or array variables. For the collection,
element may be a Variant variable, a generic Object variable or any of the specified
Automation object variable. For arrays, element can only be a Variant variable.
group
Object collection or array name.
statements
For each group in an implementation of one or more statements.
Explain
If the group has at least one element, it will enter the For Each block is executed. Once in
circulation, will be the first element of the first group all the statements in the loop. As long as
there are other elements in the group, will perform on each element of statements in the loop.
When the group is no other element in the loop is exited, then the statement following the
Next statement continues.

Exit For can only be used For Each ... Next or For ... Next control structure to provide an
alternate way to exit the method. Can be placed anywhere in the loop any number of Exit For
statement. Exit For is often used with conditional statements (such as If ... Then), and
immediately transfers control to the statement following Next.

Can be a For Each ... Next loop placed within another form nested For Each ... Next loop.
However, each loop element must be unique.

Note If you omit the Next statement element, the program will still be the same as it has been
included to continue. If the Next statement before its corresponding For statement appears,
an error occurs.
The following example illustrates how to use the For Each ... Next statement:

Function ShowFolderList (folderspec)


   Dim fso, f, f1, fc, s
   Set fso = CreateObject ("Scripting.FileSystemObject")
   Set f = fso.GetFolder (folderspec)
   Set fc = f.Files
   For Each f1 in fc
      s = s & f1.name
      s = s & "<BR>"
   Next
  ShowFolderList = s
End Function
Requirements
Version 2
To specify the number of times a group of statements repeatedly.

For counter = start To end [Step step]


[Statements]
[Exit For]
[Statements]
Next
Parameter
counter
Used as the value of loop counter variable. This variable can not be array elements or user-
defined types of elements.
start
counter initial value.
end
The final counter value.
step
the step counter. If not specified, step defaults to 1.
statements
Between For and Next that one or more statements are executed the specified number of
times.
Explain
step argument can be positive or negative. the value of the step argument determines loop
implementation, as follows:

Value of the loop if ...


Positive number or 0 counter <= end
Negative counter> = end

When the loop starts and all statements in the loop are executed, step value is added to the
counter in. At this time, or statements in the loop execute again (based on the loop starts
executing the same test), or exit the loop and the statement following the statement from
Next to continue.

Note that changes in the body of the loop counter value, the program code will make it more
difficult to read and debug.
Exit For can only be used For Each ... Next or For ... Next structure to provide an alternate way
to exit the method. In the statement can be placed anywhere in any number of Exit For
statement. Exit For is often used with conditional statements (such as If ... Then), and
immediately transfers control to the statement following Next.

You can put a For ... Next loop within another For ... Next loop, composed of nested loops.
Each cycle counter to use a different variable name. The following construction is correct:

For I = 1 To 10
      For J = 1 To 10
            For K = 1 To 10
            ...
            Next
      Next
Next
Requirements
Version 1
Returns an expression formatted as a currency value (defined using the system control panel
currency symbol).

FormatCurrency (
   expression [, NumDigitsAfterDecimal [, IncludeLeadingDigit [, UseParensForNegativeNumbers
[, GroupDigits]]]]
)
Parameter
Expression
Required. Expression to be formatted.
NumDigitsAfterDecimal
Available options. Instructions displayed right of the decimal digit value. The default value is -1,
which indicates that the computer's regional settings.
IncludeLeadingDigit
Available options. Tristate constant that indicates whether to display fractional values of zero.
For values, see "Settings" section.
UseParensForNegativeNumbers
Available options. Tristate constant that indicates whether the negative values within
parentheses. For values, see "Settings" section.
GroupDigits
Available options. Tristate constant that indicates whether to use the computer's regional
settings digit grouping symbol specified in the digital group. For values, see "Settings" section.
Set up
IncludeLeadingDigit, UseParensForNegativeNumbers and GroupDigits parameter can have the
following values:

Constant Value Description


TristateTrue -1 True
TristateFalse 0 False
TristateUseDefault -2 using the computer's regional settings in the settings.

Explain
When you omit one or more optional parameters, provided by the computer's regional
settings are omitted parameter. Monetary value associated with the currency symbol position
by the system's regional settings.

Note that in addition to "Display the start of the zero" to set the locale from the "number" tab,
all other settings information comes from the locale of the "currency" tab.
The following example uses FormatCurrency function to expression formatted as a currency
and assigned to MyCurrency:
Dim MyCurrency
MyCurrency = FormatCurrency (1000) 'MyCurrency contains $ 1000.00.
Requirements
Version 2

Returns an expression formatted as a date or time.

FormatDateTime (Date [, NamedFormat])


Parameter
Date
Required. Date expression to be formatted.
NamedFormat
Available options. That indicates the date / time format value, if omitted, the vbGeneralDate.
Set up
NamedFormat parameter can have the following values:

Constant Value Description


vbGeneralDate 0 shows the date and / or time. If there is a date part, the part is shown as the
short date format. If you have time part, the part is shown as a long format. If there is, it shows
all the parts.
vbLongDate 1 computer regional settings in the long date format specified date.
vbShortDate 2 using the computer's regional settings in the short date format specified date.
vbLongTime 3 using the computer's regional settings time format specified time.
vbShortTime 4 24-hour format (hh: mm) display the time.

Explain
The following example uses the FormatDateTime function to an expression formatted as long
date and assign it to type MyDateTime:

Function GetCurrentDate
   'FormatDateTime the date type format for long dates.
   GetCurrentDate = FormatDateTime (Date, 1)
End Function
Requirements
Version 2
Returns an expression formatted as a value.

FormatNumber (
   expression [, NumDigitsAfterDecimal [, IncludeLeadingDigit [, UseParensForNegativeNumbers
[, GroupDigits]]]]
)
Arguments
Expression
Required. Expression to be formatted.
NumDigitsAfterDecimal
Available options. Instructions displayed right of the decimal digit value. The default value is -1,
which indicates that the computer's regional settings.
IncludeLeadingDigit
Available options. Tristate constant that indicates whether to display fractional values of zero.
For values, see "Settings" section.
UseParensForNegativeNumbers
Available options. Tristate constant that indicates whether the negative values within
parentheses. For values, see "Settings" section.
GroupDigits
Available options. Tristate constant that indicates whether to use the computer's regional
settings digit grouping symbol specified in the digital group. For values, see "Settings" section.
Set up
IncludeLeadingDigit, UseParensForNegativeNumbers and GroupDigits parameter can have the
following values:

Constant Value Description


TristateTrue -1 True
TristateFalse 0 False
TristateUseDefault -2 using the computer's regional settings in the settings.

Explain
When you omit one or more optional parameters, provided by the computer's regional
settings are omitted parameter.

Note All settings information comes from the locale of the "digital" tab.
The following example uses the FormatNumber function to format the value with four decimal
point:

Function FormatNumberDemo
   Dim MyAngle, MySecant, MyNumber
   MyAngle = 1.3 'definition of angle in radians.
   MySecant = 1 / Cos (MyAngle) 'calculate the secant value.
   FormatNumberDemo = FormatNumber (MySecant, 4) 'to MySecant formatted with four
decimal point.
End Function
Requirements
Version 2
Returns an expression formatted as a% symbol is followed by a percentage (multiplied by 100).

FormatPercent (expression [, NumDigitsAfterDecimal [, IncludeLeadingDigit [,


UseParensForNegativeNumbers [, GroupDigits ]]]])
FormatPercent function syntax has the following parameters:

Parameter
Expression
Required. Expression to be formatted.
NumDigitsAfterDecimal
Available options. Instructions displayed right of the decimal digit value. The default value is -1,
which indicates that the computer's regional settings.
IncludeLeadingDigit
Available options. Tristate constant that indicates whether to display fractional values of zero.
For values, see "Settings" section.
UseParensForNegativeNumbers
Available options. Tristate constant that indicates whether the negative values within
parentheses. For values, see "Settings" section.
GroupDigits
Available options. Tristate constant that indicates whether to use the computer's regional
settings digit grouping symbol specified in the digital group. For values, see "Settings" section.
Set up
IncludeLeadingDigit, UseParensForNegativeNumbers and GroupDigits parameter can have the
following values:

Constant Value Description


TristateTrue -1 True
TristateFalse 0 False
TristateUseDefault -2 using the computer's regional settings in the settings.

Explain
When you omit one or more optional parameters, provided by the computer's regional
settings are omitted parameter.

Note All settings information comes from the locale of the "digital" tab.
The following example uses FormatPercent function to format the expression as a percentage:

Dim MyPercent
MyPercent = FormatPercent (2 / 32) 'MyPercent contains 6.25%.
Requirements
Version 2

Statement Function procedure name, parameters, and form the body of the code.

 [Public [Default] | Private] Function name [(


   arglist
)]
[Statements]
[Name = expression]
[Exit Function]
[Statements]
[Name = expression]
End Function
Parameter
Public
Function procedure can be that all the scripts access to all other procedures.
Default
Only with the Public keyword in a Class block used to represent the class Function procedure is
the default method. If a class is more than one Default procedure is specified, there is an error.

Private
Function procedure that it can only be declared in the script or other process to access data if
the function is a class, then the class Function procedure can only be accessed in the other
process.
name
Function names follow the standard variable naming rules.
arglist
Behalf of the calling process when the parameter passed to the Function list of variables.
Multiple variables separated by commas.
statements
In the Function procedure to execute any of the main group of statements.
expression
Function return value.
arglist argument has the following syntax and parts:

[ByVal | ByRef] varname [()]

Parameter
ByVal
Indicates that the parameter is passed by value mode.
ByRef
Indicates that the argument passed by reference.
varname
The name of the variable representing the argument; follows standard variable naming rules.
Explain
If not explicitly specified using either Public or Private, Function procedures are public by
default, that is, they script all of the other processes is visible. Function values of local variables
in the call in process is not preserved.

Not in any other process (for example, Sub, or Property Get) Function procedure is defined.

Use Exit Function statement can immediately withdraw from the Function procedure. Program
execution continues with the process that called the Function statement following the
statement. Function procedure can appear anywhere in any number of Exit Function
statements.

Similar to a Sub procedure, Function procedure can take arguments, perform a series of
statements and change the parameter values of the independent process. And the difference
between a Sub procedure is: when to use the value returned by the function, you can use the
expression on the right Function procedure, which is used as the internal functions, such as
Sqr, Cos, or Chr.

In the expression, you can use the function name, and then the corresponding parameters are
given in parentheses, the list to call Function procedures. For more information call a Function
procedure, see the Call statement.

Warning Function procedure can be recursive, that is, the process can call their own to
complete a given task. However, recursion can lead to stack overflow.
From the function returns a value, simply assign a value to the function name. Anywhere in the
process can be of arbitrary assignment like this. If no name assigned, then the process will
return a default value: the value the function returns 0, the string function returns a zero-
length string (""). If there are no objects in the Function reference is assigned to name (using
Set), then the function returns an object reference returns Nothing.

The following example shows how to assign a function named BinarySearch return value. In
this sample, False is assigned to the function name, that did not find a certain value.

Function BinarySearch (...)


      ...
      'This value is not found. Return value of False.
      If lower> upper Then
          BinarySearch = False
          Exit Function
      End If
      ...
End Function
Function used in the process variable is divided into two categories: one is in the process that
are explicitly declared, and the other is not. In the process variables are explicitly declared
(using Dim or the equivalent) is always the process of local variables. Used but not in the
process variable is explicitly declared local variables, unless a higher level outside the
procedure are explicitly declare them.

Warning procedure can use in the process variables are explicitly declared, but as long as there
is no script-level name defined with the same name, will have a name conflict. If the process
referenced undeclared variables and other processes, constant or variable with the same
name, it is assumed that the process is referenced in the script-level name. To avoid such
conflicts, use the Option Explicit statement to force explicit declaration of variables.
Warning VBScript may rearrange arithmetic expressions to increase internal efficiency. When
the Function procedure to modify the value of a variable mathematical expressions should be
avoided in the same expression to use this function.
Requirements
Version 1
Returns the current locale ID value.

GetLocale ()
Explain
User locale is a collection of reference information, and user's language, country / region and
cultural tradition. locale determine the keyboard layout, alphabetic sort order and the date,
time, number and currency formats.

Return value can be any 32 - bit values, such as Locale ID below:

The following are examples GetLocale function usage. To use this code, copy the standard
HTML file, everything between <BODY> signs.

Enter Date in UK format: <input type="text" id="UKDate" size="20"> <p>


Here's the US equivalent: <input type="text" id="USdate" size="20"> <p>
<input type="button" value="Convert" id="button1"> <p>
Enter a price in German: <input type="text" id="GermanNumber" size="20">
<p>
Here's the UK equivalent: <input type="text" id="USNumber" size="20"> <p>
<input type="button" value="Convert" id="button2"> <p>

<script language="vbscript">
Dim currentLocale
'Get the current locale
currentLocale = GetLocale

Sub Button1_onclick
  Dim original
  original = SetLocale ("en-gb")
  mydate = CDate (UKDate.value)
  'IE has always been the locale is set to "U.S. English",
  'So please use currentLocale variable locale is set to "U.S. English."
  original = SetLocale (currentLocale)
  USDate.value = FormatDateTime (mydate, vbShortDate)
End Sub

Sub button2_onclick
  Dim original
  original = SetLocale ("de")
  myvalue = CCur (GermanNumber.value)
  original = SetLocale ("en-gb")
  USNumber.value = FormatCurrency (myvalue)
End Sub

</ Script>
Return to the file reference to an Automation object.

GetObject ([pathname] [, class])


Parameter
Pathname
Available options. A string that contains the object to retrieve the full path and file name. If
you omit the pathname must have class.
Class
Available options. String, the object's class.
class parameter syntax is appname.objectype, which includes the following components:

Parameter
appname
Required. String name of the application providing the object.
objectype
Required. String, to create the object type or class.
Explain
Use the GetObject function to access files in the Automation object, and the object can be
assigned to an object variable. Use the Set statement to assign the object returned by
GetObject to the object variable. For example:

Dim CADObject
Set CADObject = GetObject ("C: \ CAD \ SCHEMA.CAD")
In the implementation of the code, it will start with the specified path name associated
applications, while the objects in the specified file is activated. If pathname is a zero-length
string (""), GetObject returns a new object instance of the specified type. If the pathname
argument is omitted, GetObject returns a currently active object of the specified type. If you
do not specify the type of object, an error occurs.

Some applications allow you to activate only part of the file, the file name is added after an
exclamation point (!) And used to identify the files you want to activate part of the string. For
more information on creating this string, see the application object is created the
documentation.

For example, in a drawing application, a map stored in the file may have multiple layers. You
can use the following code to activate a layer in Figure SCHEMA.CAD:

Set LayerObject = GetObject ("C: \ CAD \ SCHEMA.CAD! Layer3")


If you do not specify the object's class, Automation will be provided according to the file name
to determine the application to start and to activate the object. However, some files may
support multiple object classes. For example, the figure might support three different types of
objects: Application Objects, Drawing Object, and a Toolbar object, all of which are part of the
same file. Use the class option parameter to specify the file you want to activate the object.
For example:
Dim MyObject
Set MyObject = GetObject ("C: \ DRAWINGS \ SAMPLE.DRW", "FIGMENT.DRAWING")
In the above example, FIGMENT is the name of a drawing application, and DRAWING is one of
the object types it supports. Object is activated, you can use the code defined in the object
variable to reference it. In the previous example, you can use the object variable MyObject
access the new object's properties and methods. For example:

MyObject.Line 9, 90
MyObject.InsertText 9, 100, "Hi, hello!"
MyObject.SaveAs "C: \ DRAWINGS \ SAMPLE.DRW"
Note that there is a current instance of the object, or use the loaded object file is created, use
the GetObject function. If there is no current instance, and not ready to start using the object
file has been loaded, use the CreateObject function.
If the object has been registered as a single instance of the object, no matter how many times
the implementation of CreateObject, can only create an instance of the object. If you use a
single instance of the object, when using zero-length string ("") syntax called, GetObject always
returns the same instance, and if the pathname argument is omitted, an error occurs.

Requirements
Version 5

GetRef returns a pointer to a reference process, this process can be bound to an event.

Set object.eventname = GetRef (procname)


Parameter
object
Required. Events associated with the name of the object.
eventname
Required. Bind with the function name of the event.
procname
Required. The string contains the name of the Sub or Function procedure, the process
associated with the event.
Explain
GetRef function can be used to VBScript procedure (Function or Sub) and DHTML (Dynamic
HTML) pages that are available in any event together. DHTML object model provides objects
for different events with a variety of available information.

Scripting and programming in other languages, GetRef provided function is called function
pointer, that is, it points to the specified event occurs when the address of a procedure to be
performed.

The following example illustrates the use of the function GetRef:

<SCRIPT LANGUAGE="VBScript">
Function GetRefTest ()
   Dim Splash
   Splash = "GetRefTest Version 1.0" & vbCrLf
   Splash = Splash & Chr (169) & "YourCompany 1999"
   MsgBox Splash
End Function

Set Window.Onload = GetRef ("GetRefTest")


</ SCRIPT>
Requirements
Version 5

Returns the value of the string of hexadecimal digits.

Hex (number)
The number argument is any valid expression.

Explain
If number is not an integer, before being evaluated to rounding to the nearest integer.

If the number is Hex returns


Null Null.
Empty zero (0).

You can add a prefix in front of the number & H to represent a hexadecimal number. For
example, in hexadecimal notation, & H10 represents decimal number 16.

The following example uses the Hex function to return a hexadecimal number:

Dim MyHex
MyHex = Hex (5) 'returned 5.
MyHex = Hex (10) 'Return A.
MyHex = Hex (459) 'returned 1CB.
Requirements
Version 1
Returns a 0 to 23 integer (including 0 and 23), on behalf of one hour of the day.

Hour (time)
The time argument is any expression that can represent a time. If time contains Null, returns
Null.

The following example uses the Hour function to obtain the current time of the hour:

Dim MyTime, MyHour


MyTime = Now
MyHour = Hour (MyTime) 'MyHour contains
                        'Value representing the current time.
Requirements
Version 1
According to the value of expression a group of statements conditionally.

If condition Then statements [Else elsestatements]


Or, use the block form syntax:

If condition Then
[Statements]
[ElseIf condition-n Then
[Elseifstatements]]...
[Else
[Elsestatements]]
End If
Parameter
condition
One or more of the following two types of expressions:
Numeric or string expression that the result is True or False. If condition is Null, then the
condition is treated as False.

If TypeOf objectname Is objecttype form of expression. The objectname is any object reference
and objecttype is any valid object type. If specified by objecttype objectname is an object type,
the expression is True; otherwise False.

If the condition is True, the implementation of one or more (separated by colons) statement.
condition-n
The same condition.
elseifstatements
If the associated condition-n is True, the implementation of one or more statements.
elsestatements

Explain
Requirements
Version 1

Parameter

Default

Explain

Requirements
Version 1

Parameter
start
Available options.

Required.

Required.
Available options. For values, see "Settings" section.
Set up

Constant Value Description


vbBinaryCompare 0 Perform a binary comparison.
vbTextCompare 1 Performs a textual comparison.

Explain

Requirements
Version 1

Parameter

Required.

Required.

Available options.
Available options. For values, see "Settings" section.
Set up

vbBinaryCompare 0 Perform a binary comparison.

Explain

Requirements
Version 2

Returns the integer part.

Int (number)
Fix (number)
The number argument can be any valid numeric expression. If number contains Null, returns
Null.

Explain
Int and Fix remove the fractional part of the number argument and returns an integer result.

The difference between Int and Fix is that if the number parameter is negative, Int returns the
first number is less than or equal to a negative integer, and Fix function returns the number is
greater than or equal to the first negative integer parameters. For example, Int converts -8.4 to
-9, and Fix converts -8.4 to -8 function.

Fix (number) is equivalent to:

Sgn (number) * Int (Abs (number))


The following example illustrates how the Int and Fix functions return integer portions of
numbers:

MyNumber = Int (99.8) 'Return 99.


MyNumber = Fix (99.2) 'Return 99.
MyNumber = Int (-99.8) 'returns -100.
MyNumber = Fix (-99.8) 'return -99.
MyNumber = Int (-99.2) 'returns -100.
MyNumber = Fix (-99.2) 'return -99.
Requirements
Version 1

Explain

MyArray (0) = "Sunday"


MyArray (1) = "Monday"
MyArray (2) = "Tuesday"

Requirements
Version 1

Explain
Requirements
Version 1

Explain

Requirements
Version 1

Explain
Requirements
Version 1

Explain

Requirements
Version 1

Explain

Requirements
Version 1

Parameter

Required.
Available options.
Explain

Requirements
Version 2

Parameter

Explain

Requirements
Version 1

string argument is any valid string expression.

Explain

Requirements
Version 1
Parameter

Explain

Requirements
Version 1

Parameter

Explain

Requirements
Version 1

Explain
Explain
The constant e is approximately 2.718282.

   
End Function

string argument is any valid string expression.

Explain

Requirements
Version 1

Explain
The constant e is approximately 2.718282.

   
End Function
Requirements
Version 1

Parameter

Explain

Requirements
Version 1

The time argument is any expression that can represent a time.

Explain

Requirements
Version 1

If date contains Null, returns Null.

Explain
                   
Requirements
Version 1

Parameter

Required.

Available options.
Explain

Requirements
Version 2

Parameter

For values, see "Settings" section.

Set up

Constant Value Description


Explain

   
Requirements
Version 1

Explain

Requirements
Version 1

The number argument is any valid expression.

Explain

Null Null.
Empty zero (0).

Requirements
Version 1

Explain
Requirements
Version 1

Explain

Requirements
Version 1

Parameter
varname

subscripts
The dimension of an array variable, you can declare up to 60-dimensional arrays.

Explain

   
Requirements
Version 1

 
    [Statements]
    
    
    [Statements]
    

Parameter
Public

Default

Private

name

arglist

statements

expression

Explain

Requirements
Version 5

 
   
)
    
    
    

Parameter
Public

Private

name

arglist

Explain

Requirements
Version 5

 
   
)
    
    
    

Parameter
Public

Private

name

arglist
Explain

Requirements
Version 5

Parameter
varname

subscripts

Explain

After declaring a dynamic array, you can use the ReDim statement within a procedure to
define the dimension of the array and the elements.

   

Requirements
Version 1
Explain

   
   
   
Loop
Requirements
Version 1

Parameter

varname

subscripts

Explain

...
Requirements
Version 1

Or

Explain

Requirements
Version 1

Parameter
expression
Required.

Required.

Required.

Available options.

Available options.
Compare
Available options. For values, see "Settings" section.
Set up

Constant Value Description


vbBinaryCompare 0 Perform a binary comparison.
vbTextCompare 1 Performs a textual comparison.

Explain

Requirements
Version 2

Parameter

Required.

Required.

Required.
Explain

   
End Function
Requirements

Parameter

Explain

Requirements
Version 2

The number argument can be any valid numeric expression.

Explain
Parameter
Expression
Required.

Available options.
Explain

Requirements
Version 2

string argument is any valid string expression.

Explain

Requirements
Version 1
Explain

   
   
   
   
   
   
   
End Function
Requirements
Version 2

Explain

   
   
   
   
   
   
   
End Function
Requirements
Version 2

Explain

   
   
   
   
   
   
   
End Function
Requirements
Version 2

Explain

   
   
   
   
   
   
   
End Function
Requirements
Version 2

The time argument is any expression that can represent a time. If time contains Null, returns
Null.

Explain

   
Requirements
Version 2
End Select
Parameter

Explain

   
   
      
      
      
      
   End Select
End Sub
Requirements
Version 1

Set object.eventname = GetRef (procname)


Parameter
Available options.
object
Required.

Required.
procname
Required.
Explain

   
   Set fso = CreateObject ("Scripting.FileSystemObject")
   
   
   
   
   
   
End Function

Requirements
Version 1

Explain
To use this code, copy the standard HTML file, everything between <BODY> signs.

Enter Date in UK format: <input type="text" id="UKDate" size="20"> <p>


Here's the US equivalent: <input type="text" id="USdate" size="20"> <p>
<input type="button" value="Convert" id="button1"> <p>
Enter a price in German: <input type="text" id="GermanNumber" size="20">
<p>
Here's the UK equivalent: <input type="text" id="USNumber" size="20"> <p>
<input type="button" value="Convert" id="button2"> <p>

<script language="vbscript">
Dim currentLocale
'Get the current locale
currentLocale = GetLocale

Sub Button1_onclick
  Dim original
  original = SetLocale ("en-gb")
  mydate = CDate (UKDate.value)
  'IE has always been the locale is set to "U.S. English",
  'So please use currentLocale variable locale is set to "U.S. English."
  original = SetLocale (currentLocale)
  USDate.value = FormatDateTime (mydate, vbShortDate)
End Sub

Sub button2_onclick
  Dim original
  original = SetLocale ("de")
  myvalue = CCur (GermanNumber.value)
  original = SetLocale ("en-gb")
  USNumber.value = FormatCurrency (myvalue)
End Sub

</ Script>

The number argument can be any valid numeric expression.


Explain

The number argument can be any angle in radians to a valid numeric expression.

Explain

Explain

Requirements
Version 1
Parameter
expression
Required.

Available options.

Available options.
Compare
Available options. For values, see "Settings" section.
Set up

Constant Value Description


vbBinaryCompare 0 Perform a binary comparison.
vbTextCompare 1 Performs a textual comparison.

Explain

Requirements
Version 2

Explain
Parameter

Required.

Required.
Compare
Available options. For values, see "Settings" section.
Set up

Constant Value Description


vbBinaryCompare 0 Perform a binary comparison.
vbTextCompare 1 Performs a textual comparison.

Explain

Requirements
Version 1

Parameter
number
If number contains Null, returns Null.

Explain
Requirements
Version 1

   [Statements]
   
   [Statements]
End Sub
Parameter
Public

Default

Private

name

arglist
Multiple variables separated by commas.
statements

arglist argument has the following syntax and parts:

[ByVal | ByRef] varname [()]


Parameter
ByVal

ByRef

varname

Explain
Warning procedure can use in the process variables are explicitly declared, but as long as there
is no script-level name defined with the same name, will have a name conflict. If the process
referenced undeclared variables and other processes, constant or variable with the same
name, it is assumed that the process is referenced in the script-level name. To avoid such
conflicts, use the Option Explicit statement to force explicit declaration of variables.
Requirements
Version 1

The number argument can be any angle in radians to a valid numeric expression.

Explain

Explain

Requirements
Version 1
Explain

   
   
   
   Next
   
   
End Function
Requirements
Version 5

Parameter

Any numeric expression.

Any numeric expression.


Explain

Requirements
Version 1

Explain
Requirements
Version 1

string argument is any valid string expression.

Explain

Requirements
Version 1
Explain

Requirements
Version 2

Parameter

Required.

Available options.
Explain

Requirements
Version 1

string argument is any valid string expression.

Explain
Requirements
Version 1

Constant Value Description

Explain

Requirements
Version 1
Do
Date
Space

Parameter
date
If date contains Null, returns Null.
Firstdayofweek
The first day of the week specified constant.
Set up

Constant Value Description


vbUseSystemDayOfWeek 0 Use National Language Support (NLS) API setting.

vbMonday 2 Monday
vbTuesday 3 Tuesday
vbWednesday 4 Wednesday
vbThursday 5 Thursday
vbFriday 6 Friday
vbSaturday 7 Saturday
Constant Value Description

vbMonday 2 Monday
vbTuesday 3 Tuesday
vbWednesday 4 Wednesday
vbThursday 5 Thursday
vbFriday 6 Friday
vbSaturday 7 Saturday

Explain

Requirements
Version 1

Parameter

Required.

Available options.
Firstdayofweek
Available options.
Set up

Constant Value Description


vbUseSystemDayOfWeek 0 Use National Language Support (NLS) API setting.
vbSunday 1 Sunday (default)
vbMonday 2 Monday
vbTuesday 3 Tuesday
vbWednesday 4 Wednesday
vbThursday 5 Thursday
vbFriday 6 Friday
vbSaturday 7 Saturday

Explain
Dim MyDate

Requirements
Version 2

Please refer to the

Parameter
condition
If condition is Null, condition is treated as False.
statements

Explain

   Counter = Counter + 1 'increment the counter.


   

Requirements
Version 1

    statements

Parameter
object

statements

Explain
   
   
   

Requirements
Version 1

If date contains Null, returns Null.

Explain

You might also like