2
头图

🎈 What is VBS

  • VBS is a Windows scripting language, the full name is Microsoft Visual Basic Script Editon , Microsoft Visual BASIC Script Edition
  • vbs is built-in in the system, the code can be executed directly in the system windows , no need to compile environment, very convenient
  • vbs script is simple and efficient, most of the functions can be realized, make good use of the script vbs The script can greatly improve the efficiency and can be used to do some repeated and tedious machine operations

🎈 First VBS script

  • Create a new text document on the desktop
  • Open the text document and enter msgbox "Hello World!"
  • Change the format suffix of the text document .txt to .vbs
  • Then double click to run the file

第一个 vbs 脚本

🎈 msgbox syntax

  • Syntax: msgbox "对话框内容","对话框类型(参数:0,1,2,3,4,5)","对话框标题"
  • Dialog content: refers to the main content of the pop-up window
  • Dialog type: You can choose 0-5 a total of 6 types of dialog modes, when 0, the dialog only has 确定按钮 ; when 1, the dialog has 确定按钮 , 取消按钮 ;2时对话框有中止按钮重试按钮忽略按钮 ;3时对话框有是按钮否按钮取消按钮 ;4时对话框有是按钮否按钮关闭 ;5 o'clock dialog has 重试按钮 , 取消按钮 . If not filled, the default is 0
  • Dialog title: refers to the title of the popup window
 msgbox "飞兔小哥送你一份奖品待领取", 3, "温馨提醒"

msgbox 语法

🎈 Chinese garbled characters

  • You can see the Chinese garbled characters in the picture above
  • This is mainly caused by encoding errors. The encoding format of a normal text document is UTF-8 , but VBS the script needs the encoding format to be ANSI to be normal. run Chinese
  • 打开文本文档点击左上角文件另存为选择编码为ANSI确定解决

解决中文乱码

🎈 Popup interactive function

  • Above we just implemented a very simple display function, then we need to implement the interactive function, we need to use variables
  • In vbs you can define variables through dim , the syntax is: dim 变量名1,变量名2,变量名3...变量名n
  • Among them inputbox can be used to receive parameters manually entered by the user
 dim name
name = inputbox("请告诉我您是谁", "这是交互的标题")
msgbox name,,"欢迎您"

接收参数

显示参数

🎈 confession spoof

  • The pop-up window for confession that could not be closed before was very popular, which was made by vbs
  • Use dim a(5) to define an array, 5 indicates how many elements there are in this array
  • Use Select Case to indicate that this is an option
  • Among them, the return value of choosing agree is 6, and the return value of disagree is 7
  • If you click to disagree, then loop through the value display from the array
  • If the user clicks agree, the conspiracy succeeds, exit option
 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

弹窗选项

弹窗结果


极客飞兔
1.2k 声望649 粉丝