一、split拆分字符串
函数调用格式:split(expression,delimiter,count,compare)
参数:
Expression为需要拆分的字符串
Delimiter为字符串中的某个字符,用来识别子串的拆分位置
Count为需要返回的子串的个数,-1意味着返回所有子串
Compare为0时是根据二进制方式匹配,为1时为文本方式匹配
示例:
Dim MyString,MyArray, Msg
MyString = "VBScriptXisXfun!"
MyArray = Split(MyString, "x", -1, 1)
' MyArray(0) contains "VBScript".
' MyArray(1) contains "is".
' MyArray(2) contains "fun!".
Msg = MyArray(0) & " " & MyArray(1)
Msg = Msg & " " & MyArray(2)
MsgBox Msg
二、Date获取当前系统日期
示例:
Dim MyDate
MyDate = Date ' MyDate contains the current system date.
三、Mid截取字符
函数调用格式:mid(string,start,length)
参数:
string为需要截取的字符串
start为开始位置
length为需要截取的长度
示例:
Dim myvar
Myvar = mid(“VBScript”,3,6) ‘myvar为“Script”
四、Time返回当前系统时间
示例:
Dim mytime
mytime = Time
五、CreateObject创建并返回一个自动对象的指针
函数调用格式:CreateObject(servername.typename,location)
参数:
servername为应用对象的名字
typename为需要创建对象的类型
location为将要创建对象所在网络服务器的名字
示例1:
,创建一个Microsoft Excel sheet 对象
Dim ExcelSheet
Set ExcelSheet = CreateObject("Excel.Sheet")
,设置相应属性和方法
' Make Excel visiblethrough the Application object.
ExcelSheet.Application.Visible = True
' Place some text inthe first cell of the sheet.
ExcelSheet.ActiveSheet.Cells(1,1).Value = "This iscolumn A, row 1"
' Save the sheet.
ExcelSheet.SaveAs "C:\DOCS\TEST.XLS"
' Close Excel withthe Quit method on the Application object.
ExcelSheet.Application.Quit
' Release the objectvariable.
Set ExcelSheet = Nothing
示例2: '======================================================= ' 功能名: TestResultLog
' 目的: 将输入成功与否的日志输入到日志文件中
' 输入参数: judgment,UserName
'=======================================================
Sub TestResultLog(judgment,UserName)
Dim strSuccess,strFail,fso,myfile,strTime
strTime="[" & date & "" & mid(time,1,5) & "]"
strSuccess=strTime & " 账户“" & UserName & " 登录成功"
strFail=strTime & " 账户“" & UserName & " 登录失败"
Set fso=CreateObject("Scripting.FileSystemObject")
'判断文件是否存在,如果存在打开,否则创建
If (fso.FileExists("F:\Test_Result_Log\TestResult_log.txt")) Then
'定义常量intCode,作为打开文件函数的参数,防止写入数据是Unicode编码乱码
Const intCode=-1
Set myfile=fso.OpenTextFile("F:\Test_Result_Log\TestResult_log.txt",8,true,intCode)
else
Set myfile=fso.CreateTextFile("F:\Test_Result_Log\TestResult_log.txt",2,true)
End If
If judgment Then
myfile.WriteLine strSuccess
else
myfile.WriteLine strFail
End If
myfile.Close
set myfile=nothing
set fso=nothing
End Sub