Learning ASP Dynamic Web Page Prerequisites: Commonly used 38 functions

Source: Internet
Author: User
Tags date format array expression time and date time interval trim valid
Dynamic | functions | Web page 1. Function Array ()  
Function: Create an array variable
Format: Array (list)
Parameters: List of each numeric column in an array variable, separated by a comma
Example:
<% i = Array ("1", "2", "3")%>
Result: I was given an array 2. Function CInt ()  
Function: Converts an expression/other type of variable to an integer type (int)
Format: Cint (expression)
Parameter: expression is any valid expression/other type of variable
Example:
<%
F = "234"
Response.Write CINT (f) + 2
%>
Results: 236
function CInt () converts the character "234" to an integer 234. If the expression is empty or invalid, the return value is 0;
3. Function: Creatobject ()  
Function: Creates and returns an ActiveX object.
Format: Creatobject (obname)
Parameter bname is the name of the object
Example:
<%
Set con = Server.CreateObject ("ADODB.") Connection ")
%>
Results:
4. Function CStr ()
Function: Converts an expression/other type of variable to a character type (string)
Format: Cstr (expression)
Parameter: expression is any valid expression/other type of variable
Example:
<%
s = 3 + 2
Response.Write "The result is:" & CStr (s)
%>
Result: the function CStr () converts the integer 5 to the character "5".
5. Function date ()  
Function: Returns the date of the current system (server side)
Format: Date ()
Parameters: None
Example <% date ()%>
Result: 06/13/07
6. Function DateAdd ()  
Function: Calculates a specified time and
Format: DateAdd (timeinterval,number,date)
Parameters: TimeInterval is the time unit (month, day ...); Number is the time interval value, date is the point of origin.
Example:
<%
currentdate = #6/13/07#
Newdate = DateAdd ("M", 3,currentdate)
Response.Write Newdate
%> <%
currentdate = #12:34:45 pm#
Newdate = DATEADD ("h", 3,currentdate)
Response.Write Newdate
%>
Results:
13/6/07
3:34:45 PM
which
"M" = "month";
"D" = "Day";
If the format is currentdate, the
"H" = "Hour";
"S" = "second";
7. Function DateDiff ()  
Function: Calculates a specified time difference for a quantity
Format: DateDiff (Timeinterval,date1,date2[,firstdayofweek[,firstdayofyear]])
Parameters: TimeInterval is a time unit; Date1,date2 is a valid date expression, Firstdayofweek,firstdayofyear is any option.
Example:
<%
FromDate = #8/4/99#
ToDate = #1/1/2000#
Response.Write "There are" & _
DateDiff ("D", Fromdate,todate) & _
"Millenium from 8/4/99."
%>
Results: There are to millenium from 8/4/99.
8. Function Day ()  
Function: Returns an integer value that corresponds to a day of the month
Format: Day (date)
Parameter: date is a valid datetime expression;
Example <% =date (#8/4/99#)%>
Results: 4
9. Function FormatCurrency ()  
Functions: Converting to currency format
Format: formatcurrency (expression [, digit[,leadingdigit[,paren[,groupdigit]]]
Parameter: expression is a valid numeric expression; digit represents the number of digits after the decimal point; Leadingdigit,paren,groupdigit is any option.
Example <%=formatcurrency (34.3456)%>
Result 34.35
10. Function FormatDateTime ()  
Features: Formatting date expressions/variables
Format: FormatDateTime (Date[,nameformat])
Parameter: Date is a valid day expression/variable; NameFormat is the specified date format constant name.
Example <% =formatdatetime ("08/04/99", vbLongDate)%>
Results: Wednesday,august 04,1999
Description
--------------------------------------------------------------------------------
Describe
Returns an expression that has been formatted as a date or time.
Grammar
FormatDateTime (date[, NamedFormat])
The syntax for the FormatDateTime function has the following parameters:

Parameter description
Date required option. The date expression to be formatted.
NamedFormat can be selected. Indicates the value of the date/time format used, and if omitted, uses Vbgeneraldate.


Set up
The NamedFormat parameter can have the following values:
Constant numerical description
Vbgeneraldate 0 Displays the date and/or time. If there is a date part, the section is displayed as a short date format. If there is a time section, the section is displayed in a long time format. If all exist, all parts are displayed.
vbLongDate 1 Displays a date using the long date format specified in the computer locale.
Vbshortdate 2 displays a date using the short date format specified in the computer locale.
Vblongtime 3 Displays the time using the time format specified in the computer locale.
vbShortTime 4 Displays the time using a 24-hour format (hh:mm).

Description
The following example uses the FormatDateTime function to format an expression as a long date and assigns it to Mydatetime:
Function getcurrentdate
The FormatDateTime formats the date type as a long date type.
Getcurrentdate = FormatDateTime (Date, 1)
End Function
--------------------------------------------------------------------------------
<script language=vbs>
For I=0 to 4
Alert ("FormatDateTime" (now, &i&) is: "&formatdatetime (Now,i))
Next
</script>

11. Function IsNumeric ()
Function: Returns a Boolean value that determines whether a variable is a numeric variable or another variable that can be converted to a number.
Format: isnumeric (expression)
Parameter: expression is any variable.
Example:
<%
i= "234"
Response.Write IsNumeric (i)
%>
Result: true.
12. Function IsObject ()
Function: Returns a Boolean value that determines whether a variable is an object,
Format: isobject (expression)
Parameter: expression is any variable.
Example:
<%
Set con =server.creatobject ("adodb.connection")
Response.Write IsObject (Con)
%>
Result: True
13. Function: Lbound ()  
Function: Returns the lower bound of an array.
Format: Lbound (Arrayname[,dimension])
Parameter: Arrayname is an array variable, dimension is any item
Example:
<%
i = Array ("1", "2", "3")
Response.Write LBound (i)
%>
Results: 0
14. Function LCase ()  
Function: Converts the character of a character type variable to all lowercase characters.
Format: Lcase (String)
Parameters: string is a literal variable
Example:
<%
Str= "This is lcase!"
Response.Write Lcase (str)
%>
Result: This is lcase!
15. Function Left ()  
Function: Intercepts the front part of a string;
Format: Left (string,length)
Parameters: string strings, length intercept lengths.
Example: <% =left ("This is a test!", 6)%>
Result: this I
16. Function len ()  
Function: Returns the length of the string or the byte length of the variable
Format: Len (string *varname)
Parameters: string strings; varname arbitrary variable names
Example:
<%
Strtest= "This is a test!"
Response.Write Len (strtest)
%>
Results: 15
17. Function LTrim ()  
Function: Remove the space before the string.
Format: LTrim (String)
Parameters: String Strings.
Example: <% =ltrim ("This is a test!")
Result: This is a test!
18. Function Mid ()  
Function: Intercepts a string from a string.
Format: Mid (String,start [, length])
Parameters: String string, the beginning of the start intercept, length to intercept.
Example:
<%
Strtest= "This are a test, today is monday!"
Response.Write Mid (strtest,17,5)
%>
Result: Today
19. Function minute ()  
Function: Returns a value that represents the minute
Format: Minute (time)
Parameters: Time is a variable
Example lt;% =minute (#12:23:34#)%>
Results: 23
20. Function month ()  
Function: Returns a value indicating the month
Format: Month (time)
Parameters: Time is a date variable
Example <% =month (#08/09/99)%>
Results: 9
21. Function MonthName ()
Function: Returns the string (name) of the month.
Format: MonthName (date [, ABB])
Parameter: Date is the abb=true of the month,
Example:
<% =monthname (#4/5/99#)%>
Result: April
22. Function Now ()  
Function: Returns the current time and date of the system.
Format: Now ()
Parameters: None
Example:
<% =now ()%>
Results: 05/10/00 8:45:32 pm
23. Function: replace ()  
Function: Finds in a string, substituting the specified string.
Format: replace (Strtobesearched,strsearchfor,strreplacewith [, Start[,count[,compare]]])
Parameter: strtobesearched is a string; strSearchFor is the substring being looked for; strReplaceWith is the substring to be substituted. Start,count,compare is any option.
Example:
<%
Strtest= "This is an apple."
Response.Write Replace (strtest, "Apple", "orange")
%>
Result: This is an orange.
24. Function Right ()  
Function: Intercepts the back part of a string
Format: Right (string,length)
Parameters: string strings, length intercept lengths.
Example:
<%
Strtest= "This is a test!"
Response.Write Right (strtest,3)
%>
Result: st!
25. Function rnd ()  
Function: Returns a random value
Format: rnd[(number)]
Parameter: number is any value.
Example:
<%
Randomize ()
Response.Write Rnd ()
%>
Results: One of the 0/1 values, no randomize (), can not produce random numbers.
26. Function round ()  
Function: Full value
Format: Round (Expression[,numright])
Parameters: expression numeric expression; numright any option.
Example:
<%
i=12.33654
Response.Write Round (i)
%>
Results: 12
27. Function RTrim ()
Function: Remove the space after the string.
Format: RTrim (String)
Parameters: string is a literal
Example:
<%
Response.Write RTrim ("This is a test!")
%>
Result: This is a test!
28. Function second ()  
Function: Returns an integer value.
Format: Second (time)
Parameter: Time is a valid temporal expression;
Example lt;% =second (# 12:28:30#)%>
Results: 30
29. Function StrReverse ()  
Function: Returns a string that is in reverse order from the original string.
Format: StrReverse (String)
Parameters: string is a literal
Example <% =strreverse ("This is a test!")
Result:!tset a Si siht
30. Function Time ()  
Function: Returns the time value of the current system.
Format: Time ()
Parameters: None
Result: 9:58:28 Am
31. Function Trim ()  
Function: Delete the string before, after the space.
Format: Trim (String)
Parameters: String Strings.
Example:
<%
Strtest= ' This is a test! "
Response.Write Trim (strtest)
%>
Result: This is a test!
32. Function UBound ()
Function: Returns an upper bound of an array.
Format: Ubound (expression [, dimension])
Parameters: expression is an array expression/array variable, dimension is any item
Example:
<%
i = Array ("1", "2", "3")
Response.Write UBound (i)
%>
Results: 2
33. Function: UCase ()  
Function: Converts the character of a character type variable to uppercase characters.
Format: Ucase (String)
Parameters: string is a literal variable
Example:
<%
Str= "This is lcase!"
Response.Write Lcase (str)
%>
Result: This is lcase!
34. Function VarType ()  
Function: Returns the constant code of a variable (integer)
Format: Vartype (varname)
Parameter: varname is a variable name of any type.
Example:
<%
I=5
Response.Write VarType (i)
%>
Results: 2 (2 for integers, need to refer to ASP constant code.)
35. Function Weekday ()
Function: Returns an integer that corresponds to the day ordinal of a week.
Format: Weekday (date [, Firstofweek])
Parameter: Date is a day variable and Firstofweek is an optional option.
Example:
<%
d= # 5/9/00 #
Response.Write Weekday (d)%>
Results: 3 (3 indicates Tuesday)
36. Function WeekdayName ()  
Function: Returns a string that corresponds to the day of the week.
Format: WeekdayName (Weekday[,abb[,firstdayofweek]])
Parameters: Weekday is a date variable and abb,firstdayofweek is an optional option.
Example:
<%
D = #8/4/99#
Response.Write WeekdayName (d)
%>
Result: Wednesday
37. Function year ()  
Function: Returns the year in which the date expression is located.
Format: Year (date)
Parameter: Date is a valid day expression
Example:
<% =year (#8/9/99#)%>
Results: 1999
38. Function mod ()Function: Take the remainder.
Example: 3 Mod 2
Results: 1

Related Article

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.