西北乱跑娃 --- vbs学习笔记(经典例子)

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")  # 返回对象
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

西北乱跑娃

万水千山总是情,犒赏一下行不行

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值