当前位置:网站首页>脚本之美│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

边栏推荐
- EDI mandatory manual
- How to batch output EAN13 code to PDF
- BenchCLAMP:评估语义分析语言模型的基准
- One article to help you understand automatic injection
- What do you know about the 15 entry-level applets
- Learn about reentrantlock
- Flink practical tutorial: advanced 4-window top n
- Bi SQL constraints
- The time deviation is more than 15 hours (54000 seconds), and the time cannot be automatically calibrated
- Take you through the distributed file system
猜你喜欢

Leetcode algorithm interview sprint sorting algorithm theory (32)

Ten thousand words! Understand the inheritedwidget local refresh mechanism

ACL2022 | MVR:面向开放域检索的多视角文档表征

Installation and use of Minio

万字长文!一文搞懂InheritedWidget 局部刷新机制

北大、加州伯克利大学等联合| Domain-Adaptive Text Classification with Structured Knowledge from Unlabeled Data(基于未标记数据的结构化知识的领域自适应文本分类)

MySQL de duplication query only keeps one latest record

Code implementation of CAD drawing online web measurement tool (measuring distance, area, angle, etc.)

北大、加州伯克利大學等聯合| Domain-Adaptive Text Classification with Structured Knowledge from Unlabeled Data(基於未標記數據的結構化知識的領域自適應文本分類)

从CVPR 2022看域泛化(Domain Generalization)最新研究进展
随机推荐
德国弗莱堡大学、希尔德斯海姆大学等联合 | Zero-Shot AutoML with Pretrained Models(基于预训练模型的零样本AutoML)
PHP laravel 8.70.1 - cross site scripting (XSS) to cross Site Request Forgery (CSRF)
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
How to improve the high concurrency of the server
Detailed explanation of redisson distribution lock
New high-speed random graph API interface, the first sci-fi graph API interface
Intel openvino tool suite advanced course & experiment operation record and learning summary
WordPress plugin smart product review 1.0.4 - upload of any file
How to batch output EAN13 code to PDF
[open source]goravel, a fully functional and extensible golang web application framework
What should be done when the encryptor fails to authenticate in the new version of easycvr?
MySQL architecture SQL foundation 2
What is dynamic registration? What is static registration?
Redis source code analysis -- QuickList of redis list implementation principle
Using the provider to transform the shit like code, the amount of code is reduced by 2/3!
Micro build low code tutorial - variable definition
Shell automatically obtains hardware information
What is zero copy?
How the API gateway obtains the URI path and how the API handles local access failure
Performance optimization of database 5- database, table and data migration