当前位置:文档之家› vb函数大全(VBfunctionDaquan)

vb函数大全(VBfunctionDaquan)

vb函数大全(VBfunctionDaquan)
vb函数大全(VBfunctionDaquan)

vb函数大全(VB function Daquan)vb函数大全(VB function Daquan)

VB commonly used function Daquan 2008-03-08 19:39, now programming software, such as VB, C++, etc., mostly with a powerful library of functions, you can save effort to complete a variety of functions. Most of the time, you can't remember the function or function format that implements a function, which results in a lot of trouble in programming. As a programmer, I have a deep understanding of this. Therefore, specially prepared several VB common function introduction, for your study or reference. There are inappropriate places to say, but also welcome in the Forum on this web site, we study.

(I) type conversion class functions

1. CType (X)

[format]:

P=CBool ("X") converts X to "Boolean" (Boolean) type

P=CByte ("X") converts X to "Byte" type

P=CCur (X) 'converts X to the' Currency 'type

P=CDate ("X") converts X to "Date" type

P=CDbl ("X") converts X to "double precision" (Double) type

P=CInt (X) converts the X to an integer (Integer) type

P=CLng ("X") converts X to "long integer" (Long) type

P=CSng (X) converts X to a single precision (Single) type

P=CStr (X) converts the X to a string (String) type

P=Cvar (X) converts the X to a variant (Variant) type

P=CVErr (X) 'converts X to a Error value

[paradigm]:

(1) CStr (13) +CStr (23) after the value is converted into a string, and is connected with "+" number, and the result is: 1323

(2) CInt ("12") +12'strings are converted into integers and then summed up with 12. Results: 24

(3) P=CInt (True) ', the output is -1

"Boolean and numeric conversions should be noted, Boolean values are only True and False, in which True is -1 in memory, and False is 0

(4) CBool (-0.001) ', the output is True

When the value is converted to Boolean, the value equal to 0 will be False, and the value not equal to 0 will be True.

2. Int (X), Fix (X): take the integer value of X

[format]:

P=Int (X) 'takes the maximum integer value of <=X

P=Fix ("X") takes the integer part of X and removes the decimal directly

[paradigm]:

(1) Int (-54.6) ', the result is -55, take the maximum integer of

<=-54.6

(2) Fix (54.6) ', the result is 54, take an integer and remove the decimal directly

(two) commonly used mathematical functions

[format]:

1. Abs (N) takes absolute value

Example: Abs (-3.5) results: 3.5

2. Cos (N) cosine function

Example: Cos (0): 1

3. Exp (N) e is the exponential function at the bottom Example: Exp (3): 20.068

4. Log (N) the natural logarithm based on e

Example: Log (10): 2.3

5. Rnd[(N)] generates random numbers

Example: Rnd result: the number between 0--1

6. Sin (N) sine function

Example: Sin (0): 0

7. Sgn (N) signed function

Explanation: take the plus sign. Y=Sgn (X) is both X>0 and Y=1; X=0 is Y=0; X<0 is Y=; -1

8. Sqr (N) square root

Example: Sqr (9): 3

9. Tan (N) tangent function

Example: Tan (0): 0

10.Atn (N) reverse function

Example: Atn (0): 0

[note] in trigonometric functions, expressed in radians. (string) class function of string:

1., ASC (X), Chr (X): conversion character, character code

[format]:

P=Asc (X) returns the character code of the first character of string X

P=Chr (X) returns characters equal to X characters

[paradigm]:

(1) P=Chr (65);

'output character' A 'because the ASCII of A is equal to 65

(2) P=Asc ("A")

Output 65

2. Len (X): calculate the length of the string X

[format]:

P=Len (X)

[instructions]:

The empty string length is 0, and the space character is also a character. A Chinese text occupies 2 Bytes, but is also counted as a character.

[paradigm]:

(1) make X= "" (empty string)

The output of Len (X) is 0

(2) make X= "ABCD""

The output of Len (X) is 4

(3) make X= VB tutorial"

The output of Len (X) is 4

3. Mid (X) function: read the string X characters in the middle [format]:

P=Mid (X, n)

Read by the N character of X, read all the characters behind.

P=Mid (X, N, m)

Read by the N character of X, read the M characters behind. [paradigm]:

(1) X= "ABCDEFG""

P=Mid (X, 5)

The result is: "P=" efg"

(2) X= "ABCDEFG""

P=Mid (X, 2,4)

The result is P= "BCDE""

4. Replace: replaces some of the string in a string with another string

[format]:

P=Replace (X, S, R)

[explanation]: replace the string S in string X with string R, and then return.

[paradigm]:

X=, VB, is, very, good"

P=Replace (X, good, nice)

The output is: P=, VB, is, very, nice"

5. StrReverse: inverted string

[format]:

P=StrReverse (X)

[instructions]:

Returns the string after the X parameter is reversed

[paradigm]:

(1) X= "ABC""

P=StrReverse (X)

Output: P= "CBA""

6., Ucase (X), Lcase (X): convert English letters to uppercase and lowercase

[format]:

P=Lcase (X)

Convert uppercase characters from X strings to lowercase

P=Ucase (X)

"Convert lowercase letters from X strings to uppercase."

