加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Built-In Functions of VB Script

发布时间:2020-12-16 22:38:19 所属栏目:大数据 来源:网络整理
导读:'1)Abs Function 'Returns the absolute value of a number Dim VNum VNum = Abs(-123.44) MsgBox VNum '2)ArrayFunction '返回包含在一个数组里的变量值 Dim anyA anyA = Array("V1","V2","V3") MsgBox anyA(0) '在过程级中声明动态数组变量并分配或重新分
'1)Abs Function 'Returns the absolute value of a number Dim VNum VNum = Abs(-123.44) MsgBox VNum '2)ArrayFunction '返回包含在一个数组里的变量值 Dim anyA anyA = Array("V1","V2","V3") MsgBox anyA(0) '在过程级中声明动态数组变量并分配或重新分配存储空间。 ReDim A(5) A(4)="ReAllot" MsgBox A(4) '3)Asc Function '返回字母的 ANSI 码 'Dim VNum VNum=Asc("A") msgbox VNum '4)Chr Function '返回与指定的 ANSI 字符代码相对应的字符。 Dim Vchar Vchar = Chr(65) MsgBox Vchar '5)DateDiff Function 'Return the number of intervals between two dates. Dim Date1,Date2,x Date1 = #10-10-09# Date2 = #10-10-11# x= DateDiff("yyyy",Date1,Date2)'Difference in Years MsgBox x Date1 = #10-10-09# Date2 = #10-10-11# x= DateDiff("q",Date2)'Difference in Qarters MsgBox x Date1=#10-10-09# Date2=#10-10-11# x=DateDiff("m",Date2) Msgbox x 'Differnce in Months Date1=#10-10-09# Date2=#10-10-11# x=DateDiff("w",Date2) Msgbox x 'Differnce in weeks Date1=#10-10-09# Date2=#10-10-11# x=DateDiff("d",Date2) Msgbox x 'Differnce in days Date1=#10-10-09# Date2=#10-10-11# x=DateDiff("h",Date2) Msgbox x 'Differnce in Hours Date1=#10-10-09# Date2=#10-10-11# x=DateDiff("n",Date2) Msgbox x 'Differnce in Minutes Date1=#10-10-09# Date2=#10-10-11# x=DateDiff("s",Date2) Msgbox x 'Differnce in Seconds Date1=#10-10-09# Date2=#10-10-11# x=DateDiff("y",Date2) Msgbox x 'Differnce in day of years Date1=#10-10-09# Date2=#10-10-11# x=DateDiff("a",Date2) Msgbox x 'Error Date1=#10-10-09# Date2=#10-10-11# x=DateDiff(Date1,Date2) Msgbox x 'Error '6)Hour Function '返回 0 到 23 之间的一个整数(包括 0 和 23),代表一天中的某一小时 Dim MyTime,MyHour MyTime = Now MyHour = Hour(MyTime) ' MyHour 包含 ' 代表当前时间的数值。 MsgBox MyHour '7)Join Function '返回字符串值,其中包含了连接到一起的数组的所有元素,元素由指定的分隔符分隔开来。 Dim mystring,myarray(3) myarray(0)="Lundun *" myarray(1)="bali " myarray(2)="shanghai" mystring=Join(MyArray) msgbox mystring '8)Time Function '返回 Date 子类型 Variant,指示当前系统时间。 Dim MyTime MyTime = Time MsgBox MyTime '9)VarType Function '仅当类型库包含以下常数定义,且在您的工程文件中已经显式引用该类型库后,才允许使用这些常数。对于 VBScript,必须在代码中显式声明这些常数。 Dim x,y x=100 y=VarType(x) Msgbox y '2 (Integer) x="Hyderabad" y=VarType(x) Msgbox y '8 (String) x=#10-10-10# y=VarType(x) Msgbox y '7(Date format) x=100.56 y=VarType(x) Msgbox y ' 5(Double) y=VarType(a) Msgbox y '0 (Empty) Set x =CreateObject("Scripting.FileSystemObject") y=VarType(x) Msgbox y '9(Automation Object) '10)Mid Function '从字符串中返回指定数目的字符。 Mid(string,start[,length]) '参数 string '字符串表达式,从中返回字符。如果 string 包含 Null,则返回 Null。 Start 'string 中被提取的字符部分的开始位置。如果 start 超过了 string 中字符的数目,Mid 将返回零长度字符串 ("")。 Length '要返回的字符数。如果省略或 length 超过文本的字符数(包括 start 处的字符),将返回字符串中从 start 到字符串结束的所有字符。 '说明 '要判断 string 中字符的数目,可使用 Len 函数。 ' 下面的示例利用 Mid 函数返回字符串中从第四个字符开始的六个字符: Dim MyVar 'MyVar = Mid("VB脚本is fun!",4,6) 'MyVar 包含 "Script"。 '注意 MidB 函数与包含在字符串中的字节数据一起使用。其参数不是指定字符数,而是字节数。 '11)Timer Function '返回午夜 12 时以后已经过去的秒数 Function myTime(N) Dim StartTime,EndTime StartTime = Timer For i = 1 To N Next EndtIime = Timer myTime = EndTime - StartTime msgbox myTime End Function Call myTime(2000) '12) isNumeric Function Dim MyVar,MyCheck MyVar = 53 '赋值。 MyCheck = IsNumeric(MyVar) ' 返回 True。 MyVar = "459.95" ' 赋值。 MyCheck = IsNumeric(MyVar) ' 返回True。 MyVar = "45 Help" ' 赋值。 MyCheck = IsNumeric(MyVar) ' 返回 False。 '13)strComp 'It compares two strings based on ASCII Values and Returens -1 (1st less than 2nd ),0 (Equal) and 1 (1st greater than 2nd) Dim x,y x="cd": y="bcd" comp=strcomp(x,y) msgbox comp '14) Replace 'It replace a sub string with given value (another sub string) mystring=Replace("kb script","k","v") msgbox mystring

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读