一些新学习的VBS知识笔记

一.流程与函数

区别:

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





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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值