Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Schongar P.VBScript unleashed.1997

.pdf
Скачиваний:
43
Добавлен:
23.08.2013
Размер:
1.59 Mб
Скачать

Another function (LeftB) is provided for use with byte data contained in a string. Instead of specifying the number of characters to return, length specifies the number of bytes.

LeftB Function

The LeftB function, similar to the Left function, extracts a specified number of bytes from the beginning of a string. Its usage is

result = LeftB(string, length)

where result is a string variable, string is a valid string expression, and length is a numeric expression indicating the number of bytes to extract.

Len Function

The Len function determines the size of a string or determines how many characters are needed to store a variable. Its usage is

result = Len(string | varname)

where result is the number of characters in a string or the number of bytes required to store a variable, string is any valid string expression, and varname is a variable name.

LenB Function

The LenB function determines the size of a string or determines how many bytes are needed to store a variable. Its usage is

result = LenB(string | varname)

where result is the number of bytes in a string or the number of bytes required to store a variable, string is any valid string expression, and varname is a variable name.

LTrim Function

The LTrim function copies a string while stripping leading spaces. Its usage is

result = LTrim(string)

where result is the stripped string and string is a valid string expression from which the spaces are to be removed.

Mid Function

The Mid function copies a specified number of characters from a position within a string. Its usage is

result = Mid(string, start[, length])

where result is the resultant string, string is the expression from which characters are to be copied, start is the position in string where the part to be taken begins, and length is the number of characters to copy.

MidB Function

The MidB function is the byte version of the Mid function. It copies a specified number of bytes from a position within a string. Its usage is

result = MidB(string, start[, length])

where result is the resultant string, string is the expression from which bytes are to be copied, start is the position in string where the part to be taken begins, and length is the number of bytes to copy.

Right Function

The Right function copies a specified number of characters from the trailing portion of a string. Its usage is

result = Right(string, length)

where result is the resultant string, string is the expression from which the characters are to be copied, and length is a numeric expression indicating how many characters to copy.

RightB Function

The RightB function is the byte version of the Right function. It copies a specified number of bytes from the trailing portion of a string. Its usage is

result = RightB(string, length)

where result is the resultant string, string is the expression from which the bytes are to be copied, and length is a numeric expression indicating how many bytes to copy.

RTrim Function

The RTrim function copies a string while stripping trailing spaces. Its usage is

result = RTrim(string)

where result is the stripped string and string is a valid string expression from which the spaces are to be removed.

String Function

The String function builds a string containing multiple copies of the same character. Its usage is

result = String(number, character)

where result is a string variable, number is the length of the returned string, and character is the character code used to build the return string.

Trim Function

The Trim function copies a string while stripping leading and trailing spaces. Its usage is

result = Trim(string)

where result is the copied string and string is a valid string expression from which the spaces are to be removed.

UCase Function

The UCase function copies a string while converting all characters to uppercase. Its usage is

result = UCase(string)

where result is the resultant string and string is any valid string expression.

Input Functions

Input functions are procedures that automate and simplify the display and preparation of input for a script. They make it easy to provide dialog boxes and other Windows controls.

InputBox Function

The InputBox function prompts the user for input. It displays dialog box containing a prompt or other controls and then waits for the user to reply. Its usage is

result = InputBox(prompt[, title][, default][, x][, y][, help, context])

where result is the string entered by the user, prompt is the message to be displayed, title is a string to be displayed in the title bar, default is the preloaded response for the user, x and y are the coordinates-in twips (1/20th of a point)-for placement of the dialog box, help identifies the Help file to use to provide context-sensitive Help for the dialog box, and context is the Help context number for the appropriate Help topic. When a Help file is specified, a Help button is automatically added to the dialog box.

Upon return from the procedure, result will contain the contents of the text box (if the user chooses OK) or a zerolength string (if the user selects Cancel).

MsgBox Function

The MsgBox function displays a message in a dialog box with buttons and returns a value indicating which button the user has chosen. Its usage is

result = MsgBox(prompt[, buttons][, title][, help, context])

where result is the value of the button selected by the user (see Table A.4), prompt is the string to be displayed in the dialog box, buttons is a number indicating the buttons and types to be displayed as depicted in Table A.5, title is the string to be displayed in the title bar of the dialog box, help identifies the Help file to use to provide contextsensitive Help for the dialog box, and context is the Help context number for the appropriate Help topic. When a Help file is specified, a Help button is automatically added to the dialog box.

Table A.4. result values.

Value

Description

1

OK

2

Cancel

3

Abort

4

Retry

5

Ignore

6

Yes

7

No

Table A.5. buttons settings.

