当前位置:网站首页>Beauty of script │ VBS introduction interactive practice

Beauty of script │ VBS introduction interactive practice

2022-06-24 13:08:00 51CTO

Catalog

One 、 What is? VBS

  • VBS It's a kind of Windows Scripting language , The full name is Microsoft Visual Basic Script Editon, Microsoft Visualization BASIC Script version
  • vbs It's built-in , The code can be found in windows Direct execution in the system , No compilation environment is required , Very convenient
  • vbs The script is simple , Efficient , Most functions can be realized , Make good use of vbs Script , Can greatly improve the efficiency , It can be used to do some repeated and tedious machine operations

Two 、 first VBS Script

  • Create a new text document on the desktop
  • Open a text document , Type in msgbox "Hello World!"
  • Suffix the format of the text document .txt Change it to .vbs
  • Then double click the run file

 Beauty of script │VBS Introduction interactive practice _ Scripting language

3、 ... and 、msgbox grammar

  • grammar :msgbox " Dialog content "," Dialog type ( Parameters :0,1,2,3,4,5)"," Dialog title "
  • Dialog content : It refers to the main content of the pop-up window
  • Dialog type : You can choose 0-5 common 6 Three types of dialog modes ,0 The dialog box only has OK button ;1 The dialog box has OK button Cancel button ;2 The dialog box has Stop button Retry button Ignore button ;3 The dialog box has It's a button No button Cancel button ;4 The dialog box has It's a button No button And it is forbidden to click on the... In the upper right corner of the dialog box close Button ;5 The dialog box has Retry button Cancel button . If you don't fill in the silent opinion 0
  • Dialog title : It refers to the title of the pop-up window
msgbox " Brother flying rabbit gives you a prize to receive ", 3, " Warm reminder "

     
  • 1.

 Beauty of script │VBS Introduction interactive practice _vbs_02

Four 、 Chinese garbled

  • You can see the Chinese garbled code in the above figure
  • This is mainly caused by coding errors , The encoding format of a normal text document is UTF-8 Of , however VBS The script needs to be encoded in ANSI Can run Chinese normally
  • At this time we need Open a text document Click on the file in the upper left corner Save as Select code as ANSI determine Can solve

 Beauty of script │VBS Introduction interactive practice _ Scripting language _03

5、 ... and 、 Pop up interactive function

  • We just implemented a very simple display function , Then we need to implement the interactive function , Variables are needed
  • stay vbs Through dim Defining variables , The grammar is :dim Variable name 1, Variable name 2, Variable name 3... Variable name n
  • among inputbox It can be used to receive parameters manually entered by the user
dim name
name = inputbox(" Please tell me who you are ", " This is the title of the interaction ")
msgbox name,," Welcome "

     
  • 1.
  • 2.
  • 3.

 Beauty of script │VBS Introduction interactive practice _ Scripting language _04

 Beauty of script │VBS Introduction interactive practice _windows_05

6、 ... and 、 Confession mischief

  • Before the very fire can not close the confession pop-up window , Namely vbs make
  • Use dim a(5) You can define arrays ,5 Indicates how many elements are in the array
  • Use Select Case Indicates that this is an option
  • The return value of the selected consent is 6, The return value of disagree is 7
  • If you click disagree , Then loop through the array to show
  • If the user clicks agree , Then the plot will succeed , Exit options
MsgBox " The Buddha cries for "
MsgBox " Naihe bridge waits "
MsgBox " Look back 500 times "
MsgBox " Looking back over the millennia "
MsgBox " The reincarnation of all ages "
MsgBox " Change your present life love "
MsgBox " Would you please "
dim a(5)
a(0)=" Tian Da , Big land , Girlfriend is the biggest "
a(1)=" Pay up "
a(2)=" Write your name in the room "
a(3)=" Help clear the shopping cart "
a(4)=" Baoda "
a(5)=" Just promise me to ^o^"
Dim j
Do
Select Case msgbox (" The girl , Be my girlfriend ", 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.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.

 Beauty of script │VBS Introduction interactive practice _vbs_06

 Beauty of script │VBS Introduction interactive practice _vbs_07

原网站

版权声明
本文为[51CTO]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/175/202206241233193651.html