函数

一、split拆分字符串

函数调用格式:split(expression,delimiter,count,compare)

参数:

Expression为需要拆分的字符串

Delimiter为字符串中的某个字符,用来识别子串的拆分位置

Count为需要返回的子串的个数,-1意味着返回所有子串

Compare为0时是根据二进制方式匹配,为1时为文本方式匹配

示例:

       Dim MyString,MyArray, Msg

                     MyString = "VBScriptXisXfun!" 

                     MyArray = Split(MyString, "x", -11)

                     ' 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

' 目的:             将输入成功与否的日志输入到日志文件中  

' 输入参数:      judgmentUserName

'=======================================================

       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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值