VBS Programming Tutorial (1th article) _vbs

Source: Internet
Author: User
It's not a good thing to find out that most black and white friends don't program, so this time I wrote a simple programming tutorial about VBScript. Mainly for the rookie, know how to program friends do not waste time, 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, 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
dim name,msg msg= "Please enter your name:"  name=inputbox (MSG, name)  msgbox (name)   Enter the above list of programs into Notepad,    then save as a file with a. vbs extension (select all files in the save type). Then double-click Run,  observe the results .  Note: Please enter the program list,  do not copy-> paste!  Let me explain. This program,  the first and second lines are "REM" and "  '  ",  the same,  means that the line is a comment row,  means that the two lines do nothing, It's just a function of the program.,  copyright information and so on .  comment Line is one of the most important parts of the program,  although it is not required,  but it is good for others to read source code,  and to analyze the source code themselves .  A good habit is to add clear,  concise annotations where necessary. .  Dim is used to declare a variable, ,  variable type in a VBS is not that important,  it means that VBS will help you automatically identify variable types,  and variables do not have to be declared before using the,  program will dynamically allocate the variable space .  in the VBS you do not have to consider whether name stores an integer or a decimal number (known as "floating point"),  also do not have to consider a string (a string of characters,  such as : "Hello world"),  vbs will automatically help you fix .  so the third line can delete the,  effect does not change,  but I strongly disagree with this. The basic principle of a variable is: to declare, Use the. Variable name begins with a letter, you can use an underscore, a number,  but you cannot use a word that is already defined by the VBS,  such as dim,  cannot be a pure number .  the next line is called "assignment",  "=" is the assignment symbol,  is 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 .  to the left of the assignment number is a variable,  to the right is the value to assign to the variable,  after the assignment,  MSG this variable in the program is equivalent to "Please enter your name:" Thisstring, but when MSG is replicated again,  the original value disappears .  not only string,  other variables are assigned,  such as:  a=2, b=12.222 and so on .  down, InputBox and MsgBox are functions built in VBS,  a function is equivalent to a "black box",  with input (parameters) and output (return value),  you don't have to understand how a function works,  Just understand what this function can do.,  we could also define our own functions,  but that's going to wait until later .  now we just have to understand,  a function can have return values or no,  can have parameters or not.   For example InputBox is a function with a return value,  we use the variable on the left of the assignment to "connect" to the InputBox return value--That's what you enter .  the InputBox right bracket is the argument list,  each parameter is " , "separate,  each parameter has a different effect,  for example, the first parameter is displayed in the hint,  we passed 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 parameter is the title of the dialog box,  we use the direct quantity (the name "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 enter 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,  this is the function of the third parameter .  MsgBox function is the function used to output,  there is no specific output function in the VBS (printf in the print,c in basic) ,  so we can only use the dialog box to observe the output,  msgbox the necessary parameters only one,  is to output the content,  in this case,  we do not need to ignore MsgBox return value .  About MsgBox and InputBox we'll be talking about,  today just warm up, &nBSP; .  points:  1)   annotations (REM or ' beginning ") do not work in a program,  but it makes it easier for others to read your program.  2)   Variables like a box,  or a code name,   can represent something you want to represent .  variable assignment using "="  3   with "" The wrapped character called "string"  4)   function is like a "black box",  with parameter and return value,  "=" The variable on the left can catch the return value  5)  inputbox function pops up an input dialog box, MsgBox for output   job:  1)   Test InputBox's third parameter  2)   Write a program to output your age  3)   Write a program for 3 times input,  Enter your and your parents ' names (required to display the prompts),  and 3 times output  

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.