VBScript函数摘要

3 篇文章 0 订阅
  
1.abs()
功能:返回绝对值
2.array()
功能:创建一个数组变量
语法: array(list)
例:
a=array(10,20,30) ’数组 a的值被赋为(10,20,30)
b=a(2)    ’b=30
3.asc()
功能:返回字符串第一个字母的 ASCII码
例:
asc(“Apple”) ’返回 65
4.cdate()
功能:将字符串转换成日期
例:
MyDate=cdate(“October 1,2004”)
 
5.chr()
功能:将一个 ASCII码转换成字符
例:
chr(65) ’返回字符“ A”
6.cint()
功能:将一表达式或其它类型的变量转换成整型
语法: cint(expression)
例:
f= cint(” 234”) ’f=234
7.creatobject()
功能:创建并返回一个 ActiveX对象.
语法: CreatObject(obname)
例:
<%
set  cn = Server.CreateObject(“ADODB.Connection”)
%>
8.cstr()
功能:将一表达式或其它类型的变量转换成字符串类型
语法: cstr(expression)
例:
<%
s  = 3 + 5
response.write ” The result is: ” & cStr(s)
%>
’打印出字符串 ” The result is: 8”
9.date()
功能:返回当前系统 (server端)日期
例:
<%  date() %>
可能的返回值是 12/14/04
10.dateadd()
功能:计算某个指定的时间和
语法: dateadd(timeinterval,number,date)
参数: timeinterval是时间单位(月,日..),number是时间间隔值,date是时间起始点
例:
<%
currentDate  = #8/4/04#
newDate  = DateAdd(“m”,3,currentDate)
response.write  newDate
%>
结果为11/4/04
11.datediff()
功能:计算两个指定时间的差
语法: datediff(timeinterval,date1,date2[,firstdayofweek[,firstdayofyear]])
参数: timeinterval是时间单位,date1、date2是有效的日期表达式,firstdayofweek、 firstdayofyear是任意选项
例:
<%
fromDate  = #8/4/99#
toDate  = #1/1/2000#
response.write ” There are ” & _
DateDiff(“ d”,fromDate,toDate) & _
“ days to millenium from 8/4/99”
%>
结果为: There are 150 days to millenium from 8/4/99
12.datepart()
功能:返回给定日期的特定部分
例:
yearPart=datepart(“yyyy”,”31-dec-2004”)          ’yearPart值为 2004
monthPart=datepart(“m”,”31-dec-2004”)          ’monthPart值为 12
dayPart=datepart(“d”,”31-dec-2004”)          ’dayPart值为 31
13.day()
功能:返回一个整数值 ,对应于某月的某日
语法: day(有效的日期表达式)
例:
<%  =date(#9/16/04#) %>
结果为 16
14.formatcurrency()
功能:转换成货币格式
语法: formatcurrency(expression [,digit[,leadingdigit[,paren[,groupdigit]]]])
其中: expression 是有效的数字表达式,digit表示小数点后的位数。Leadingdigit,parten,groupdigit是任意选项
例:
<%=FormatCurrency(34.3456)%>
结果为 34.35
15.formatdatetime()
功能:格式化日期表达式
语法: formatdatetime(date[,nameformat])
其中: date为有效的日期表达式,nameformat是指定的日期格式常量名称
例:
newdate=now
formatdatetime(newdate,0)       ’返回“ 04-12-31 下午06:30:31”
formatdatetime(newdate,1)       ’返回“ 2004年12月31日”
formatdatetime(newdate,2)       ’返回“ 04-12-31”
formatdatetime(newdate,3)       ’返回“下午 06:30:31”
formatdatetime(newdate,4)       ’返回“ 18:30”
说明:
NamedFormat为可选项。如果省略,则使用  vbGeneralDate
NamedFormat 参数可以有以下值
vbGeneralDate  0 显示日期和/或时间。如果有日期部分,则将该部分显示为短日期格式。
如果有时间部分,则将该部分显示为长时间格式。如果都存在,则显示
所有部分
vbLongDate      1 使用计算机区域设置中指定的长日期格式显示日期
vbShortDate   2 使用计算机区域设置中指定的短日期格式显示日期
vbLongTime     3 使用计算机区域设置中指定的时间格式显示时间
vbShortTime   4 使用24小时格式(hh:mm)显示时间
16.inputbox()
功能:在对话窗口中显示提示等待输入
语法: inputbox(prompt[,title][,default][,helpfile,context])[,xpos][ypos]
例:
input=inputbox(“Enter your name”)
msgbox(“Your name is”& input)
17.int(),fix()
功能:取整数部分
例:
int(99.8)             ’返回 99
fix(99.8)             ’返回 99
int(-99.8)            ’返回 -100
fix(-99.8)            ’返回 -99
int(-99.2)            ’返回 -100
fix(-99.2)            ’返回 -99
18.isdate()
功能:测试表达式是否为日期
语法: isdate(expression)
例:
date1=”October 1,2004”
date2=#10/1/2004#
date3=”window”
check1=isdate(date1)           ’返回 true
check2=isdate(date2)           ’返回 true
check3=isdate(date3)           ’返回 false
19.isnumeric()
功能:返回一个布尔值 ,判断变量是否为数字变量,或者是可以转换成数字的其它变量
语法: isnumeric(expression)
其中: expression可以是任意变量
例子:
i=“ 234”
check=isnumeric(i)    ’返回 true
20.isobject()
功能:返回一个布尔值 ,判断变量是否为对象变量
语法: isobject(expression)
其中: expression 可以是任意变量
例:
<%
set  cn =server.creatobject(“adodb.connection”)
response.write  isobject(cn)
%>
结果为 true
21.lbound() ,ubound()
功能:返回一个数组的下界和上界
语法: lbound(arrayname[,dimension])
ubound(arrayname[,dimension])
其中: arrayname是数组变量,dimension是任意项
例:
Dim A(3,4)             
lbound(A,1)               ’返回 0,第1维的起始序号
ubound(A,1)               ’返回 3,第1维的结束序号
lbound(A,2)               ’返回 0,第2维的起始序号
ubound(A,2                ’返回 4,第2维的结束序号
22.lcase()
功能:将一字符串变换成小写字符串
语法: lcase(string)
例:
<% 
str=“ THIS is Lcase!”
response.write  Lcase(str)
%>
结果为: this is lcase!
23.left()  
功能:截取一个字符串的左边部分
语法: left(string,length)
其中: string字符串,length截取的长度
例:
left(“ this is a test!”,4)    ’返回this
24.len()
功能:返回字符串长度
语法: len(string)
例:
<% 
strtest=“ this is a test!”
response.write  len(strtest)
%>
结果为 15 
25.ltrim() 、rtrim()、trim()
功能: ltrim()去掉字符串前的空格
rtrim()去掉字符串后的空格
trim()去掉字符串前、后的空格
例:
ltrim  (“ this is a test!”)    ’返回“this is a test!”
26.mid()
功能:从字符串中截取子字符串
语法: mid(string,start[,length])
其中: string字符串,start截取的起点,length要截取的长度
例:
<% 
strtest=“ this is a test, This is a book.”
response.write  mid(strtest,17,5)
%>
结果为 This
27.minute()
功能:返回分钟数
语法: minute(time)
其中 time为时间变量
例:
minute(#10:28:36#)        ’返回 28
28.month()
功能:返回月份
语法: month(time)
其中: time是日期变量
例:
month(#08/09/04#)        ’返回8
29.monthname()
功能:返回月份的字符串表示
语法: monthname(date [,abb])
其中: date是日期变量,abb=true时 则月份用缩写
例:
monthname(#4/5/04#)         ’返回 April
30.now()
功能:返回系统的当前时间和日期
语法: now()
说明:无参数
例:
<%  =now() %>
可能的结果为 12/24/04 8:45:32 am
31.replace()
功能:在字符串中查找 ,替代指定的子字符串
语法: replace(strtobesearched,strsearchfor,strreplacewith [,start[,count
[,compare]]])
其中: strtobesearched是字符串,strsearchfor是要查找的子字符串,
strreplacewith 是用来替代的子字符串, start、count、compare是任意选项
例:
<% 
strtest=“ this is an apple.”
response.write  replace(strtest,”apple”,”orange”)
%>
结果为 this is an orange
32.right()
功能:截取一个字符串的右边部分
语法: right(string,length)
其中: string字符串,length截取的长度
例:
<% 
strtest=“ this is a test!”
response.write  right(strtest,5)
%>
结果为 test!
33.rnd()
功能:返回一个 0~1之间的随机小数
格式: rnd[(number)]
其中: number是任意数值
 例子 :
 <%
 randomize()
 response.write  rnd()
 %>
 结果返回一个 0~1之间的随机小数,若没有 randomize(),则不能产生随机数
34.round()
功能:完整数值
语法: round(expression[,numright])
其中: expression数字表达式,numright任意选项
例:
<% 
i=12.1234
response.write  round(i,3)
%>
结果为 12.123
35.rtrim()
功能:去掉字符串右边的空格
语法: rtrim(string)
例:
<% 
response.write  rtrim(“this is a test! ”)
%>
结果为“ this is a test!”
36.second()
功能:返回秒数
语法: second(time)
其中: time是一个有效的时间表达式
例:
<%  =second(#10:28:36#) %>
结果为 36
37.strreverse()
功能:返回与原字符串排列逆向的字符串
语法: strreverse(string)
例:
<%  =strreverse(“this is a test!”)
结果为 !tset a si siht
38.time()
功能:返回当前系统的时间值
语法 time()
说明:无参数
例:
<%=time()%>
可能的结果为 9:28:88 am 
39.trim()
功能:删去字符串前、后的空格
语法: trim(string)
例:
<% 
strtest=“  this is a test! ”
response.write  trim(strtest)
%>
结果为“ this is a test!”
40.ubound()
功能:返回一个数组的上界
语法: ubound(expression [,dimension])
其中: expression是数组表达式,dimension是任意项
例:
Dim A(3,4)
Ubound(A,1)               ’返回 3,第1维的上界
Ubound(A,2)               ’返回 4,第2维的上界
41.ucase()
功能:将一字符类型变量的字符全部变换成大写字符
例:
<%
str=“ THIS is Ucase!”
response.write  ucase(str)
%> 
结果为 THIS IS UCASE!
42.vartype()  
功能:返回变量的类型代码
语法: Vartype(varname)
其中: varname是任何类型的变量名称
例:
<%
i=5
response.write  vartype(i)               ’返回2
response.write  vartype(#12/12/04#)      ’返回7
response.write  vartype(“a string”)    ’返回8
%>
43.weekday()
功能:返回一个整数 ,代表一周中的第几天
语法: weekday(date [,firstofweek])
其中: date为日期变量,firstofweek为任选项
例:
<% 
d=#12/24/04#
response.write  weekday(d)
%>
结果为 5(表示星期五)
44.weekdayname()
功能:返回字符串,表示星期几
语法: weekdayname(weekday[,abb[,firstdayofweek]])
其中: weekday为日期变量,abb,firstdayofweek为任选项
例:
<%
d=#12/24/04#
response.write  weekdayname(d)
%>
结果为 Friday
45.year()
功能:返回日期表达式中的年份
语法: year(date)
其中: date是有效的日期表达式
例:
<%=year(#9/9/76#)  %>
结果为 1976
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值