Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Case Analysis of VBS starter scripting language

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the relevant knowledge of "case analysis of VBS entry script language". The editor shows you the operation process through the actual case. The operation method is simple, fast and practical. I hope this article "case analysis of VBS entry script language" can help you solve the problem.

A brief introduction to VBS

VBS is a Windows scripting language, the full name is Microsoft Visual Basic Script Editon (Microsoft Visual BASIC script version).

Why do you want to learn VBS

Vbs is built into the system, and the scripts written with it do not need to be compiled into binary files, and the source code is interpreted and executed directly by the Windows system host host.

He does not need a specific compilation environment, any text editor can be prepared, beginners with Windows's own "notepad (Notepad)" can be prepared and executed, if you want to learn in depth, it is recommended to use a professional editor to support code highlighting, more convenient, Notepad++ is quite good.

Vbs script code is simple and efficient, and it can do what most high-level languages can do. It can automate the usual repetitive, tedious computer operations and greatly improve work efficiency (benefits for lazy people).  

Third, the first VBS script

Brothers who have studied programming know that it must be "Hello World!" Because the first program for most computer programming classes is to output "Hello World!" .

Open your notepad or create a new text document directly on the desktop, enter the following code, press the Ctrl+S shortcut to save, and then change the suffix to .vbs. (try to use shortcut keys to make your operation more smooth.)

Msgbox "Hello World!"

Remember to save (form a habit) every time you write and modify it! Many beginners will make the mistake of running without saving, causing a lot of trouble (such as me, woo-woo).

What? You can't find a suffix, you don't even know what a suffix is! Then you may be a real computer rookie, but it's all right. I know you. (boss, please skip it directly)

Press the "win+E" shortcut to open Explorer or any folder, click View, check the "File extension" check box, and then go back to have a look, is there something more?

Before checking:

After the check box, the extra part is his suffix:

   

Then select it and press the "F2" shortcut to rename it to: the first VBS script .vbs

Now double-click can be executed, no accident will be like the following picture (under the win10 system), click OK, the dialog box will disappear, although a little rough, but this is really the first script we wrote.

If there is an accident, it will be like the following picture, this kind of mistake will be made by many beginners, it is normal, this is because your symbol is not entered in English (Shift switch between Chinese and English).

No matter what the code is, you must pay attention to the input method status of the taskbar and use the English input method (important! ).

But it's also good, at least it proves that you didn't copy my code, but you did it yourself.

Code parsing:

Msgbox "Hello World!"

Msgbox is an internal function of VBS, each function can complete certain functions, you just need to follow its syntax format and fill in the corresponding parameters in the corresponding position.

What are the parameters? The parameter is the part you fill in (those in double quotes).

Msgbox syntax format:

Msgbox "Dialog content", "Dialog Type (parameters: 0meme1jin2)", "Dialog title"

You can continue to modify your original code and look at each type of dialog style (remember to change and save! )

Fourth, to achieve simple interactive functions

Our above code just pops up a dialog box without even the most basic interactive functions, but we can simply modify it.

Dim namename = inputbox ("Please enter your name:", "name") msgbox name, "your name is"

Some students may report errors like the following figure at run time, mostly because of coding (no errors can be skipped by students).

Right-click your problem VBS script, select "Edit", view the lower right corner of the file format, found that the current encoding is "UTF-8", which will report errors, the solution is also very simple, press the "Ctrl+Shift+S" shortcut key to open the "Save as" window, change the lower right corner of the encoding to "ANSI", and then confirm to save the replacement.

Now that you are looking at your VBS script coding, it has become "NASI". Now double-click to run it.

Double-click to open:

Enter a name:

Click OK:

Code parsing:

Dim namename = inputbox ("Please enter your name:", "name") msgbox name, "your name is"

The first sentence defines a variable named "name". "dim" is a statement that defines a variable. The syntax format is:

Dim variable name 1, variable name 2, variable name 3... Variable name n

The second sentence: receive the information entered by the user and give the received information to the variable "name" for storage. "name" represents the content entered by the user. "=" is the symbol for passing data, and the rule is to pass from right to left. "inputbox" is an internal function of VBS, which can receive the input. The syntax format is as follows:

Inputbox ("dialog box content", "dialog box title")

The third sentence: the principle is the same as our first program, but this time the output dialog box is the variable value "name" we created.

Msgbox name, "your name is"

Students who are eager to learn may ask: why don't you put double quotes in this "name" variable? Today we will add to it, make a comparison, and we will understand.

Running result:

LOOK, he did not output the information I entered, but output "name", this is because the contents of the double quotation marks will be output as is, we want to output the information stored in the variable, just put the variable name on it.

Pay attention to:

1. The location of the file does not affect the execution of the script, but it is best to put it in a place where you can find it easily (I usually build various folders on my desktop to store separately).

two。 The extension must be ".vbs".

3. Symbols must be entered under the English input method.

4. Be sure to save every time you write and modify it.

This is the end of the introduction to "instance Analysis of VBS getting started scripting language". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report