There are a lot of built-in functions in ASP. Some are for typecasting, formatting, math, date and string manipulation.
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”) |
|
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. |
|
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: | ||
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”. | |
Date() | ||
FUNCTION: | Returns the current system date. | |
SYNTAX: | Date() | |
ARGUMENTS: | None. | |
EXAMPLE: | <%=Date%> | |
RESULT: | 8/4/99 | |
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”; |
|
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. | |
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 | |
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)%> | |
RESULT: | $34.35 | |
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 | |
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)%> | |
RESULT: | 45.325 | |
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 Panel’s regional settings. | |
EXAMPLE: | <%=FormatPercent(0.45267, 3)%> | |
RESULT: | 45.267% | |
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) |
|
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 the value 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) |
|
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) |
|
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) |
|
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 | |
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 | |
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 | |
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 | |
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) |
|
IsObject() | ||
FUNCTION: | Returns a boolean value indicating whether an expression refers to an automation object. | |
SYNTAX: | IsObject(expression) | |
ARGUMENTS: | expression is any valid expression. | |
EXAMPLE: | <% Set con = Server.CreateObject(“ADODB.Connection”) response.write IsObject(con) %> |
|
RESULT: | True | |
LBound() | ||
FUNCTION: | Returns the base index value for a dimension of any array. | |
SYNTAX: | Lbound(arrayname [, dimension]) | |
ARGUMENTS: | arrayname is the name of any array; dimension is an optional number indicating the dimension to find the lower bound. | |
EXAMPLE: | <% i = Array(“Monday”,”Tuesday”,”Wednesday”) response.write LBound(i) %> |
|
RESULT: | 0 | |
LCase() | ||
FUNCTION: | Returns a string that has been converted into lowercase characters. | |
SYNTAX: | Lcase(string) | |
ARGUMENTS: | string is any valid string expression. | |
EXAMPLE: | <% strTest = “This is a test!” response.write LCase(strTest) %> |
|
RESULT: | this is a test! | |
Left() | ||
FUNCTION: | Returns the number of characters from the left side of a string. | |
SYNTAX: | Left(string, length) | |
ARGUMENTS: | string is any valid string expression; length is the length of characters to return. | |
EXAMPLE: | <% strTest = “This is a test!” response.write Left(strTest, 3) %> |
|
RESULT: | Thi | |
Len() | ||
FUNCTION: | Returns the number of characters in a string or the number of bytes required to store a variable. | |
SYNTAX: | Len(string | varName) | |
ARGUMENTS: | string is any valid string expression; varName is any valid variable name. | |
EXAMPLE: | <% strTest = “This is a test!” response.write Len(strTest) %> |
|
RESULT: | 15 (The total length of strTest is 15 characters) |
|
LTrim() | ||
FUNCTION: | Returns a string without leading spaces. | |
SYNTAX: | LTrim(string) | |
ARGUMENTS: | string is any valid string expression. | |
EXAMPLE: | <% strTest = ” This is a test!” response.write LTrim(strTest) %> |
|
RESULT: | This is a test! | |
Mid() | ||
FUNCTION: | Returns a specified number of characters from a string. | |
SYNTAX: | Mid(string, start [, length]) | |
ARGUMENTS: | string is any valid string expression; start is a numeric character position to begin extraction from; length (optional) is the number of characters to return. | |
EXAMPLE: | <% strTest = “This is a test! Today is Monday.” response.write Mid(strTest, 17, 5) %> |
|
RESULT: | Today | |
Minute() | ||
FUNCTION: | Returns the number of the minutes in current system time. | |
SYNTAX: | Minute(time) | |
ARGUMENTS: | time is any valid time expression. | |
EXAMPLE: | <%=Minute(#12:45:32 PM#)%> | |
RESULT: | 45 | |
Month() | ||
FUNCTION: | Returns the number of the month of the year. | |
SYNTAX: | Month(date) | |
ARGUMENTS: | date is any valid date expression. | |
EXAMPLE: | <%=Month(#08/04/99#)%> | |
RESULT: | 8 | |
MonthName() | ||
FUNCTION: | Returns a string identifying the specified month. | |
SYNTAX: | MonthName(month, [, Abb]) | |
ARGUMENTS: | month is the numeric representation for a given month; Abb (optional) is a boolean value used to display month abbreviation. True will display the abbreviated month name and False (default) will not show the abbreviation. | |
EXAMPLE: | <%=MonthName(Month(#08/04/99#))%> | |
RESULT: | August | |
Now() | ||
FUNCTION: | Returns the current system date and time. | |
SYNTAX: | Now() | |
ARGUMENTS: | None | |
EXAMPLE: | <%=Now%> | |
RESULT: | 8/4/99 9:30:16 AM | |
Replace() | ||
FUNCTION: | Returns a string in which a specified sub-string has been replaced with another substring a specified number of times. | |
SYNTAX: | Replace(strToBeSearched, strSearchFor, strReplaceWith [, start [, count [, compare]]]) | |
ARGUMENTS: | strToBeSearched is a string expression containing a sub-string to be replaced; strSearchFor is the string expression to search for within strToBeSearched; strReplaceWith is the string expression to replace sub-string strSearchFor; start (optional) is the numeric character position to begin search; count (optional) is a value indicating the comparision constant. | |
EXAMPLE: | <% strTest = “This is an apple!” response.write Replace(strTest, “apple”, “orange”) %> |
|
RESULT: | This is an orange! | |
Right() | ||
FUNCTION: | Returns a specified number of characters from the right side of a string. | |
SYNTAX: | Right(string, length) | |
ARGUMENTS: | string is any valid string expression; length is any valid numeric expression representing the number of characters to return. | |
EXAMPLE: | <% strTest = “This is an test!” response.write Right(strTest, 3) %> |
|
RESULT: | st! | |
Rnd() | ||
FUNCTION: | Returns a random number. | |
SYNTAX: | Rnd [ (number) ] | |
ARGUMENTS: | number is any valid numeric expression. | |
EXAMPLE: | <% Randomize() response.write RND() %> |
|
RESULT: | Any number between 0 and 1 (Without Randomize(), the number will not re-generate) |
|
Round() | ||
FUNCTION: | Returns a number rounded to a specified number of decimal places. | |
SYNTAX: | Round(expression [, numRight]) | |
ARGUMENTS: | expression is any valid numeric expression to be rounded; numRight (optional) is any numeric expression used to indicate the number of digits to the right of the decimal point. | |
EXAMPLE: | <% i = 32.45678 response.write Round(i) %> |
|
RESULT: | 32 | |
Rtrim() | ||
FUNCTION: | Returns a copy of a string without trailing spaces. | |
SYNTAX: | Rtrim(string) | |
ARGUMENTS: | string is any valid string expression. | |
EXAMPLE: | <% strTest = “This is a test!! ” response.write RTrim(strTest) %> |
|
RESULT: | This is a test!! | |
Second() | ||
FUNCTION: | Returns the current seconds value of the current system time. | |
SYNTAX: | Second(time) | |
ARGUMENTS: | time is any valid time expression. | |
EXAMPLE: | <%=Second(#12:34:28 PM#)%> | |
RESULT: | 28 | |
StrReverse() | ||
FUNCTION: | Returns a string where the character order has been reversed | |
SYNTAX: | StrReverse(string) | |
ARGUMENTS: | string is any valid string expression | |
EXAMPLE: | <% strTest = “This is a test!!” response.write StrReverse(strTest) %> |
|
RESULT: | !!tset a si sihT | |
Time() | ||
FUNCTION: | Returns the current system time. | |
SYNTAX: | Time() | |
ARGUMENTS: | None. | |
EXAMPLE: | <%=Time%> | |
RESULT: | 9:58:28 AM | |
Trim() | ||
FUNCTION: | Returns a string without leading and trailing spaces. | |
SYNTAX: | Trim(string) | |
ARGUMENTS: | string is any valid string expression. | |
EXAMPLE: | <% strTest = ” This is a test!! ” response.write Trim(strTest) %> |
|
RESULT: | This is a test!! | |
UBound() | ||
FUNCTION: | Returns the largest available subscipt for a dimension of an array. | |
SYNTAX: | Ubound(arrayname [, dimension]) | |
ARGUMENTS: | arrayname is the name of a valid array; dimension (optional) is a number indicating the dimension to find the upper bound. | |
EXAMPLE: | <% i = Array(“Monday”,”Tuesday”,”Wednesday”) response.write UBound(i) %> |
|
RESULT: | 2 (array index starts with 0) |
|
UCase() | ||
FUNCTION: | Returns a string that has been converted to uppercase characters. | |
SYNTAX: | UCase(string) | |
ARGUMENTS: | string is any valid string expression. | |
EXAMPLE: | <% strTest = “This is a test!!” response.write UCase(strTest) %> |
|
RESULT: | THIS IS A TEST!! | |
VarType() | ||
FUNCTION: | Returns the subtype of a variable | |
SYNTAX: | VarType(varName) | |
ARGUMENTS: | varName is the required variable name | |
EXAMPLE: | <% i = 3 response.write varType(i) %> |
|
RESULT: | 2 (2 indicates Integer. Refers to ASP Constants) |
|
WeekDay() | ||
FUNCTION: | Returns a whole number representing the day of the week. | |
SYNTAX: | WeekDay(date [, firstdayofweek]) | |
ARGUMENTS: | date is any valid date expression; firstdayofweek is an optional date constant to assign the first day of week. | |
EXAMPLE: | <% d = #8/4/99# response.write Weekday(d) %> |
|
RESULT: | 4 (4 indicates the fourth of the week, which is Wednesday) |
|
WeekDayName() | ||
FUNCTION: | Returns the specified day of the week. | |
SYNTAX: | WeekDayName(weekday [, Abb [, firstdayofweek]]) | |
ARGUMENTS: | weekday is the numeric representation for the day of the week; Abb is an optional boolean value (if set to true, the weekday name will be abbreviated; if set to false, the full weekday name is displayed); and firstdayofweek is an optional date constant to assign the first day of week. | |
EXAMPLE: | <% d = #8/4/99# response.write WeekdayName(Weekday(d)) %> |
|
RESULT: | Wednesday | |
Year() | ||
FUNCTION: | Returns the current year. | |
SYNTAX: | Year(date) | |
ARGUMENTS: | date is any valid date expression. | |
EXAMPLE: | <%=Year(#8/4/99#)%> | |
RESULT: | 1999 |