VBScript set of functions

Source: Internet
Author: User
Tags date format array expression functions variable time interval valid
vbscript| function 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: 05/10/00
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 = #8/4/99#
Newdate = DateAdd ("M", 3,currentdate)
Response.Write Newdate
%> <%
currentdate = #12:34:45 pm#
Newdate = DATEADD ("h", 3,currentdate)
Response.Write Newdate
%>
Results:
11/4/99
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
--------------------------------------------------------------------------------
 

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.writ



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.