[instructions] no other characters or Chinese characters will be affected except English letters.

[paradigm]:

(1) make X=, VB, and, VC"

The result of Lcase (X) is "VB, and, VC", and Ucase (X) is "VB AND VC""

7. InStr function: finding strings

[format]:

P=InStr (X, Y)

Locate the position of the Y from the first character of the X

P=InStr (n, X, Y)

Find the position of the Y from the X n character

[instructions]:

(1) if the Y is found in X, the return value is the place where the first character of the Y appears in X.

(2) InStr (X, Y) is equivalent to InStr (1, X, Y).

(3) if the string length, or X is an empty string, or Y is not found in X, 0 is returned.

(4) if Y is an empty string, returns 0.

Date time class function:

1., Year (X), Month (X), Day (X): take out year, month, day

[format]:

P=Year (X)

Take out the value of the X "year" section

P=Month (X)

Take out the value of the X "month" section

P=Day (X)

Take out the value of the X "day" section

[description]:Year returns in AD, and if X has only time and no date, the date is #1899/12/30#

2., Hour, Minute, Second function: take out, divide, or second

[format]:

P=Hour (X)

Take the value of the "X" part of the "when"

P=Minute (X)

Take out the value of the "X" part

P=Second (X)

Take out the value of the X "seconds" section

[indicates that the return value of]:Hour is between 0---23

[paradigm]:

X=10:34:23

P=Hour (X)

Q=Minute (X)

R=Second (X)

Output results: P=10, Q=34, R=23

3., DateSerial function: merge year, month, date, become date

[format]:DateSerial (Y, M, D)

Where Y is the year, M is the month, and D is the date

[instructions]:

(1) if the value of M is greater than 12, the month will be

extrapolated from December to M-12 months; if less than 1, the month will be extrapolated from January to 1-M months.

(2) if the date D is greater than the number of days in that month, the date from the date of the month, the number of D- months later; if less than 1, then the date from 1 days forward projections 1-D days.

[paradigm]:

P=DateSerial (2000,02,02)

The result is P=2000/02/02

4.TimeSerial function: when merging, minutes and seconds become time

[format]:P=TimeSerial (H, M, S)

H is the number of hours, M is minutes, and S is seconds

[explanation]: the principle of calculation is the same as that of DateSerial above

[paradigm]:

P=TimeSerial (6,32,45)

The result was: P=6:32:45

5.Date, Time, Now function: read the date and time of the system

[format]:

P=Date ()

P=Time ()

P=Now ()

[explanation]: none of these three functions have arguments

[paradigm]:

If the current time is 19:26 on August 29, 2003 evening, 45 seconds, then

P=Now ()

The result is: P=2003-08-29 19:26:45

6.MonthName: returns the name of the month

[format]:P=MonthName (X)

[to indicate that the]:X parameter can be passed in to 1---12, returns the value of "month" and "February""...... But in English Windows, the return is "January", "February""......

[paradigm]:

P=MonthName (1)

"P=" one month"

7.WeekdayName: returns the name of the week

[format]:P=WeekdayName (X)

[shows that the]:X parameter can be passed in 1 - 7, and returns the value "Sunday", Monday"...... But in English windows, the return is "Sunday", "Monday""......

[paradigm]:

P=WeekdayName (1)

The result is: P=, Sunday"

Mathematical function of https://www.doczj.com/doc/cc6562192.html, function Daquan

Abs (Num) takes absolute value.

Exp (Num) returns the value of e at the bottom and num as an exponent, such as Exp (2) returning the e^2 value.

Log (Num) returns the natural pair value of parameter num, which is the Double type, that is, the logarithm based on E.

Hex (Num) converts the parameter num to 16.

Oct (Num) converts the parameter num to 8

Sign (Num) returns the positive and negative sign of the parameter. If num is greater than 0, the return value is 1; if num equals 0, then

the return value is 0; if num is less than 0, then the return value is -1.

Sqrt (Num) returns the square root of the argument, Double type.

Atan (Num) tangent function

Sin (Num) sine function

Cos (Num) cosine function

Tan (Num) tangent function

Rand (Num, [int]) will enter the parameter num four, five, to

specify four to five into which decimal, you can add second parameters int. For example, Round (12.456) returns the value of 12 Round (12.4567,3) returns 12.457.

Rnd [[nun]] produces a random number less than 1, greater than or equal to 0, of type Single. If num is less than 0, then each will return the same number; if you don't provide the parameters or parameter is greater than 0, so in order to generate a random number next, this is the default value; if the parameter num is equal to 0, then returns the last generated random number. In order to generate different random numbers each time, it is better to use the Randomize statement before using the Rand () function. To randomly generate an integer from N to M, you can

use the following formula: Int (Rand ()) *M-N+1, +N.

Pow (x, y) seeks the Y power of X.

Val (STR) converts the number in a string to Integer or Double type.

Str (Num) converts a numeric type parameter into a string to return.

When the Fix (Num) parameter is greater than 0, the decimal part is removed; when the parameter is less than 0, the value returned is greater than or equal to the parameter value.

When the Int (Num) parameter is greater than 0, the decimal part is removed; when the number is less than 0, the parameter is returned less than or equal to the parameter value.

相关主题
文本预览
相关文档 最新文档