VBScript Application


'========
'显示声明变量
'========
option explicit

'Example
'Call ExampleOne(0)
'ExampleOne 10

dim value
value = 10
'msgbox "Example Two " & ExampleTwo(value) & " Value " & value &  " Example Three " & ExampleThree(value) & " Value " & value 

rem call ExampleFour
call ExampleFive

Rem ========
Rem 过程
Rem ========
sub Example
'========
'声明变量
'========
dim a,b
a = 10
b = 10
'========
'条件
'========
if a eqv b then
msgbox "equal"
end if
a = 5
if a < b then
msgbox "than"
end if
b = 1
if a > b then
msgbox "greate"
end if
'========
'条件
'========
dim j
j = 2
select case j
case "0"
msgbox 0
case else
msgbox "not null"
end select
'============
'循环
'============
dim i
for i = 0 to 3 step 1
msgbox i
next
'============
'循环
'============
i = 0
while i < 3
msgbox i
i = i + 1
wend
'============
'循环
'============
i = 0
do
msgbox "First Loop " & i
if i = 2 then
exit do
end if
i = i + 1
loop while i < 4
i = 3
do until i < 0
msgbox "Second Loop " & i
if i = 2 then
exit do
end if
i = i - 1
loop
'========
'常量
'========
const PI = 3.1415926
msgbox "PI is " & PI
end sub
'========
'过程
'========
Function ExampleOne (i)
msgbox i
end function
Function ExampleTwo(Byval i)
i = i + 100
ExampleTwo = i
end function
Function ExampleThree(ByRef i)
i = i + 100
ExampleThree = i
end function

Sub ExampleFour
'========
'Dictionary和循环
'========
dim dic,week
Set dic = CreateObject("Scripting.Dictionary")
dic.add "1","Monday"
dic.add "2","Tuesday"
dic.add "3","Wednesday"
dic.add "4","Thursday"
dic.add "5","Friday"
dic.add "6","Saturday"
if not dic.Exists("7") then
dic.add "7","Sunday"
end if
for each week in dic
msgbox week & dic(week)
next
dim i,wk,wi
wk = dic.Keys
wi = dic.Items
for i = 0 to dic.Count step 1
if dic.Count = i then exit for
msgbox wk(i) & wi(i)
next
end sub

sub ExampleFive
'========
'FileSystemObject
'========
dim fs,ts,f,folder,folders
dim path,fn
rem 创建一个文件系统对象
Set fs = CreateObject("Scripting.FileSystemObject")
rem 输入一个路径
path = inputbox("Please Input a Path","Get a Path","D:/Temp/Script")
rem 输入一个文件名
fn = inputbox("Please Input a Path","Get a Path","testfile.txt")
rem 根据路径和文件名,判读该文件是否已经存在
if not fs.FileExists(fs.BuildPath(path,fn)) then
rem 如果不存在就创建
set ts = fs.CreateTextFile(fs.BuildPath(path,fn),True)
rem 向文件写数据
ts.WriteLine("test")
rem 关闭文件流
ts.close
else
rem 如果存在就删除
fs.DeleteFile fs.BuildPath(path,fn),True
end if
rem 判读文件夹是否存在
if not fs.FolderExists(fs.BuildPath(path,"test")) then
rem 不存在,就创建
fs.CreateFolder(fs.BuildPath(path,"test"))
else
rem 存在,就删除
fs.DeleteFolder fs.BuildPath(path,"test"), True
end if
rem 显示路径的叶子
msgbox "Base Name " & fs.GetBaseName(path)
rem 显示路径的驱动
msgbox "Drive is " & fs.GetDrive(fs.GetDriveName(fs.GetAbsolutePathName(path)))
rem 显示绝对路径
msgbox "Absolute Pathe Name " & fs.GetAbsolutePathName(path)
msgbox "Drive Name " & fs.GetDriveName(path)
msgbox "Extension Name " & fs.GetExtensionName(fn)
end sub

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值