Vbs file introduction (resend)

Source: Internet
Author: User

NLP programming 1 (vbs basics)
What is VBScript? VBScript is Microsoft Visual BASIC script Editon. (Microsoft Visual BASIC script version ). vbs (further abbreviated as VBScript) is a visual basic-based scripting language. microsoft Visual Basic is a visual programming tool developed by Microsoft. Its syntax is based on basic. the script language is not compiled into a binary file. The host directly interprets the source code and runs it. Simply put, the program you write is not compiled into .exe, but directly sent to the user. you can run the vbs source program.
I know that cainiao is most concerned with developing vbs programs using tools. The answer is notepad. (Notepad ). i'm not kidding. In fact, any text editor can be used to develop vbs, but notepad is provided by the system and is easy to find. even so, I suggest you download a professional text editor, because these tools can provide "syntax highlighting" and other functions to facilitate development, I prefer edit plus (2.10 ).
OK. Let's write a VBScript program to warm up.
Rem input and echo your name
\ 'Use inputbox and msgbox Functions
Dim name, MSG
MSG = "enter your name :"
Name = inputbox (MSG, "name ")
Msgbox (name)
Enter the program list in notepad and save it as follows. files with the extension vbs (select "all files" in "Save type "). double-click "run" to view the running result. note: Please enter the program list by yourself, do not copy-> Paste
Let me explain this program. The first and second rows start with the "REM" Statement and "\ '", respectively. These two things have the same effect, it indicates that the line is a comment, that is, the two lines do nothing, just to describe the functions of this program, copyright information, and so on. annotation line is one of the most important parts of a program. Although it is not necessary, it is good for others to read the source code and analyze the source code themselves. A good habit is to add clear and concise comments where necessary.
Dim is used to declare a variable. In vbs, the variable type is not so important, that is, vbs will help you automatically identify the variable type, and the variable does not have to be declared before use, the program dynamically allocates variable space. in vbs, you do not need to consider whether the name is stored as an integer or a decimal number (also known as "Floating Point"), or whether it is a string (a string of characters, such: "Hello World"), vbs will automatically help you. therefore, the statement in the third line can be deleted, and the effect will not change, but I strongly oppose this. The basic principle of a variable is to declare it first and then use it later. A variable name must start with a letter. It can contain underscores and numbers, but cannot contain words defined by vbs, such as dim or pure numbers.
The next line is called "value assignment" and "=" is a value assignment symbol. It is not an equal sign in mathematics, although it looks the same. this is an orthodox understanding. You must understand it as equals and there is nothing to do with it. the left side of the assignment number is a variable, and the right side is the value to be assigned to the variable. After the assignment, the MSG variable is equivalent to "enter your name:" This string, however, when MSG is replicated again, the original value disappears. not only strings, but any other variables are assigned values like a = 2, B = 12.222.
Next, inputbox and msgbox are vbs built-in functions. A function is equivalent to a "black box" with input (parameter) and output (return value ), you don't need to know how a function works. You only need to know what this function can do. We can also define our own functions, but we will not talk about it later. now, we only need to know that a function can have a return value or no parameter. for example, inputbox is a function with a returned value. We use the variable on the left of the value pair to "catch" the returned value of inputbox-the content you entered. the parameter list is in the brackets on the Right of inputbox. Each parameter is separated by commas (,). Each parameter has different effects. For example, the first parameter is displayed in the prompt, we passed the MSG variable as the first parameter to the inputbox function, while MSG = "enter your name :", therefore, in the prompt bar of the dialog box, we will see "enter your name:" The second parameter is the title of the dialog box. We use a direct volume (named "constant ", here is "String constant") passed to the function, of course, you can also pass variables. inputbox also has many parameters. For example, you can add a character after "name", "and enter a string (a string enclosed by double quotation marks" is called a string) run the command and check the result. you will find that the text box used for input has the default value, which is the role of the third parameter.
Msgbox is a function used for output. In vbs, there is no special output function (print in basic, printf in c). Therefore, we can only observe the output result in a dialog box, there is only one required parameter for msgbox, that is, the content to be output. In this case, we do not need to care about the return value of msgbox. we will discuss msgbox and inputbox in the future. Today, it's just a warm-up, so far.
Key points:
1) The comments (beginning with REM or \ ') line does not work in the program, but it makes it easier for others to understand your program.
2) A variable is like a box or code, which can represent what you want to represent. The variable value assignment uses "="
3) The character wrapped in "" is called "string"
4) The function is like a "black box" with parameters and return values. The variable on the Left can hold the return values.
5) an input dialog box is displayed for the inputbox function, and msgbox is used for output.
Job:
1) Test the third parameter of inputbox
2) write a program to output your age
3) write a program and input it three times. Enter the names of you and your parents respectively (the prompt must be displayed) and output it three times.

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.