欢迎光临
我们一直在努力

ASP中的函数应用方法及应用举例(一)-ASP教程,ASP应用

建站超值云服务器,限时71元/月

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
%>
  result: creates an array contains 7 elements:
myarray(“sunday”,”monday”, … … “saturday”)
————————————-
  
2. cint()
  function: returns an expression that has been converted to an interget subtype.
  syntax: cint(expression)
  arguments: expression is any valid expression
  example: <%
f = “234”
response.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”)
%>
  result:  
————————————-
  
4. cstr()
  function: returns an expression that has been converted to a variant of subtype string.
  syntax: cstr(expression)
  arguments: expression is any valid expression
  example: <%
s = 3 + 2
response.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%>
  result: 8/4/99
————————————-
  
6. dateadd()
  function: returns a date to which a specific time interval has been added.
  syntax: dateadd(timeinterval,number,date)
  arguments: timeinterval is the time interval to add; number is amount of time intervals to add; and date
is the starting date.
  example: <%
currentdate = #8/4/99#
newdate = dateadd(“m”,3,currentdate)
response.write newdate
%>

<%
currentdate = #12:34:45 pm#
newdate = dateadd(“h”,3,currentdate)
response.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.”
%>
  result: there are 150 days to millenium from 8/4/99.
————————————-
  
8. day()
  function: returns a whole number representing the day of the month.
  syntax: day(date)
  arguments: date is any valid date expression.
  example: <%=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 panels regional settings.
  example: <%=formatcurrency(34.3456)%>
  result: $34.35
————————————-
  
10. formatdatetime()
  function: returns an expression formatted as a date or time.
  syntax: formatdatetime(date, [, namedformat])
  arguments: date is any valid date expression, and namedformat is an optional date/time constant.
  example: <%=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 panels regional settings.
  example: <%=formatnumber(45.324567, 3)%>
  result: 45.325
————————————-
  
11. formatpercent()
  function: returns an expression formatted as a percent value with a trailing percent (%)
  syntax: formatpercent(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 panels regional settings.
  example: <%=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#)%>
  result: 16
(hour has been converted to 24-hour system)
————————————-
  
13. instr()
  function: returns the numeric position of the first instance of one string within another.
  syntax: instr([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 thevalue indicating the comparison constant.
  example: <%
strtext = “this is a test!!”
pos = instr(strtext, “a”)
response.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
%>
  result: 13
(string “s” is the 13th character of strtext if you search from the end of the strtext)
————————————-
  
15. int()
  function: returns the integer portion of a number
  syntax: int(number)
  arguments: number is any valid numeric expression.
  example: <%=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)
%>
  result: false
————————————-

17. isdate()
  function: returns a boolean value indicating whether the expression can be converted to a date.
  syntax: isdate(expression)
  arguments: expression is any valid expression.
  example: <%
strtest = “8/4/99”
response.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)
%>
  result: true
————————————-
  
19. isnull()
  function: returns a boolean value that indicates whether an expression contains no valid datatype.
  syntax: isnull(expression)
  arguments: expression is any valid expression.
  example: <%
dim i
response.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)
%>
  result: true
(even if there are quotation marks around 345, which indicates datatype of string, isnumeric() function
will still try to convert a string to numeric value first)

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » ASP中的函数应用方法及应用举例(一)-ASP教程,ASP应用
分享到: 更多 (0)

相关推荐

  • 暂无文章