您的位置:首页 > 编程语言 > VB

一些新学习的VBS知识笔记

2015-09-09 18:11 260 查看
一.流程与函数

区别:

Sub无返回值;

Function有返回值;

示例:

Sub tian(a)
msgbox a
End Sub

tian "Hello World!"
Function tian2(a)
tian2 = a - 3
End Function

MsgBox tian2(4)


二.把字符串分成数组

split,可以把有规律的字符串转为数组

MyString ="VBScriptXisXfun!"
MyArray =Split(MyString, "x", -1, 1)
Msg =MyArray(0)&" "&MyArray(1)&" "&MyArray(2)
MsgBox Msg


三.判断今天星期几
weekday(date),返回值为整数。

周一时返回2,周二时返回3,周六时返回7,周日时返回1。

四.判断文件和文件夹是否存在

fso.fileExists与fso.folderExists

例:

Set fso=CreateObject("Scripting.FileSystemObject")
msgbox fso.fileExists("C:\Users\Administrator\Desktop\test.vbe")
If fso.fileExists("C:\Users\Administrator\Desktop\test.vbe") Then
msgbox "存在"
else
msgbox "不存在"
end if
Set fso=CreateObject("Scripting.FileSystemObject")
msgbox fso.folderExists("C:\Users\Administrator\Desktop")
If fso.fileExists("C:\Users\Administrator\Desktop") Then
msgbox "存在"
else
msgbox "不存在"
end if


五.保留几位小数,当然也可以直接取整

取整的话是Round(pi, 0),后方的数决定几位小数。

Dim MyVar, pi
pi =3.14159
MyVar =Round(pi, 2) 'MyVar contains 3.14。


六.判断当前是当天第几秒

timer

貌似一般用于查看程序花多长时间

例:

Dim StartTime, EndTime
StartTime =Timer
For I =1 To 10000000
Next
EndTime =Timer
TimeIt =EndTime - StartTime
MsgBox TimeIt
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: