VBS BASIC Programming Tutorial (1th) _vbs

Source: Internet
Author: User
Tags constant
, if you want to contact the following VBScript can also, but since there is a programming foundation recommended directly to find some reference books to read, it will be faster.

What is VBScript? The full name of VBScript is: Microsoft Visual Basic Script editon. (Microsoft Visual Basic Script version). As its literal disclosure, the VBS (further shorthand for VBScript) is a scripting language based on Visual Basic.

I further explain that Microsoft Visual Basic is a set of visual programming tools produced by Microsoft, based on basic syntax. scripting language, is not compiled into binary files, directly by the host (host) to explain the source code and execution, the simple point is that you write the program does not need to compile to exe, but directly to the user to send. vbs source program, users can execute.

I know the rookie is now the most concerned about what tools to develop the VBS program, the answer is: Notepad. I am not joking, in fact, any kind of text editor can be used to develop VBS development, but Notepad is brought by the system, more easy to find. However, I suggest you download a professional text editor, because these tools can provide "syntax highlighting" and other features, more convenient development, with whichever you like, I prefer edit Plus (2.10).
 
OK, let's start by writing a VBScript program to warm up.
REM input and echo your name '
Using the InputBox and MsgBox functions
Copy Code code as follows:

Dim name,msg
msg= "Please enter your name:"
Name=inputbox (msg, "name")
Msgbox (name)

Enter the list of programs above into Notepad and save it as a file with a. vbs extension (select all files in the "Save Type").

Then double-click to run and observe the results of the operation.   Note: Please input the program list, do not copy-> paste! Let me explain this procedure, the first and second lines begin with the "REM" statement and the "'", and these two things work the same way, which means that the line is a comment line, which means that the two lines do nothing, just to illustrate the function of the program, copyright information, and so on. The comment line is one of the most important parts of the program, and although it is not required, it is good for others to read the source code and to analyze the source code for themselves. A good habit is to add clear, concise notes where necessary.

Dim is used to declare a variable, in the VBS, the variable type is not so important, that is, the VBS will help you automatically identify the variable type, and the variable is not necessarily declared before use, the program will dynamically allocate the variable space. In the VBS you don't have to consider whether name stores an integer or a decimal number (known as a "floating point"), and you don't have to consider a string (a string of characters, such as "Hello World"), and the VBS will automatically fix it for you. So the third line of statements can be deleted, the effect will not change, but I strongly oppose to do so, the basic principle of a variable is: first declare, then use. Variable names begin with a letter, you can use underscores, numbers, but you can't use a word that is already defined by the VBS, such as dim, nor is it a pure number.
The next line is called "assignment", and "=" is the assignment symbol, not the equal number in mathematics, although it looks the same. This is orthodox understanding, you have to understand that there is nothing to be. The left side of the assignment is a variable, and the right is the value to assign to the variable, and after the assignment, the MSG variable in the program equals "Please enter your name:" This string, but when MSG is replicated again, the original value disappears. Not only strings, but any other variables are assigned this way,
For example: a=2, b=12.222 and so on.

Further down, InputBox and MsgBox are built-in functions of VBS, a function is the equivalent of a "black box", with input (parameters) and output (return value), you can not understand how the function works, as long as you know what the function can do, we can also define their own functions, But that will wait until later. Now we just have to understand that a function can have a return value or not, and you can have parameters or not. For example, InputBox is a function that returns a value, and we use the variable on the left of the assignment to "pick up" the return value of the InputBox-what you enter. In the bracket to the right of the InputBox is the argument list, each parameter is separated by a "," partition, each of which has a different effect, such as the first parameter is shown in the hint, we pass the MSG variable as the first parameter to the InputBox function, and msg= "Please enter your name:", So we'll see in the dialog box, "Please enter your name:" The second argument is the title of the dialog box, we use the direct amount (called "constant", here is "string constant") passed to the function, of course, you can also pass variables. InputBox also has a lot of parameters, such as you add a "," after "name" and then type in a random string of characters (strings, a string of characters wrapped in double quotes, called strings) and run to see the results. You will find that the text box used for the input has the default value, which is the function of the third parameter.

The MsgBox function is the function that is used to output, there is no special output function in the VBS (printf in the print,c in basic), so we can only use the dialog to observe the output, MsgBox only one of the necessary parameters, is to output the content, in this case, We don't have to ignore the return value of MsgBox. We'll be talking about MsgBox and InputBox, and it's just warm up today.

Points:
1 Comments (REM or ' beginning ') do not work in the program, but can make it easier for others to read your program.
2 The variable is like a box, or a code symbol, can represent what you want to represent. Variable assignment using "="
3 "" "wrapped up in the character called" string "
4 function like a "black box", with parameters and return values, with "=" to the left of the variable can catch the return value
5) InputBox function pops up an input dialog box, MsgBox is used for output

Homework:
1) The third parameter of the test InputBox
2 Write a program to output your age
3 Write a program for 3 times input, input you and your parents ' names (required to display the prompts), and 3 times output

The above layout is too messy, you can refer to the following articles:
VBScript MsgBox function
VBScript InputBox function
A flexible and practical introduction to the VBS tutorial

More learning skills is to read more and write more tests.

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.