Current location - Training Enrollment Network - Mathematics courses - VB statement function daquan
VB statement function daquan
(1) Type conversion function

1.CType(X)

[Format]:

P=CBool(X)

Convert x to boolean type.

P=CByte(X)

Convert x to byte type.

P=CCur(X)

Convert x to currency type.

P=CDate(X)

Convert x to type "date"

P=CDbl(X)

Convert x to type "Double"

P=CInt(X)

Convert x to integer type.

P=CLng(X)

Convert x to type "Long".

P=CSng(X)

Convert x to a single type.

P=CStr(X)

Convert x to a string type.

P=Cvar(X)

Convert x to a variable type.

P=CVErr(X)

Convert x into an error value.

[example]:

( 1).CStr( 13)+CStr(23)

After the value is converted into a string, connect it with a "+"sign. Results: 1323.

(2).CInt(" 12")+ 12

The string is converted into an integer and added to 12. The result is 24.

(3).P=CInt (true)

The output result is-1.

When converting a Boolean value into a numerical value, it should be noted that a Boolean value has only a true value and a false value, where the true value is-1 in memory and the false value is stored as 0.

(4).CBool(-0.00 1)

The output result is true.

When converting a numeric value to a Boolean value, a numeric value equal to 0 will be False, and a numeric value not equal to 0 will be True.

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

[Format]:

P=Int(X)' take

P=Fix(X)' Take the integer part of x and remove the decimal directly.

[example]:

( 1) Int(-54.6)

The result is -55, take

(2) Repair (54.6)

The result is 54, take the integer and directly remove the decimal.

(B) commonly used mathematical functions

[Format]:

1.Abs(N) takes the absolute value.

For example: Abs(-3.5) Result: 3.5

2. Cosine function

Example: Cos(0) result: 1

3. Exponential function based on exponential function

Example: Experiment (3) Result: 20.068

4. Natural Logarithm Based on E

Example: Log( 10) Result: 2.3

5.Rnd[(N) generates random numbers.

Example: Rnd result: a number between 0 and 1.

6. Sine function

Example: Sin(0) Result: 0

7. Symbolic function

Caption: Hold the sign. Y=Sgn(X) is X >;; 0 then y =1; X=0 then y = 0;; X<0 then Y=-1.

8. Square root of sqr (n)

Example: Sqr(9) Result: 3

9. Tangent function

Example: Tan(0) Result: 0

10.Atn(N) arctangent function

Example: Atn(0) Result: 0

[Note]: In trigonometric functions, it is expressed in radians.

(a) string function:

1.ASC(X), Chr(X): character code of converted characters.

[Format]:

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

P=Chr(X) returns the character whose character code is equal to x.

[example]:

( 1)P=Chr(65)

Output the character a, because the ASCII code 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)

[description]:

The length of the empty string is 0, and the space character is counted as one character. Although a Chinese character occupies 2 bytes, it is also a word.

[example]:

(1) Make X= "(empty string)

The output result of Len(X) is 0.

(2) let 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 characters in the middle of the string X.

[Format]:

P=Mid(X,n)

Starting from the nth character of x, read all the characters after it.

P=Mid(X,n,m)

Starting with the nth character of x, read the next m characters.

[example]:

( 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. Replacement: Replace some specific strings with other strings.

[Format]:

P = substitution (x, s, r)

[Description]: Replace the string S in the string X with the string R, and then return.

[example]:

X="VB is very good "

P = substitution (x, good, good)

The output result is: P="VB looks good "

5.StrReverse: Invert the string

[Format]:

P=StrReverse(X)

[description]:

Returns the reverse string of the x parameter.

[example]:

( 1)X="abc "

P=StrReverse(X)

Output result: P="cba "

6.Ucase(X), Lcase(X): change the case of English letters.

[Format]:

P=Lcase(X)

Converts uppercase letters in an X string to lowercase letters.

P=Ucase(X)

Converts lowercase letters in an X string to uppercase letters.

[Description]: Except English letters, other characters or Chinese characters are not affected.

[example]:

(1) let x = "VB and VC"

The result of Lcase(X) is "vb and vc", and the result of Ucase(X) is "VB and VC".

7.InStr function: find string

[Format]:

P = instrument (x, y)

Find out where y appears from the first character of x.

P=InStr(n,X,Y)

Find the position of y from the nth character of x.

[description]:

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

(2) InStr(X, y) is equivalent to InStr( 1, x, y).

(3) If the length of the string, or X is an empty string, or Y is not found in X, it will return 0.

(4) If y is an empty string, 0 is returned.

(2) Date and time function:

1. year (x), month (x) and day (x): take out the year, month and day.

[Format]:

P = year (x)

Remove the value of the "year" part of x.

P = month (x)

Take out the value of the "month" part of x.

P = days (x)

Take out the value of the x "days" part.

[Description]: Year returns the AD year. If there is only time in X but no date, the date is regarded as # 1899/ 12/30#

2. Hours, minutes and seconds function: take out hours, minutes or seconds.

[Format]:

P = hours (x)

Remove the value of the "when" part of x.

P = minutes (x)

Take out the value of the "points" part of x.

P = seconds (x)

Take out the value of the second part of X.

[Description]: The return value of: The hour is between 0 and 23.

[example]:

X= 10:34:23

P = hours (x)

Q = minutes (x)

R = seconds (x)

Then the output results are: P= 10, Q=34, R=23.

3.DateSerial function: merge the year, month and day into a date.

[Format]:]: Date series (y, m, d, m, d)

