📄 vba_functions.html
字号:
CLng(expression)<br> <br> The expression argument is any valid expression.<br> <br> In general, you can document your code using the subtype conversion functions to show that the result of some operation should be expressed as a particular data type rather than the default data type. For example, use CInt or CLng to force integer arithmetic in cases where currency, single-precision, or double-precision arithmetic normally would occur.<br> <br> Use the CLng function to provide internationally aware conversions from any other data type to a Long subtype. For example, different decimal separators are properly recognized depending on the locale setting of your system, as are different thousand separators.<br> <br> If expression lies outside the acceptable range for the Long subtype, an error occurs.<br> <br> The following example uses the CLng function to convert a value to a Long: <br> <br> Dim MyVal1, MyVal2, MyLong1, MyLong2<br> MyVal1 = 25427.45: MyVal2 = 25427.55 ' MyVal1, MyVal2 are Doubles.<br> MyLong1 = CLng(MyVal1) ' MyLong1 contains 25427.<br> MyLong2 = CLng(MyVal2) ' MyLong2 contains 25428.<p>Note. CLng differs from the Fix and Int functions, which truncate, rather than round, the fractional part of a number. When the fractional part is exactly 0.5, the CLng function always rounds it to the nearest even number. For example, 0.5 rounds to 0, and 1.5 rounds to 2.</td><td>2</td></tr><tr><td>Command</td><td>Returns the argument portion of the command line used to launch Microsoft Visual Basic or an executable program developed with Visual Basic. <br> <br> Syntax<br> <br> Command<br> <br> Remarks<br> <br> When Visual Basic is launched from the command line, any portion of the command line that follows <br> /cmd<br> is passed to the program as the command-line argument. In the following example, <br> cmdlineargs<br> represents the argument information returned by the Command function.<br> <br> VB /cmd cmdlineargs<br> For applications developed with Visual Basic and compiled to an .exe file, Command returns any arguments that appear after the name of the application on the command line. For example:<br> <br> MyApp cmdlineargs<br> To find how command line arguments can be changed in the user interface of the application you're using, search Help for "command line arguments."</td><td> -</td></tr><tr><td>Cos</td><td>Returns a Double specifying the cosine of an angle.<br> <br> Syntax<br> <br> Cos(number)<br> <br> The required number argument is a Double or any valid numeric expression that expresses an angle in radians.<br> <br> Remarks<br> <br> The Cos function takes an angle and returns the ratio of two sides of a right triangle. The ratio is the length of the side adjacent to the angle divided by the length of the hypotenuse.<br> <br> The result lies in the range -1 to 1.<br> <br> To convert degrees to radians, multiply degrees by pi/180. To convert radians to degrees, multiply radians by 180/pi.</td><td>1</td></tr><tr><td>Count</td><td> </td><td>?</td></tr><tr><td>CreateObject</td><td>Creates and returns a reference to an ActiveX object.<br> <br> Syntax<br> <br> CreateObject(class,[servername])<br> <br> The CreateObject function syntax has these parts:<br> <br> Part Description <br> class Required; Variant (String). The application name and class of the object to create. <br> servername Optional; Variant (String). The name of the network server where the object will be created. If servername is an empty string (""), the local machine is used. <br> <br> The class argument uses the syntax appname.objecttype and has these parts:<br> <br> Part Description <br> appname Required; Variant (String). The name of the application providing the object. <br> objecttype Required; Variant (String). The type or class of object to create. <br> <br> Remarks<br> <br> Every application that supports Automation provides at least one type of object. For example, a word processing application may provide an Application object, a Document object, and a Toolbar object.</td><td>-</td></tr><tr><td>CSng</td><td> </td><td>?</td></tr><tr><td>CStr</td><td> </td><td>?</td></tr><tr><td>CurDir</td><td>Returns a Variant (String) representing the current path.<br> <br> Syntax<br> <br> CurDir[(drive)]<br> <br> The optional drive argument is a string expression that specifies an existing drive. If no drive is specified or if drive is a zero-length string (""), CurDir returns the path for the current drive.</td><td> </td></tr><tr><td>Cvar</td><td> </td><td> </td></tr><tr><td>CVDate</td><td> </td><td> </td></tr><tr><td>CVErr</td><td>Returns a Variant of subtype Error containing an error number specified by the user.<br> <br> Syntax<br> <br> CVErr(errornumber)<br> <br> The required errornumber argument is any valid error number.<br> <br> Remarks<br> <br> Use the CVErr function to create user-defined errors in user-created procedures. For example, if you create a function that accepts several arguments and normally returns a string, you can have your function evaluate the input arguments to ensure they are within acceptable range. If they are not, it is likely your function will not return what you expect. In this event, CVErr allows you to return an error number that tells you what action to take.<br> <br> Note that implicit conversion of an Error is not allowed. For example, you can't directly assign the return value of CVErr to a variable that is not a Variant. However, you can perform an explicit conversion (using CInt, CDbl, and so on) of the value returned by CVErr and assign that to a variable of the appropriate data type.</td><td>-</td></tr><tr><td>Date</td><td>Returns a Variant (Date) containing the current system date.<br> <br> Syntax<br> <br> Date<br> <br> Remarks<br> <br> To set the system date, use the Date statement.<br> <br> Date, and if the calendar is Gregorian, Date$ behavior is unchanged by the Calendar property setting. If the calendar is Hijri, Date$ returns a 10-character string of the form mm-dd-yyyy, where mm (01-12), dd (01-30) and yyyy (1400-1523) are the Hijri month, day and year. The equivalent Gregorian range is Jan 1, 1980 through Dec 31, 2099.</td><td>1</td></tr><tr><td>DateAdd</td><td>Returns a Variant (Date) containing a date to which a specified time interval has been added.<br> <br> Syntax<br> <br> DateAdd(interval, number, date)<br> <br> The DateAdd function syntax has these named arguments:<br> <br> Part Description <br> interval Required. String expression that is the interval of time you want to add. <br> number Required. Numeric expression that is the number of intervals you want to add. It can be positive (to get dates in the future) or negative (to get dates in the past). <br> date Required. Variant (Date) or literal representing date to which the interval is added. <br> <br> Settings<br> <br> The interval argument has these settings:<br> <br> Setting Description <br> yyyy Year <br> q Quarter <br> m Month <br> y Day of year <br> d Day <br> w Weekday <br> ww Week <br> h Hour <br> n Minute <br> s Second <br> <br> Remarks<br> <br> You can use the DateAdd function to add or subtract a specified time interval from a date. For example, you can use DateAdd to calculate a date 30 days from today or a time 45 minutes from now.<br> <br> To add days to date, you can use Day of Year ("y"), Day ("d"), or Weekday ("w").<br> <br> The DateAdd function won't return an invalid date. The following example adds one month to January 31:<br> <br> DateAdd("m", 1, "31-Jan-95")<br> In this case, DateAdd returns 28-Feb-95, not 31-Feb-95. If date is 31-Jan-96, it returns 29-Feb-96 because 1996 is a leap year.<br> <br> If the calculated date would precede the year 100 (that is, you subtract more years than are in date), an error occurs.<br> <br> If number isn't a Long value, it is rounded to the nearest whole number before being evaluated.<br> <br> Note The format of the return value for DateAdd is determined by Control Panel settings, not by the format that is passed in date argument.<br> <br> Note For date, if the Calendar property setting is Gregorian, the supplied date must be Gregorian. If the calendar is Hijri, the supplied date must be Hijri. If month values are names, the name must be consistent with the current Calendar property setting. To minimize the possibility of month names conflicting with the current Calendar property setting, enter numeric month values (Short Date format).</td><td>1</td></tr><tr><td>DateDiff</td><td>Returns a Variant (Long) specifying the number of time intervals between two specified dates.<br> <br> Syntax<br> <br> DateDiff(interval, date1, date2[, firstdayofweek[, firstweekofyear]])<br> <br> The DateDiff function syntax has these named arguments:<br> <br> Part Description <br> interval Required. String expression that is the interval of time you use to calculate the difference between date1 and date2. <br> date1, date2 Required; Variant (Date). Two dates you want to use in the calculation. <br> firstdayofweek Optional. A constant that specifies the first day of the week. If not specified, Sunday is assumed. <br> firstweekofyear Optional. A constant that specifies the first week of the year. If not specified, the first week is assumed to be the week in which January 1 occurs. <br> <br> Settings<br> <br> The interval argument has these settings:<br> <br> Setting Description <br> yyyy Year <br> q Quarter <br> m Month <br> y Day of year <br> d Day <br> w Weekday <br> ww Week <br> h Hour <br> n Minute <br> s Second <br> <br> <br> The firstdayofweek argument has these settings:<br> <br> Constant Value Description <br> vbUseSystem 0 Use the NLS API setting. <br> vbSunday 1 Sunday (default) <br> vbMonday 2 Monday <br> vbTuesday 3 Tuesday <br> vbWednesday 4 Wednesday <br> vbThursday 5 Thursday <br> vbFriday 6 Friday <br> vbSaturday 7 Saturday <br> <br> Constant Value Description <br> vbUseSystem 0 Use the NLS API setting. <br> vbFirstJan1 1 Start with week in which January 1 occurs (default). <br> vbFirstFourDays 2 Start with the first week that has at least four days in the new year. <br> vbFirstFullWeek 3 Start with first full week of the year. <br> <br> <br> Remarks<br> <br> You can use the DateDiff function to determine how many specified time intervals exist between two dates. For example, you might use DateDiff to calculate the number of days between two dates, or the number of weeks between today and the end of the year.<br> <br> To calculate the number of days between date1 and date2, you can use either Day of year ("y") or Day ("d"). When interval is Weekday ("w"), DateDiff returns the number of weeks between the two dates. If date1 falls on a Monday, DateDiff counts the number of Mondays until date2. It counts date2 but not date1. If interval is Week ("ww"), however, the DateDiff function returns the number of calendar weeks between the two dates. It counts the number of Sundays between date1 and date2. DateDiff counts date2 if it falls on a Sunday; but it doesn't count date1, even if it does fall on a Sunday.<br> <br> If date1 refers to a later point in time than date2, the DateDiff function returns a negative number.<br> <br> The firstdayofweek argument affects calculations that use the "w" and "ww" interval symbols.<br> <br> If date1 or date2 is a date literal, the specified year becomes a permanent part of that date. However, if date1 or date2 is enclosed in double quotation marks (" "), and you omit the year, the current year is inserted in your code each time the date1 or date2 expression is evaluated. This makes it possible to write code that can be used in different years.<br> <br> When comparing December 31 to January 1 of the immediately succeeding year, DateDiff for Year ("yyyy") returns 1 even though only a day has elapsed.<br> <br> Note For date1 and date2, if the Calendar property setting is Gregorian, the supplied date must be Gregorian. If the calendar is Hijri, the supplied date must be Hijri.</td><td>1</td></tr><tr><td>DatePart</td><td>Returns a Variant (Integer) containing the
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -