Common VBScript Functions

Source: Internet
Author: User
Tags rtrim

From: http://www.cnitblog.com/ffan/archive/2005/08/12/1487.html

 

1. Function Array () 
Function: creates an array variable.
Format: array (list)
Parameter: List is each numeric column in the array variable, separated by commas (,).
Example:
<% I = array ("1", "2", "3") %>
Result: I is assigned as an array.

2. Function CINT () 
Function: converts an expression or another type of variable to an integer (INT)
Format: CINT (expression)
Parameter: expression is a valid expression or variable of other types.
Example:
<%
F = "234"
Response. Write CINT (f) + 2
%>
Result: 236
The CINT () function converts the character "234" to an integer 234. If the expression is null or is invalid, the return value is 0;

CINT (), clng (), csng (), cdbl ()
Function: converts a variable to an integer, long integer, single-precision, or double-precision type.

3. function: creatobject ()

Function: Creates and returns an ActiveX object.
Format: creatobject (obname)
The bname parameter is the object name.
Example:
<%
Set con = server. Createobject ("ADODB. Connection ")
%>
Result:

4. Function CSTR ()
Function: converts an expression or another type of variable to a string)
Format: CSTR (expression)
Parameter: expression is a valid expression or variable of other types.
Example:
<%
S = 3 + 2
Response. Write "the result is:" & CSTR (s)
%>
Result: The CSTR () function converts integer 5 to the "5" character ".

5. function date () 
Function: returns the date of the current system (server ).
Format: Date ()
Parameter: None
Example <% date () %>
Results: 05/10/00
 
6. Function dateadd () 
Function: Calculate a specified time and
Format: dateadd (timeinterval, number, date)
Parameter: timeinterval is the time unit (month, day...); number is the time interval value, and date is the time start point.
Example:
<%
Currentdate = #8/4/99 #
Newdate = dateadd ("M", 3, currentdate)
Response. Write newdate
%> <%
Currentdate = #12:34:45 #
Newdate = dateadd ("H", 3, currentdate)
Response. Write newdate
%>
Result:
11/4/99
3:34:45
Where
"M" = "month ";
"D" = "day ";
If the format is currentdate, then,
"H" = "hour ";
"S" = "Second ";

7. Function datediff ()
Function: calculates the time difference between a specified number of values.
Format: datediff (timeinterval, date1, date2 [, firstdayofweek [, firstdayofyear])
Parameter: timeinterval is the 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 )&_
"Days to Millenium from 8/4/99 ."
%>
Result: There are 150 days to Millenium from 8/4/99.
 
8. function day ()
Function: returns an integer corresponding to a day of a month.
Format: Day (date)
Parameter: date is a valid date expression;
Example <% = Date (#8/4/99 #) %>
Result: 4

9. Function formatcurrency ()
Function: convert to a currency format.
Format: formatcurrency (expression [, digit [, leadingdigit [, Paren [, groupdigit])
Parameter: expression is a valid numeric expression; digit indicates the number of digits after the decimal point; leadingdigit, Paren, groupdigit is any option.
Example <% = formatcurrency (34.3456) %>
Result 34.35

10. Function formatdatetime () 
Function: format a date expression or variable.
Format: formatdatetime (date [, nameformat])
Parameter: date is a valid date expression/variable. nameformat is the constant name of the specified date format.
Example <% = formatdatetime ("08/04/99", vblongdate) %>
Result: Wednesday, August 04,1999
Note:
--------------------------------------------------------------------------------
Description
Return expression, which has been formatted as a date or time.
Syntax
Formatdatetime (date [, namedformat])
The syntax of the formatdatetime function includes the following parameters:

Parameter description
Date is required. The date expression to be formatted.
Namedformat is optional. Indicates the value of the date/time format used. If it is omitted, vbgeneraldate is used.

Set
The namedformat parameter can have the following values:
Constant Value description
Vbgeneraldate 0 displays the date and/or time. If there is a date part, it is displayed as the short date format. If there is a time part, it is displayed as a long time format. If all exist, all parts are displayed.
Vblongdate 1 displays the date in the long date format specified in the computer region settings.
Vb1_date 2 displays the date in the short date format specified in the computer region settings.
Vblongtime 3 displays the time in the specified time format in the computer region settings.
Vb1_time 4 uses the 24-hour format (HH: mm) to display the time.

Description
The following example uses the formatdatetime function to format the expression as a long date type and assign it to mydatetime:
Function getcurrentdate
"Formatdatetime format the date type to the long date type.
Getcurrentdate = formatdatetime (date, 1)
End Function
--------------------------------------------------------------------------------
11. Function isnumeric () 
Function: returns a Boolean value to determine whether the variable is a numeric variable or another variable that can be converted to a number.
Format: isnumeric (expression)
Parameter: expression is an arbitrary variable.
Example:
<%
I = "234"
Response. Write isnumeric (I)
%>
Result: True.
 
12. Function isobject () 
Function: returns a Boolean value to determine whether the variable is an object variable,
Format: isobject (expression)
Parameter: expression is an arbitrary variable.
Example:
<%
Set con = server. creatobject ("ADODB. Connection ")
Response. Write isobject (CON)
%>
Result: True.
 
13. function: lbound () 
Function: returns the lower bound to an array.
Format: lbound (arrayname [, dimension])
Parameter: arrayname is an array variable, and dimension is any item.
Example:
<%
I = array ("1", "2", "3 ")
Response. Write lbound (I)
%>
Result: 0

14. Function lcase () 
Function: converts all characters of a One-character type variable to lowercase characters.
Format: lcase (string)
Parameter: string is a string variable.
Example:
<%
STR = "This is lcase !"
Response. Write lcase (STR)
%>
Result: This is lcase!

15. function left () 
Function: truncates the first part of a string;
Format: Left (string, length)
Parameter: String string, the length of the part intercepted by length.
Example: <% = left ("This is a test !", 6) %>
Result: This I

16. Function Len () 
Function: returns the length of a string or the length of a variable in bytes.
Format: Len (string * varname)
Parameter: String string; any variable name of varname
Example:
<%
Strtest = "this is a test !"
Response. Write left (strtest)
%>
Result: 15
 
17. Function ltrim () 
Function: removes spaces before a string.
Format: ltrim (string)
Parameter: String string.
Example: <% = ltrim ("This is a test !")
Result: this is a test!

18. function mid () 
Function: truncates a string from a string.
Format: Mid (string, start [, length])
Parameter: String string, the start point of start truncation, And the length to be truncated.
Example:
<%
Strtest = "This is a test, today is Monday !"
Response. Write mid (strtest, 17,5)
%>
Result: Today

19. Function minute () 
Function: returns a value, indicating minutes.
Format: minute (time)
Parameter: time is the time variable.
Example lT; % = minute (#12:23:34 #) %>
Result: 23

20. Function month () 
Function: returns a value indicating the month.
Format: Month (time)
Parameter: Time is the date variable.
Example <% = month (#08/09/99) %>
Result: 9

 21. Function monthname ()
Function: returns the string (name) of the month ).
Format: monthname (date [, ABB])
Parameter: date is the date variable. If ABB is set to true, the abbreviation of the month is displayed,
Example:
<% = Monthname (#4/5/99 #) %>
Result: l

22. function now () 
Function: returns the current time and date of the system.
Format: Now ()
Parameter: None
Example:
<% = Now () %>
Result: 8:45:32, 05/10/00

23. function: Replace () 
Function: searches for strings to replace the specified strings.
Format: Replace (strtobesearched, strsearchfor, strreplacewith [, start [, Count [, compare])
Parameter: strtobesearched is a string; strsearchfor is a substring to be searched; strreplacewith is a substring to replace. Start, count, and compare are any options.
Example:
<%
Strtest = "This is an apple ."
Response. Write Replace (strtest, "apple", "orange ")
%>
Result: This is an orange.

24. function right () 
Function: truncates the back part of a string.
Format: Right (string, length)
Parameter: String string, the length of the part intercepted by length.
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 an arbitrary number.
Example:
<%
Randomize ()
Response. Write RND ()
%>
Result: If randomize () is not displayed, a random number is not generated.

26. Function round () 
Function: complete value
Format: round (expression [, numright])
Parameter: expression numeric expression; Any numright option.
Example:
<%
I = 12.33654.
Response. Write round (I)
%>
Result: 12

27. Function rtrim () 
Function: removes spaces after a string.
Format: rtrim (string)
Parameter: string is a string.
Example:
<%
Response. Write rtrim ("This is a test! ")
%>
Result: this is a test!
 
28. Function second () 
Function: returns an integer.
Format: Second (time)
Parameter: Time is a valid time expression;
Example lT ;%= second (#12:28:30 #) %>
Result: 30
 
29. Function strreverse () 
Function: returns the reverse string of the original string.
Format: strreverse (string)
Parameter: string is a string.
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 ()
Parameter: None
Result: 9: 58: 28 AM
 
31. Function trim () 
Function: removes spaces before a string.
Format: trim (string)
Parameter: String string.
Example:
<%
Strtest = "this is a test! "
Response. Write trim (strtest)
%>
Result: this is a test!
 
32. Function ubound ()
Function: returns the upper bound of an array.
Format: ubound (expression [, dimension])
Parameter: expression is an array expression or an array variable, and dimension is any item.
Example:
<%
I = array ("1", "2", "3 ")
Response. Write ubound (I)
%>
Result: 2

33. function: ucase ()
Function: converts all characters of a One-character type variable to uppercase or lowercase characters.
Format: ucase (string)
Parameter: string is a string variable.
Example:
<%
STR = "This is lcase !"
Response. Write lcase (STR)
%>
Result: This is lcase!

34. Function vartype () 
Function: return the constant code (integer) of the variable)
Format: vartype (varname)
Parameter: varname is the name of any type of variable.
Example:
<%
I = 5
Response. Write vartype (I)
%>
Result: 2 (2 indicates an integer. You need to refer to the ASP constant code .)

35. Function weekday () 
Function: returns an integer corresponding to the day of the week.
Format: weekday (date [, firstofweek])
Parameter: date is the date variable, and firstofweek is any option.
Example:
<%
D = #5/9/00 #
Response. Write weekday (d) %>
Result: 3 (3 indicates Tuesday)

 36. Function weekdayname ()
Function: returns a string corresponding to the day of the week.
Format: weekdayname (weekday [, ABB [, firstdayofweek])
Parameter: weekday is the date variable, ABB, and firstdayofweek are any options.
Example:
<%
D = #8/4/99 #
Response. Write weekdayname (d)
%>
Result: Wednesday

 37. Function year () 
Function: returns the year of the date expression.
Format: Year (date)
Parameter: date is a valid date expression.
Example:
<% = Year (#8/9/99 #) %>
Result: 1999
38. Function Mod (): returns the remainder.
Example: 3 mod 2

Result: 1

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.