当前位置:网站首页>脚本之美│VBS 入门交互实战
脚本之美│VBS 入门交互实战
2022-06-24 09:51:00 【极客飞兔】
一、什么是 VBS
VBS是一种Windows脚本语言,全称是Microsoft Visual Basic Script Editon,微软公司可视化 BASIC 脚本版vbs是系统内置的,代码可在windows系统中直接执行,不需要编译环境,非常的方便vbs脚本简单,高效,大部分功能都可以实现,利用好vbs脚本,可以极大的提高效率,可以用它来做一些反复繁琐的机器操作
二、第一个 VBS 脚本
- 在桌面上新建一个文本文档
- 打开文本文档,在其中输入
msgbox "Hello World!" - 将文本文档的格式后缀
.txt改为.vbs - 然后双击运行文件即可

三、msgbox 语法
- 语法:
msgbox "对话框内容","对话框类型(参数:0,1,2,3,4,5)","对话框标题" - 对话框内容:是指弹窗的主体内容
- 对话框类型:可以选择
0-5共6种类型的对话框模式,0时对话框只有确定按钮;1时对话框有确定按钮、取消按钮;2时对话框有中止按钮、重试按钮、忽略按钮;3时对话框有是按钮、否按钮、取消按钮;4时对话框有是按钮、否按钮并且对话框禁止点击右上角的关闭按钮;5时对话框有重试按钮、取消按钮。如果不填默认为0 - 对话框标题:是指弹窗的标题
msgbox "飞兔小哥送你一份奖品待领取", 3, "温馨提醒"

四、中文乱码
- 上图可以看到中文乱码了
- 这主要是因为编码错误导致的,正常的文本文档它的编码格式是
UTF-8的,但是VBS脚本需要编码格式是ANSI才可以正常运行中文 - 这时候我们需要
打开文本文档►点击左上角文件►另存为►选择编码为ANSI►确定即可解决

五、弹窗交互功能
- 上面我们只是实现了很简单的展示功能,那么我们需要实现交互功能,就要用到变量了
- 在
vbs中可以通过dim定义变量,语法为:dim 变量名1,变量名2,变量名3...变量名n - 其中
inputbox可以用来接收用户手动输入的参数
dim name
name = inputbox("请告诉我您是谁", "这是交互的标题")
msgbox name,,"欢迎您"


六、表白恶搞
- 之前很火的关闭不了的表白弹窗,就是
vbs做出来的 - 使用
dim a(5)可以定义数组,5表示这个数组里面有多少元素 - 使用
Select Case表示这是一个选项 - 其中选择同意的返回值为6,不同意的返回值为7
- 如果点击了不同意,那就循环从数组中取值展示
- 如果用户点击了同意,那就阴谋得逞,退出选项
MsgBox "佛前哭求"
MsgBox "奈何桥等待"
MsgBox "五百次回眸"
MsgBox "千年的回首"
MsgBox "百世的轮回"
MsgBox "换你今朝一世情缘"
MsgBox "可否"
dim a(5)
a(0)="天大,地大,女友最大"
a(1)="工资上交"
a(2)="房写你名"
a(3)="帮清购物车"
a(4)="保大"
a(5)="你就答应我把^o^"
Dim j
Do
Select Case msgbox ("姑娘,做我女朋友吧", 4)
Case 6
MsgBox "you are my girlfriend," + Chr(13) + "from this day until to my last days."
exit do
Case 7
msgbox a(i)
i=i+1
if i >= 6 then
i = 0
end if
end Select
Loop


边栏推荐
- 23. opencv - image mosaic project
- 什么是递归?
- Why should we make the best use of the external chain in SEO?
- 服乔布斯不服库克,苹果传奇设计团队解散内幕曝光
- Canvas infinite scan JS special effect code
- MYSQL_ Elaborate on database data types
- Five methods of JS array summation
- Quick completion guide for mechanical arm (II): application of mechanical arm
- The nodejs service global timeout callback failed to get process Domain problem
- Four methods of object merging and four methods of object merging in JS
猜你喜欢

线程运行原理

机械臂速成小指南(二):机械臂的应用

Simple pricelist style code

Cookie 、Session、localstorage、Sessionstorage的区别

Appium automation test foundation - mobile end test environment construction (I)

What you must know about distributed systems -cap

Quick completion guide for manipulator (III): mechanical structure of manipulator

服乔布斯不服库克,苹果传奇设计团队解散内幕曝光

Shape change loader loads jsjs special effect code

机械臂速成小指南(一):机械臂发展概况
随机推荐
Virtual CD-ROM function how to use and install virtual CD-ROM
88. merge ordered arrays
Nxshell session management supports import and export
Window function row in SQL Server_ number()rank()dense_ rank()
System design: load balancing
The nodejs service global timeout callback failed to get process Domain problem
Apple's legendary design team disbanded after jobs refused to obey cook
Disaster recovery series (II) -- enterprises' one-stop disaster recovery construction with the help of cloud platform?
栈题目:函数的独占时间
I pushed my younger brother into Tencent. Look at his benchmark resume!
Tencent geek challenge small - endless!
Dedecms template file explanation and homepage label replacement
Solve the timeout of Phoenix query of dbeaver SQL client connection
What characteristics should a good design website have?
Simple pricelist style code
What is recursion?
What is a compressed file? What are the advantages of different methods of compressing files?
PPT绘图相关,快捷键,美观度
How does easydss use go fastdfs distributed file servers to reduce service pressure?
Svg+js drag slider round progress bar