Where y is the year, m is the month and d is the date.

[description]:

If the value of (1) M is greater than 12, the month is calculated backwards from 12 months; If it is less than 1, the month is calculated backwards from 1 to 1-M months.

(2) If the date d is greater than the number of days in the current month, the date is calculated backwards from the number of days in the current month, and d is the number of days in the current month; If it is less than 1, the date is calculated forward from 1 to1-d.

[example]:

P = date series (February 2, 2000)

The result is P=2000/02/02.

4. Time series function: When merging, minutes and seconds become time.

[format ]: p = time series (h, m, s)

Where h is the hour, m is the minute and s is the second.

[Description]: The calculation principle is the same as the above DateSerial.

[example]:

P = time series (6, 32, 45)

The result is: P=6:32:45.

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

[Format]:

P = date ()

P = time ()

P = now ()

[Description]: These three functions have no parameters.

[example]:

If the current time is August 29th, 2003 19: 26: 45, 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)

[Description]: The x parameter can be passed into 1- 12, and the return values are "January" and "February" ... but in English Windows environment, the return values are "January" and "February". ...

[example]:

P=MonthName( 1)

So P= "January"

7.weekdayname: returns the name of the week.

[Format ]: p = weekdayname (x)

[Description]: If the x parameter can be passed in as 1-7, the return values will be "Sunday" and "Monday" ... but in English windows environment, "Sunday" and "Monday" will be returned.

[example]:

P=WeekdayName( 1)

The result is: P= "Sunday "

Function name function function

Cbool(string) is converted to a Boolean value.

Cbyte(string) is converted to a value of type byte.

Ccur (string) is converted to a monetary value.

Cdate (string) was converted to a value of type days ago.

Cdbl (string) is converted to a double-precision value.

Cint (string) is converted to an integer value.

Clng (string) is converted to a long integer value.

Csng (string) is converted to a single-precision value.

Cstr(var) is converted into a string value.

A string(var) value is converted to a string.

The Val(string) string is converted into a numerical value.

***************************************

Abs(nmb) returns the absolute value of the molecule.

Atn(nmb) returns the arc tangent of a number.

Cos(nmb) returns the residual value of an angle.

Exp(nmb) returns the power of the natural index.

Int(nmb) returns the plastic (carry) part of the number 8.4- >; nine

Fix(nmb) returns the shaping (rounding) part of the number 8.4- >; eight

Formatpercent (expression) returns a percentage.

Hex(nmb) returns the data of 16 hexadecimal number.

Log(nmb) returns the natural logarithm.

Oct(nmb) returns the octal number of a number.

Rnd returns a random number greater than "0" and less than "1"

Sgn(nmb) judges the sign of numbers.

Sin(nmb) returns the positive value of the angle.

Sqr(nmb) returns the square root of a number.

Tan(nmb) returns the tangent of a number.

Asc(string) returns an ASCII string.

Chr(charcode) returns characters according to the character code.

Instr(string, searchstr) returns the first character position of a search string, where string is a string and searchstr is a search string.

InstrRev(string, searchstr) is the same as above, starting from the right.

Lcase(var) converts a string to lowercase.

Left(string, nmb) returns the nmb string from the left.

Len(string) returns the length of a string.

Ltrim(string) truncates the spaces on the left side of the string.

Filter(Inputstrings, value) returns the word set of string array, where Inputstrings is the string group and value is the character to find in the array.

Rtrim(string) truncates the space to the right of the string.

Trim(string) truncates the spaces before and after the string.

Mid(string, start, len) returns the len character starting from the starting position in string.

Replace (string, find, wit str) In string, replace the search string with with withstr.

Right(string, nmb) returns the nmb string from the right.

Space(nmb) returns a string with the specified space.

StrComp(string 1, string2) compares two strings.

Ucase(string) converts a string to uppercase.

****************************************

Date () returns the current system date.

DateAdd(interval, nmb, date nmb, date) returns the date of the specified time interval to which the base time has been added, where interval is the time interval type, that is, year, month, day, hour and minute.

DateDiff (interval, nmb 1, nmb2) returns two time intervals, and the meaning of interval is the same as above.

Datevalue(Date) plays the date part in the date.

Day(date) returns the number of days.

FormatDatetime(date) returns an expression formatted as a date.

Hour(time) returns the number of hours of time.

Minute(time) returns the number of minutes of time.

Month(date) returns the month in the date.

Now () returns the date and time of the system.

Second(time) returns the number of seconds in time.

Time () returns the current time of the system.

Weekday(date) returns the day of the week.

WeekdayName(date) returns the Chinese name of a day of the week.

Year(date) returns the year.

IsArray(var) determines whether the variable is an array.

IsDate(var) determines whether the variable is a date.

IsNull(var) determines whether the variable is empty.

IsNumeric determines whether the expression contains numeric values.

IsObject(var) determines whether a variable is an object.

TypeName(var) returns the data type of a variable

************************************

Array(list) returns an array.

Create an object.

Gets the file object.

Inputbox provides a dialog box for entering data.

LBound(arrayP) returns the minimum index of an array.

Msgbox (string) outputs a message box.

Split(liststr) returns a one-dimensional array from a list string.

Ubound(array) returns the maximum index of an array.