A flexible and practical introduction to the VBS tutorial BASIC article _vbs

Source: Internet
Author: User
Tags constant
We often hear that the VBS function is very powerful and very simple, do you want to know about VBS, now let's learn the VBS together.

VBS is only an abbreviation of English, the full name is Visual Basic Script Edition, that is, the VBS is a Visual Basic script version, many people say that the VBS is a subset of VB. Because VBS is basically consistent with Visual Basic in programming syntax and functions. The general functionality that Visual basic can implement, VBS can also be implemented, and the implementation of the process is easier than Visual Basic, because as long as a text editor can complete the VBS programming, and Windows from the notebook Notepad is fully qualified.

Here we write a classic routine: Hello world. What we want to achieve is the effect shown in Figure 1, in order to achieve this effect only need a statement on the line. The following are specific practices: Open Notepad, enter "MsgBox" ("Hello World") in the edit area (Figure 2), then save the file with a VBS extension ("All Files" in "Save Type", and in "filename", enter the filename that includes the extension), such as "Hello World.vbs "), save the completed directly double-click the saved file, the effect came out. Learn VB Friends know MsgBox function is one of the most common functions of VB programming, it can implement pop-up window prompts information.


Figure 1


  
Figure 2

The output will have input, and MsgBox corresponds to the input function InputBox it is used to receive user input information, and then return to the specified variable. Let's use one more example to illustrate the following. Enter the following in your notebook:

Dim Name
Name=inputbox ("Please enter your Internet café name", "name")
MsgBox (name)

When you save, double-click to run, and the window shown in Figure 3 appears.


Figure 3

To enter what you want to enter in the window (such as the "Grass network" in this example), click OK and a prompt will pop up to show you what you entered (Figure 4).

Figure 4

Now let's take a closer look at the meaning of the above content. Dim is the keyword that declares the variable in Visual Basic and is also applicable in the VBS, as follows:

Dim variable name [as type]

The contents of the brackets can be omitted (the brackets in the later article refer to this meaning). If omitted, then the variable you declare will be variant, and the data type of the variable will be based on the value you assign to the variable, and if the value you assign to the variable is an integral type, it will be an integer variable. The second statement "Name=inputbox" ("Please enter your Internet café name", "name"), meaning that when you perform the InputBox function, you assign the user input to the variable Name, "=" is the assignment symbol, but differs from the "=" in the number.

It says variables, and it may not be possible for readers who have not studied programming to understand what is called a variable. In fact, in advanced language programming, there are constants in addition to variables. To be blunt, constants and variables are named memory units that access data by using the memory cell name when you read the modified data. In particular, a variable is the amount of value that can be changed while the program is running. Greater flexibility. Constants are constant in the program's operation, constants are generally divided into three kinds: direct constants, user-declared symbolic constants. A direct constant can be used without a declaration, such as 123 is a direct constant, you can use it directly, but you can't change it, if you try to change it, like 123=321, it will go wrong when the program runs. The constants declared by the user are intended to facilitate the reading or modification of the program and modify the constants declared by the user themselves, so the values associated with the declared constants will change accordingly, rather than being modified one by one. The key word for a constant declaration is const, for example: Const pi=3.14159. Let's write a program that calculates the area of a circle. Enter the following in Notepad:

Const PI=3.14
Dim r,s
R=inputbox ("Please enter the radius of the circle you want to calculate", "radius")
S=pi*r*r
MsgBox ("The area of the circle is" & S)

Save as a VBS file, a calculation of the circle area of the program is completed.

At this point, I guess we have a preliminary understanding of VBS programming, to learn more deeply to choose the structure and circulation structure, which will be covered in the following article.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.