ASP中的函数应用方法及应用举例(一)

1.Array()
FUNCTION: Returns a variant containing an array.
SYNTAX: Array(list)
ARGUMENTS: list is a comma-delimited list of values to add to the array.
EXAMPLE: ```

Dim myArray()
For i = 1 to 7
Redim Preserve myArray(i)
myArray(i) = WeekdayName(i)
Next

 1RESULT: Creates an Array contains 7 elements:   
 2myArray("Sunday","Monday", ... ... "Saturday")   
 3\-------------------------------------   
 4  
 52\. CInt()   
 6FUNCTION: Returns an expression that has been converted to an Interget subtype.   
 7SYNTAX: CInt(expression)   
 8ARGUMENTS: expression is any valid expression   
 9EXAMPLE: ```
10   
11f = "234"   
12response.write cINT(f) + 2   

RESULT: 236
Converts string "234" to mathematic value 234.
If f is empty (un-initialized variable), cINT() returns 0.
-------------------------------------

3. CreateObject()
FUNCTION: Creates and returns a reference to ActiveX automation object.
SYNTAX: CreateObject(objName)
ARGUMENTS: objName is any valid ActiveX automation object.
EXAMPLE: ```

Set con = Server.CreateObject("ADODB.Connection")

 1RESULT:   
 2\-------------------------------------   
 3  
 44\. CStr()   
 5FUNCTION: Returns an expression that has been converted to a variant of subtype String.   
 6SYNTAX: CStr(expression)   
 7ARGUMENTS: expression is any valid expression   
 8EXAMPLE: ```
 9   
10s = 3 + 2   
11response.write "The result is: " & cStr(s)   

RESULT: Converts a mathematic value 5 to a string "5".
-------------------------------------

5. Date()
FUNCTION: Returns the current system date.
SYNTAX: Date()
ARGUMENTS: None.
EXAMPLE: ``` =Date

 1RESULT: 8/4/99   
 2\-------------------------------------   
 3  
 46\. DateAdd()   
 5FUNCTION: Returns a date to which a specific time interval has been added.   
 6SYNTAX: DateAdd(timeinterval,number,date)   
 7ARGUMENTS: timeinterval is the time interval to add; number is amount of time intervals to add; and date   
 8is the starting date.   
 9EXAMPLE: ```
10   
11currentDate = #8/4/99#   
12newDate = DateAdd("m",3,currentDate)   
13response.write newDate   
1   
2currentDate = #12:34:45 PM#   
3newDate = DateAdd("h",3,currentDate)   
4response.write newDate   

RESULT: 11/4/99
3:34:45 PM

"m" = "month";
"d" = "day";

If currentDate is in time format then,
"h" = "hour";
"s" = "second";
-------------------------------------

