ASP進階學習:VBscrpt函數大全

來源:互聯網
上載者:User
函數|函數

Array()

函數返回一個數組
運算式 Array(list)
允許資料類型: 字元,數字均可
執行個體:


 
<%
Dim myArray()
For i = 1 to 7
Redim Preserve myArray(i)
myArray(i) = WeekdayName(i)
Next
%>

返回結果: 建立了一個包含7個元素的數組myArray
myArray("Sunday","Monday", ... ... "Saturday")

CInt()

函數將一個運算式轉化為數字類型

運算式 CInt(expression)

允許資料類型: 任何有效字元均可

執行個體:

<%
f = "234"
response.write cINT(f) + 2
%>

返回結果: 236

轉化字元"234"為數字"234",如果字串為空白,則返回0值

CreateObject()

函數建立和返回一個登入的ACTIVEX組件的執行個體。

運算式 CreateObject(objName)

允許資料類型: objName 是任何一個有效、登入的ACTIVEX組件的名字.

執行個體:

<%
Set con = Server.CreateObject("ADODB.Connection")
%>

CStr()

函數轉化一個運算式為字串.

運算式 CStr(expression)

允許資料類型: expression 是任何有效運算式。

執行個體:


 
<%
s = 3 + 2
response.write "The 返回結果 is: " & cStr(s)
%>

返回結果: 轉化數字“5”為字元“5”。

Date()

函數返回當前系統日期.

運算式 Date()

允許資料類型: None.

執行個體:

<%=Date%>

返回結果: 9/9/00

DateAdd()

函數返回一個被改變了的日期。

運算式 DateAdd(timeinterval,number,date)

允許資料類型:
timeinterval is the time interval to add;
number is amount of time intervals to add;
and date is the starting date.

執行個體:


 
<%
currentDate = #9/9/00#
newDate = DateAdd("m",3,currentDate)
response.write newDate
%>
<%
currentDate = #12:34:45 PM#
newDate = DateAdd("h",3,currentDate)
response.write newDate
%>

返回結果: 9/9/00

3:34:45 PM

"m" = "month";

"d" = "day";

If currentDate is in time format then,

"h" = "hour";

"s" = "second";

DateDiff()

函數返回兩個日期之間的差值。

運算式 DateDiff(timeinterval,date1,date2 [, firstdayofweek [, firstweekofyear]])

允許資料類型: timeinterval 表示相隔時間的類型,如“M“表示“月”。

執行個體:

<%
fromDate = #9/9/00#
toDate = #1/1/2000#
response.write "There are " & _
DateDiff("d",fromDate,toDate) & _
" days to millenium from 9/9/00."
%>

返回結果: 從9/9/00 到2000年還有 150 天.

Day()

函數返回一個月的第幾日 .

運算式 Day(date)

允許資料類型: date 是任何有效日期。

執行個體:

<%=Day(#9/9/00#)%>

返回結果: 4

formatCurrency()

函數返回運算式,此運算式已被格式化為貨幣值

運算式 formatCurrency(Expression [, Digit [, LeadingDigit [, Paren [, GroupDigit]]]])

允許資料類型: Digit 指示小數點右側顯示位元的數值。預設值為 -1,指示使用的是電腦的地區設定; LeadingDigit 三態常數,指示是否顯示小數值小數點前面的零。

執行個體:

<%=formatCurrency(34.3456)%>

返回結果: $34.35

formatDateTime()

函數返回運算式,此運算式已被格式化為日期或時間

運算式 formatDateTime(Date, [, Namedformat])

允許資料類型: Namedformat 指示所使用的日期/時間格式的數值,如果省略,則使用 vbGeneralDate.

執行個體:

<%=formatDateTime("09/9/00", vbLongDate)%>

返回結果: Sunday, September 09, 2000

formatNumber()

函數返回運算式,此運算式已被格式化為數值.

運算式 formatNumber(Expression [, Digit [, LeadingDigit [, Paren [, GroupDigit]]]])

允許資料類型: Digit 指示小數點右側顯示位元的數值。預設值為 -1,指示使用的是電腦的地區設定。; LeadingDigit i指示小數點右側顯示位元的數值。預設值為 -1,指示使用的是電腦的地區設定。; Paren 指示小數點右側顯示位元的數值。預設值為 -1,指示使用的是電腦的地區設定。; GroupDigit i指示小數點右側顯示位元的數值。預設值為 -1,指示使用的是電腦的地區設定。.

執行個體:

<%=formatNumber(45.324567, 3)%>

[1] [2] 下一頁  



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.