Professional Documents
Culture Documents
Abs Function
Abs Function
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
Atn (number)
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.
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.
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.
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:
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:
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 #).
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.
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:
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.
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:
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.
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:
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.
The following example uses the CSng function to convert the value Single:
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.
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:
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.
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
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:
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
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.
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.
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.
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:
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:
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:
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:
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.
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:
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.
Exit Do
Exit For
Exit Function
Exit Property
Exit Sub
Exit statement syntax has the following form:
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:
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:
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:
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:
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
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:
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).
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:
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.
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.
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.
The following are examples GetLocale function usage. To use this code, copy the standard
HTML file, everything between <BODY> signs.
<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.
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:
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.
<SCRIPT LANGUAGE="VBScript">
Function GetRefTest ()
Dim Splash
Splash = "GetRefTest Version 1.0" & vbCrLf
Splash = Splash & Chr (169) & "YourCompany 1999"
MsgBox Splash
End Function
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.
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:
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.
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.
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:
Returns a string in another string, counting from the emergence from the end position.
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:
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.
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:
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:
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:
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:
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 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.
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.
The following example uses the Left function to return MyString left three letters:
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 (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:
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:
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.
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:
Return value
The MsgBox function returns the following values:
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.
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.
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.
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:
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:
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:
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.
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.
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
Requirements
Version 2
Parameter
Required.
Required.
Required.
Explain
End Function
Requirements
Parameter
Explain
Requirements
Version 2
Explain
Parameter
Expression
Required.
Available options.
Explain
Requirements
Version 2
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
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.
<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>
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
Explain
Requirements
Version 2
Explain
Parameter
Required.
Required.
Compare
Available options. For values, see "Settings" section.
Set up
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
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
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
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
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
Explain
Dim MyDate
Requirements
Version 2
Parameter
condition
If condition is Null, condition is treated as False.
statements
Explain
Requirements
Version 1
statements
Parameter
object
statements
Explain
Requirements
Version 1
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
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.
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.
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.
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:
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:
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 #).
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.
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:
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:
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:
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:
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:
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.
The following example uses the CSng function to convert the value Single:
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.
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:
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.
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
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:
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
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.
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.
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.
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:
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:
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:
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:
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.
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:
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.
Exit Do
Exit For
Exit Function
Exit Property
Exit Sub
Exit statement syntax has the following form:
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:
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.
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:
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:
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
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:
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).
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:
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.
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:
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.
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.
The following are examples GetLocale function usage. To use this code, copy the standard
HTML file, everything between <BODY> signs.
<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.
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:
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.
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.
<SCRIPT LANGUAGE="VBScript">
Function GetRefTest ()
Dim Splash
Splash = "GetRefTest Version 1.0" & vbCrLf
Splash = Splash & Chr (169) & "YourCompany 1999"
MsgBox Splash
End Function
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.
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:
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
Explain
Requirements
Version 1
Parameter
Required.
Required.
Available options.
Available options. For values, see "Settings" section.
Set up
Explain
Requirements
Version 2
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.
Explain
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
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
Explain
Requirements
Version 1
Explain
The constant e is approximately 2.718282.
End Function
Requirements
Version 1
Parameter
Explain
Requirements
Version 1
Explain
Requirements
Version 1
Explain
Requirements
Version 1
Parameter
Required.
Available options.
Explain
Requirements
Version 2
Parameter
Set up
Requirements
Version 1
Explain
Requirements
Version 1
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
Explain
Requirements
Version 2
Parameter
Required.
Required.
Required.
Explain
End Function
Requirements
Parameter
Explain
Requirements
Version 2
Explain
Parameter
Expression
Required.
Available options.
Explain
Requirements
Version 2
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
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.
<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 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
Explain
Requirements
Version 2
Explain
Parameter
Required.
Required.
Compare
Available options. For values, see "Settings" section.
Set up
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
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
Requirements
Version 1
Explain
Requirements
Version 1
Explain
Requirements
Version 1
Explain
Requirements
Version 2
Parameter
Required.
Available options.
Explain
Requirements
Version 1
Explain
Requirements
Version 1
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
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
Explain
Dim MyDate
Requirements
Version 2
Parameter
condition
If condition is Null, condition is treated as False.
statements
Explain
Requirements
Version 1
statements
Parameter
object
statements
Explain
Requirements
Version 1
Explain