dim 用于定义变量
const 用于定义常量
’或 rem 用于注释代码
运算符 + - * / ^ mod int()
and 与 or 并列关系
条件判断语句
dim a,b
a=14
b=3
if a>b then
msgbox "True"
end if
条件判断语句高级
dim a
a=10
if a>50 then
msgbox "True"
else if a>80 then
msgbox "优秀"
else
msgbox "kdc"
end if
end if # 有几个if就有几个end if
select case 代替if else if end if的条件语句
dim a
a=input("请输入")
a=int(a)
select case a
case 1
msgbox "1"
case 2
msgbox "2"
case else
msgbox "error"
end select
循环语句(密码验证实例一)
dim password
const pass = "123456"
do
password = inputbox("请输入密码:")
select case password
case pass
msgbox "密码正确"
exit do
case else
msgbox "密码不正确,请重新输入"
end select
loop
循环语句(密码验证实例二)
dim password, num
num=0
const pass="123456"
do
password=inputbox("")
if password=pass then
msgbox "密码输入正确"
exit do
else
if num=3 then
msgbox "输入超次,程序关闭"
exit do
else
num+=1
msgbox "密码错误,请重新输入"
end if
end if
loop
循环语句(密码验证实例三)
dim password, num
num=0
const pass="123456"
do while num>2
password=inputbox("")
if password=pass then
msgbox "密码输入正确"
exit do
else
num+=1
end if
loop
for循环(一)
dim count
for count=0 to 10
msgbox count
next
for循环(二)
dim num:num=0
for i=1 to 10
num = num+1
if num=5 then
exit for
end if
next
msgbox i
列表数组操作
dim num(9) # 定义数组长度为10
rem "增"
name(0)=1
rem "删"
name(0)=1
rem "改"
name(0)=1
rem "查"
msg = name(0)
msgbox msg
自定义函数(有参函数,无参函数)有返回值相当于return
function func()
megbox "hello word"
end function
call func()
function func(name)
megbox "hello word"&name
end function
call func("你妹")
子程序(有参函数,无参函数)无返回值
sub func()
megbox "hello word"
end sub
call func()
内建函数
msgbox()
inputbox()
date() # 系统日期
time() # 系统日期
now() # 系统日期和时间
abs() # 绝对值
cos()
sin()
lcase() # 大写转化小写
ucase() # 小写转化大写
len()
replace()
isarray() # 判断是否是数组
lbound() # 数组起始下标
ubound() # 数组最大下标
conversion() # 转化函数
cint() # 将字符串转化为数字类型
formatpercent(2/5,1) #格式化保留一位小数
set ws=wscript.createobject("wscript.shell")
ws.run() # 返回0,1
ws.exec("notepad.exe") # 返回对象
西北乱跑娃 --- vbs学习笔记(经典例子)
最新推荐文章于 2022-12-31 22:19:24 发布