Setting

Description

 

Button settings

0

OK button only

1

OK and Cancel buttons

2

Abort, Retry, and Ignore buttons

3

Yes, No, and Cancel buttons

4

Yes and No buttons

5

Retry and Cancel buttons

 

Icon settings

16

Critical Message icon

32

Warning Query icon

48

Warning Message icon

64

Information Message icon

 

Default settings

0

First button is default

256

Second button is default

512

Third button is default

768

Fourth button is default

 

Dialog type

0

Application modal

4096

System modal

Mathematical Functions

The mathematical functions simplify the programming of tasks involving mathematical and geometric procedures. When using these functions, remember that some functions may be derived from other functions.

Some useful formulas are shown below:

radians = degrees * PI / 180

degrees = radians * 180 / PI

PI = 3.1415926535897932

natural log: e = 2.718282

Sin(a) = a / c

Cos(a) = b / c

Tan(a) = a / b

Sec(a) = 1 / Cos(a)

Cosec(a) = 1 / Sin(a)

Cotan(a) = 1 / Tan(a)

Arcsin(X) = Atn(X / Sqr(-X * X + 1))

Arccos(X) = Atn(-X / Sqr(-X * X + 1)) + 2 * Atn(1)

Arcsec(X) = Atn(X / Sqr(X * X - 1)) + Sgn((X) -1) * (2 * Atn(1))

Arccosec(X) = Atn(X / Sqr(X * X - 1)) + (Sgn(X) - 1) * (2 * Atn(1))

Arccotan(X) = Atn(X) + 2 * Atn(1)

HSin(X) = (Exp(X) - Exp(-X)) / 2

HCos(X) = (Exp(X) + Exp(-X)) / 2

HTan(X) = (Exp(X) - Exp(-X)) / (Exp(X) + Exp(-X))

HSec(X) = 2 / (Exp(X) + Exp(-X))

HCosec(X) = 2 / (Exp(X) - Exp(-X))

HCotan(X) = (Exp(X) + Exp(-X)) / (Exp(X) - Exp(-X))

HArcsin(X) = Log(X + Sqr(X * X + 1))

HArccos(X) = Log(X + Sqr(X * X - 1))

HArctan(X) = Log((1 + X) / (1 - X)) / 2

HArcsec(X) = Log((Sqr(-X * X + 1) + 1) / X)

HArccosec(X) = Log((Sgn(X) * Sqr(X * X + 1) +1) / X)

HArccotan(X) = Log((X + 1) / (X - 1)) / 2

LogN(x) = Log(x) / Log(n)

Abs Function

The Abs function obtains the absolute value of a number. Its usage is

result = Abs(number)

where result is the absolute value of the number argument.

Atn Function

The Atn function obtains the arctangent of a number. Its usage is

result = Atn(number)

where result is the angle in radians that corresponds to the tangent number argument.

Cos Function

The Cos function obtains the cosine of an angle. Its usage is

result = Cos(number)

where result is the ratio of the length of the side adjacent to the angle divided by the length of the hypotenuse and number is an angle in radians.

Exp Function

The Exp function obtains the base of natural logarithms raised to a power. Its usage is

result = Exp(number)

where result is the antilog of the number argument.

Fix Function

The Fix function obtains the integer portion of a number. Its usage is

result = Fix(number)

where result is the integer portion of the number argument.

Int Function

The Int function obtains the integer portion of a number. Its usage is

result = Int(number)

where result is the integer portion of the number argument.

Log Function

The Log function obtains the natural logarithm of a number. Its usage is

result = Log(number)

where result is the logarithmic value of the number argument.

Rnd Function

The Rnd function obtains a random number. Its usage is

result = Rnd[(switch)]

where result is a random number and switch indicates how the random number is to be determined. A positive number for switch indicates that the next random number in the sequence should be returned.

Before calling this function, the random number generator should be initialized by using the Randomize statement.

Sgn Function

The Sgn function obtains the sign of a number. Its usage is

result = Sgn(number)

where result is 1 if the number argument is positive, 0 if number is 0, and -1 if number is negative.

Sin Function

The Sin function obtains the sine of an angle. Its usage is

result = Sin(number)

where result is the ratio of the length of the side opposite the angle divided by the length of the hypotenuse and number is an angle in radians.

Sqr Function

The Sqr function obtains the square root of a number. Its usage is

result = Sqr(number)

where result is the square root of the number argument.

Tan Function

The Tan function obtains the tangent of an angle. Its usage is

result = Tan(number)

where result is the ratio of the length of the side opposite the angle divided by the length of the side adjacent to the

angle and number is an angle in radians.