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


边栏推荐
- Svg+js drag slider round progress bar
- 程序员在技术之外,还要掌握一个技能——自我营销能力
- Can text pictures be converted to word? How to extract text from pictures
- What is the resource search platform and how resource search works
- Distribute proofs of manuscripts by scanning
- Base64 decoding method three ways for non professionals
- js数组求和的5种方法
- Common third-party UI frameworks
- The record of 1300+ times of listing and the pursuit of ultimate happiness
- 什么是递归?
猜你喜欢

把腾讯搬到云上,治愈了他们的技术焦虑

Flink cluster construction and enterprise level yarn cluster construction

Stack Title: exclusive time of function

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

腾讯开源项目「应龙」成Apache顶级项目:前身长期服务微信支付,能hold住百万亿级数据流处理...

283. move zero

线程运行原理

Fashionable pop-up mode login registration window

Cookie 、Session、localstorage、Sessionstorage的区别
![Illustration miscellaneous [for archiving to prevent loss]](/img/cf/bf48bfda020a3c8690339a388efc5d.png)
Illustration miscellaneous [for archiving to prevent loss]
随机推荐
A method of generating non repeated numbers in nodejs
Today's sleep quality record 76 points
Learn to use the kindeditor rich text editor. Click to upload a picture. The mask is too large or the white screen solution
Quick completion guide for mechanical arm (II): application of mechanical arm
What is the function of the graphics card driver? Do you want to update the graphics card driver
Quick completion guide for manipulator (III): mechanical structure of manipulator
使用Process Monitor工具监测进程对注册表和文件的操作
What is the bin file for? How to open the file correctly
Besides technology, programmers also need to master a skill - self marketing ability
JMeter interface test tool foundation - use badboy to record JMeter script
Cloud vendor secondary virtualization restrictions
Plant growth H5 animation JS special effect
[technical tutorial] national standard protocol platform easygbs cascading supports customized national standard channels
Web project deployment
System design: load balancing
26.删除有序数组的重复项
Lightweight deployment of firefoxsend temporary file sharing service using Tencent cloud
SQL Server about like operator (including the problem of field data automatically filling in spaces)
23. opencv - image mosaic project
"Adobe international certification" Adobe Photoshop adjusts cropping, rotation and canvas size