7. DateDiff()
FUNCTION: Returns the number of intervals between two dates.
SYNTAX: DateDiff(timeinterval,date1,date2 [, firstdayofweek [, firstweekofyear]])
ARGUMENTS: timeinterval is the time interval to add; date is a valid date expression; firstdayofweek and
firstweekofyear are optional values to specify the first day of the week and first week of year.
EXAMPLE: ```

fromDate = #8/4/99#
toDate = #1/1/2000#
response.write "There are " & _
DateDiff("d",fromDate,toDate) & _
" days to millenium from 8/4/99."

1RESULT: There are 150 days to millenium from 8/4/99.   
2\-------------------------------------   
3  
48\. Day()   
5FUNCTION: Returns a whole number representing the day of the month.   
6SYNTAX: Day(date)   
7ARGUMENTS: date is any valid date expression.   
8EXAMPLE: ```
9=Day(#8/4/99#)

RESULT: 4
-------------------------------------

9. FormatCurrency()
FUNCTION: Returns an expression formatted as a currency value.
SYNTAX: FormatCurrency(Expression [, Digit [, LeadingDigit [, Paren [, GroupDigit]]]])
ARGUMENTS: Expression is a valid numeric expression; Digit is an optional numeric value used to indicate
number of digits to the right of the decimal point; LeadingDigit is an optional tristate value to display
a leading zero; Paren is an optional tristate value used to display parentheses around negative values;
and GroupDigit is an option tristate value used to display a number as specified in the group delimiter
settings of the Control Panel's regional settings.
EXAMPLE: ``` =FormatCurrency(34.3456)

1RESULT: $34.35   
2\-------------------------------------   
3  
410\. FormatDateTime()   
5FUNCTION: Returns an expression formatted as a date or time.   
6SYNTAX: FormatDateTime(Date, [, NamedFormat])   
7ARGUMENTS: Date is any valid date expression, and NamedFormat is an optional date/time constant.   
8EXAMPLE: ```
9=FormatDateTime("08/4/99", vbLongDate)

RESULT: Wednesday, August 04, 1999
-------------------------------------

10. FormatNumber()
FUNCTION: Returns an expression formatted as a number.
SYNTAX: FormatNumber(Expression [, Digit [, LeadingDigit [, Paren [, GroupDigit]]]])
ARGUMENTS: Expression is a valid numeric expression; Digit is an optional numeric value used to indicate
number of digits to the right of the decimal point; LeadingDigit is an optional tristate value to display
a leading zero; Paren is an optional tristate value used to display parentheses around negative values;
and GroupDigit is an option tristate value used to display a number as specified in the group delimiter
settings of the Control Panel's regional settings.
EXAMPLE: ``` =FormatNumber(45.324567, 3)

 1RESULT: 45.325   
 2\-------------------------------------   
 3  
 411\. FormatPercent()   
 5FUNCTION: Returns an expression formatted as a percent value with a trailing percent (%)   
 6SYNTAX: FormatPercent(Expression [, Digit [, LeadingDigit [, Paren [, GroupDigit]]]])   
 7ARGUMENTS: Expression is a valid numeric expression; Digit is an optional numeric value used to indicate   
 8number of digits to the right of the decimal point; LeadingDigit is an optional tristate value to display   
 9a leading zero; Paren is an optional tristate value used to display parentheses around negative values;   
10and GroupDigit is an option tristate value used to display a number as specified in the group delimiter   
11settings of the Control Panel's regional settings.   
12EXAMPLE: ```
13=FormatPercent(0.45267, 3)

RESULT: 45.267%
-------------------------------------

12. Hour()
FUNCTION: Returns a whole number representing the hour of the day between 0 and 23.
SYNTAX: Hour(time)
ARGUMENTS: time is any valid date/time expression.
EXAMPLE: ``` =Hour(#4:45:34 PM#)

 1RESULT: 16   
 2(Hour has been converted to 24-hour system)   
 3\-------------------------------------   
 4  
 513\. Instr()   
 6FUNCTION: Returns the numeric position of the first instance of one string within another.   
 7SYNTAX: Instr([start, ] strToBeSearched, strSearchFor [, compare])   
 8ARGUMENTS: start (optional) is the numeric position to start the string search; strToBeSearched is the   
 9string expression to be searched; strSearchFor is the string expression search value; and compare   
10(optional) is the value indicating the comparison constant.   
11EXAMPLE: ```
12   
13strText = "This is a test!!"   
14pos = Instr(strText, "a")   
15response.write pos   

RESULT: 9
(string "a" is the 9th character in strText)
-------------------------------------

14. InstrRev()
FUNCTION: Returns the numeric position of one string within another starting from the end of the string.
SYNTAX: InstrRev([start, ] strToBeSearched, strSearchFor [, compare])
ARGUMENTS: start (optional) is the numeric position to start the string search; strToBeSearched is the
string expression to be searched; strSearchFor is the string expression search value; and compare
(optional) is the value indicating the comparison constant.
EXAMPLE: ```

strText = "This is a test!!"
pos = InstrRev(strText, "s")
response.write pos

 1RESULT: 13   
 2(string "s" is the 13th character of strText if you search from the end of the strText)   
 3\-------------------------------------   
 4  
 515\. Int()   
 6FUNCTION: Returns the integer portion of a number   
 7SYNTAX: Int(number)   
 8ARGUMENTS: number is any valid numeric expression.   
 9EXAMPLE: ```
10=INT(32.89)

RESULT: 32
(If cINT() is used instead, the result will be 33)

-------------------------------------
16. IsArray()
FUNCTION: Returns a boolean value indicating whether a variable is an array.
SYNTAX: IsArray(name)
ARGUMENTS: name is the variable to be determined.
EXAMPLE: ```

strTest = "Test!"
response.write IsArray(strTest)

 1RESULT: False   
 2\-------------------------------------   
 3  
 417\. IsDate()   
 5FUNCTION: Returns a boolean value indicating whether the expression can be converted to a date.   
 6SYNTAX: IsDate(expression)   
 7ARGUMENTS: expression is any valid expression.   
 8EXAMPLE: ```
 9   
10strTest = "8/4/99"   
11response.write IsDate(strTest)   

RESULT: True
-------------------------------------

18. IsEmpty()
FUNCTION: Returns a boolean value indicating whether a variable has been initialized.
SYNTAX: IsEmpty(expression)
ARGUMENTS: expression is any valid expression.
EXAMPLE: ```

Dim i
response.write IsEmpty(i)

 1RESULT: True   
 2\-------------------------------------   
 3  
 419\. IsNull()   
 5FUNCTION: Returns a boolean value that indicates whether an expression contains no valid datatype.   
 6SYNTAX: IsNull(expression)   
 7ARGUMENTS: expression is any valid expression.   
 8EXAMPLE: ```
 9   
10Dim i   
11response.write IsNull(i)   

RESULT: False
-------------------------------------

20. IsNumeric()
FUNCTION: Returns a boolean value indicating whether an expression can be evaluated as a number.
SYNTAX: IsNumeric(expression)
ARGUMENTS: expression is any valid expression.
EXAMPLE: ```

i = "345"
response.write IsNumeric(i)

1RESULT: True   
2(Even if there are quotation marks around 345, which indicates datatype of string, IsNumeric() function   
3will still try to convert a string to numeric value first)   
4\-------------------------------------
Published At
Categories with Web编程
Tagged with
comments powered by Disqus