当前位置:网站首页>脚本之美│VBS 入门交互实战
脚本之美│VBS 入门交互实战
2022-06-23 21:46:00 【InfoQ】
一、什么是 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

边栏推荐
- Freiburg University, Hildesheim University and other universities in Germany jointly | zero shot automl with pre trained models (zero sample automl based on pre training model)
- Take you through the distributed file system
- Ten thousand words! Understand the inheritedwidget local refresh mechanism
- TMUX support, file transfer tool Trz / Tsz (trzsz) similar to RZ / SZ
- How to dynamically insert a picture into a QR code
- How to build an API gateway and how to maintain an API gateway?
- Modify jar package
- The latest research progress of domain generalization from CVPR 2022
- KnowDA: All-in-One Knowledge Mixture Model for Data Augmentation in Few-Shot NLP(KnowDA:用于 Few-Shot NLP 中数据增强的多合一知识混合模型)
- The 10th Blue Bridge Cup single chip microcomputer
猜你喜欢

使用 Provider 改造屎一样的代码,代码量降低了2/3!

CAD图在线Web测量工具代码实现(测量距离、面积、角度等)

从CVPR 2022看域泛化(Domain Generalization)最新研究进展

Hackinglab penetration test question 8:key can't find it again

Peking University, University of California Berkeley and others jointly | domain adaptive text classification with structured knowledge from unlabeled data (Domain Adaptive Text Classification Based o

Configuring error sets using MySQL for Ubuntu 20.04.4 LTS

University of North China, Berkeley University of California, etc. | Domain Adaptive Text Classification with structural Knowledge from unlabeled data

How to improve the content quality of short video, these four elements must be achieved

Error running PyUIC: Cannot start process, the working directory ‘-m PyQt5. uic. pyuic register. ui -o

北大、加州伯克利大学等联合| Domain-Adaptive Text Classification with Structured Knowledge from Unlabeled Data(基于未标记数据的结构化知识的领域自适应文本分类)
随机推荐
How to select Poe, poe+, and poe++ switches? One article will show you!
The 11th Blue Bridge Cup
CMU博士论文 | 通过记忆的元强化学习,118页pdf
Environment construction of go language foundation
Talking about using email to attack social engineering
How does the fortress machine view the account assigned by the server? What are the specific steps?
Statistics of clinical trials - Calculation of tumor trial endpoint
Bi SQL constraints
[tutorial] build a personal email system using Tencent lightweight cloud
Teacher lihongyi from National Taiwan University - grade Descent 2
北大、加州伯克利大學等聯合| Domain-Adaptive Text Classification with Structured Knowledge from Unlabeled Data(基於未標記數據的結構化知識的領域自適應文本分類)
After CVM is configured with IPv6, it cannot be accessed as IPv6 or cannot access IPv6 sites
Benchclock: a benchmark for evaluating semantic analysis language models
CAD图在线Web测量工具代码实现(测量距离、面积、角度等)
Manually push a message platform
WordPress preview email for wocomerce 1.6.8 cross site scripting
Why is the server fortress machine error code 110? How to solve error code 110?
How to defend the security importance of API gateway
How to batch output EAN13 code to PDF
Flink practical tutorial: advanced 4-window top n