欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-03-30 09:56:43
1.array()   function: returns a variant containing an array.   syntax:...
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