VBScript

asp

2008-03-27 14:03

Option Explicit                        必须声明变量
on error resume next            错误继续
dim name                            
dim famname(5)
dim table(4, 6)
const n123=666

If....Then
.....
Else
....
End if

select case a
case 1 ...
case 2 ...
case 3 ...
case else
end select


do while ...
...
loop


for i=0 to 100 [Step 1]
...
next


for each x in names
....
next

sub mySub()
....
end sub


function myFunction(参数,参数)
...
myFunction=返回值
end function

'函数或过程中 的变量如果不定义 将调用全局变量 如果内部定义将是局域变量
Vbscript 时间/日期

Now

Date
Year
Month
MonthName
Day

Time
Hour
Minute
Second

DateAdd                      s m h d n y    w q
DateDiff

Weekday
WeekdayName

------------------------------------------------------------------------------------------------------------------
Vbscript 字符串

------------------------------------------------------------------------------------------------------------------
Vbscript测试,转换,数学

IsArray(): 判断一对象是否为数组,返回布尔值 .

IsDate(): 判断一对象是否为日期,返回布尔值

IsEmpty(): 判断一对象是否初始化,返回布尔值.

IsNull(): 判断一对象是否为空,返回布尔值.

IsNumeric(): 判断一对象是否为数字,返回布尔值.

IsObject(): 判断一对象是否为对象,返回布尔值.

CStr():
转化一个表达式为字符串.

CBool, CByte,CDate,CDbl, CInt,CLng, CSng, CStr

LBound 函数下
UBound 函数上

随机数
Randomize
Rnd()
Abs()            绝对值
Round(pi, 2
) 四舍五入
Int、Fix           负数 下 上取整
Sgn(number)            1 0 -1

TypeName("VBScript")   ' 返回 "String"
TypeName(4)            ' 返回 "Integer"



------------------------------------------------------------------------------------------------------------------

B(返回字节数)

Asc, AscB, AscW                                     Asc("A")      '返回 65

Chr, ChrB, ChrW                                      'Chr(65)    '返回 A

InStr                                                        'instr([N,]STR1,STR2) 在str1中寻找str2第一次出现的位置
InStrB                                                        '而是字节位置
InStrRev                                                    '逆向查找

Join                                                            'Join(数组[,分割符])       默认空格
Len, LenB                                                   '字符长度 汉字也是1

LCase
, 小
UCase,大            

Left
, LeftB                         
Right, RightB                 
Mid, MidB                                                     'Mid("VB脚本is fun!", 4, 6) "is fun"

Replace(str,a,b)                                         'a替换b
Split                                                            'array = Split(MyString, "//")

LTrim,RTrim.Trim
              

Space(10)                                              ' 返回具有 10 个空格的字符串。

StrReverse                                              '相反顺序排列字符串

String(5, "*")                                            ' 返回"*****"

StrComp         

Filter
Dim MyIndex
Dim MyArray (3)
MyArray(0) = "Sunday"
MyArray(1) = "Monday"
MyArray(2) = "Tuesday"
MyIndex = Filter(MyArray, "Mon") 'MyIndex(0) 包含 "Monday"