VBA Learning Notes (2)-Process

Source: Internet
Author: User
Tags mathematical functions natural logarithm random seed square root

A procedure is a collection that executes one or more given tasks.

into: subroutines and functions.

1. Sub-Program

[Private| Public | Friend] [StaticSub  name [(arglist)][staements][Exit Sub][statements]End Sub

Friend indicates that the sub is visible throughout the project, but object instance controllers are not visible

2. function, with return value

[Private| Public | Friend] [StaticSub name [(arglist)]  [ as type][statements][name= expression][Exit Function][statements][name = expression]End Function

Function arguments are optional and can be detected with the IsMissing function when invoked, returning a Boolean value;

If  Then ' .... Else ' .... End if

However, for the ParamArray parameter, IsMissing returns always false to detect whether the upper bound is less than the lower bound (UBound (A ()) returns the upper bound of a)

3. Call the direct name or call to invoke the

4.VBA built-in functions

1). Test function

IsNumeric (x) ' is a number that returns a Boolean result, True or False

IsDate (x) ' is a date, returns a Boolean result, True or False

IsEmpty (x) ' is empty, returns a Boolean result, True or False

IsArray (x) ' Indicates whether the variable is an array.

IsError (expression) ' Indicates whether the expressions are an error value

IsNull (expression) ' Indicates whether the expression does not contain any valid data (Null).

IsObject (identifier) ' Indicates whether an identifier represents an object variable

2). Mathematical functions

Sin (x), Cos (x), Tan (x), Atan (x) ' trigonometric functions in radians

Log (x) ' Returns the natural logarithm of X

EXP (x) ' Return ex

Abs (x) ' Return absolute value

int (number), fix (number) returns the integer part of the argument, the difference: int converts 8.4 to-9, and fix converts-8.4 to 8

SGN (number) ' Returns a Variant (Integer) that indicates the sign of the parameter

SQR (number) ' Returns a Double that specifies the square root of the parameter

VarType (varname) ' Returns an Integer that indicates the subtype of the variable

Rnd (x) ' returns single-precision data between 0-1 and X for random seed

3). String functions

Trim (String) remove the left and right sides of string blank

Ltrim (String) remove left blank of string

Rtrim (String) Remove the right-side whitespace from the string

Len (String) calculates the string length

Left (string, x) takes a string of x characters

Right (string, x) takes a string of x characters

Mid (String, start,x) takes a string of x characters starting from the start bit

Convert Ucase (string) to uppercase

Convert Lcase (string) to lowercase

Space (x) returns a string of x blanks

ASC (String) returns an Integer that represents the character code of the first letter in the string

CHR (CharCode) returns a string that contains characters associated with the specified character code

3) conversion function, commonly used is:

Val (string) converted to data type

Str (number) converted to string

Others: CBool (expression), cbyte,cdate, etc.

5). Time function

Now returns a Variant (date) that specifies the date and time according to the date and time set by the computer system.

Date returns a Variant (date) that contains the system date.

Time returns a Variant (Date) that indicates the current system times.

The Timer returns a single that represents the number of seconds from midnight to now.

TimeSerial (hour, minute, second) returns a Variant (date) that contains time, minutes, and seconds.

DateDiff (interval, date1, date2[, firstdayofweek[, FirstWeekOfYear]]) returns the value of Variant (long) that represents the number of time intervals between two specified dates

Second (Time) returns a Variant (integer) with a value from 0 to 59, representing a second in a minute

Minute (Time) returns a Variant (integer) with a value from 0 to 59 that represents the minute of the hour

Hour (Time) returns a Variant (integer) with a value from 0 to 23 that represents an hour of the day

Day Returns a Variant (integer) whose value is an integer between 1 and 31, representing the day of the one month

Month (date) returns a Variant (integer) with a value from 1 to 12 that represents the month of the year

Year (date) returns a Variant (integer) that contains an integer representing the years.

Weekday (date, [FirstDayOfWeek]) returns a Variant (integer) containing an integer representing the day of the week

ref:http://club.excelhome.net/forum.php?mod=viewthread&tid=178278&extra=page%3d3%26filter%3ddigest% 26digest%3d1&page=2

Bookmark a good forum posts:

Original Excel VBA Quick start of the Bible
Http://club.excelhome.net/thread-178278-1-1.html

VBA Learning Notes (2)-Process

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.