Keystroke Wizard Script-a good tutorial for learning VBS _VBS

Source: Internet
Author: User
Today I will be the overall introduction of VBS, I hope to give you an intuitive impression. In addition, the key to the official website of the Keyboard Wizard tutorial (Li Yue Production), to help you understand this dongdong.
I. Overview
To make a computer do things, one must give it instructions. The original instructions are very complex, are some 0011001 of things, and then gradually simplified, instructions are also closer to the human language. VBS (Microsoft (R) Visual Basic (r) scripting) is also a high-level language, compared to other high-level languages, it has a simple and easy to learn, and is a good entry point for computer beginners in the field of programming.
If the evolution from low-level language to high-level language is the strategic problem of human control computer, then the specific setting variable, cycle is the specific tactical problem of computer control. What we are learning now is the tactic of using VBS to make computers work for us.
Second, from the simplest things to start.
Web Hawk script:
VBS I
VBS I=10
While I>0
saystring sell xxx, price negotiable.
VBS I=I-1
Delay 10000
ENDfor
Many people scoff at this script, and there are many ways to do it, some times simpler than the script. But as the explanation progresses, we will find that VBS provides us with a powerful tool. What do you mean by following these lines first?
VBS I//tells the computer to have a variable called I.
VBS I=10//This variable is 10
While i>0//When this variable is greater than 0 executes the following until you see the first endfor.
saystring sell xxx, price negotiable. Key statement: Output text
VBS I=I-1//This variable minus 1, and then the number minus 1 as the value of I.
Delay 10000//KEY statement: Pause 10 seconds (10000 milliseconds)
ENDfor//back at while
Effect: Hawking 10 times after the end.
Now I'm going to take a little effort to explain why I have to toss out so many troublesome things.
The usefulness and importance of variables
In fact, this program can be written completely
saystring sell xxx, price negotiable.
Delay 10000
saystring sell xxx, price negotiable.
Delay 10000
...... Repeat n times
saystring sell xxx, price negotiable.
Delay 10000
In fact, complex program segments can be restored to the order of the program, with a lot of complicated things not to display programming ability, but to their convenience.
When we sell XXX all the time may not have any feeling, but when we sell yyy? Do you want to mend it all? Or we have to repeat 1000 times, and then only repeat 500 times, is it serious to count 500, and then delete the back? Of course, we make up this small program is still more comfortable to change. But to improve development will have to do a big program, but also have to rely on our variable friends.
The variable is actually a character code, like you and my name, in order to separate the variables and let them work separately. When you name a variable, you can use numbers, characters, and underscores, but you can't use Chinese characters, spaces, and other weird symbols, and numbers can't be used for the first character.
Before using variables, write a statement like VBS I, which means that I am now assigning a variable, named I, to participate in the program's operation. In fact, you can not perform such registration procedures, directly in the program to use I, but the practice proved that this is a bad habit, let you write a large program when unable to do.
Then the VBS I=10 tells the program that the variable I now has a value of 10, where I will be used in the future, which is equal to 10. For example, VBS J=I+1 is actually equivalent to j=10+1, so the value of J is 11.
The charm of a variable is not only that it can take the place of numbers, but it can also replace characters, but compared with numbers, characters have their particularity.
Like what:
VBS i= "character"
VBS j= "threaded"
VBS A=I & J
At this point A is the string connection. Note the two new symbols that appear here: "Number and & symbol." Someone might have guessed their role. The character is the content between the number. The computer has a completely incomprehensible understanding of the VBS I=10 and the VBS i= "10". The & number is a string number. If A=j & I, then A is a threaded character.
Once we know the use of variables, we can change the Hawking program to be more interesting. For example, we want to let the program say different words, first say 10 times sell xxx, say 10 times sell yyy. Then we can write:
VBS I
VBS I=10
While I>0
Ifexpression i<=5
saystring sell xxx, price negotiable.
endif
Ifexpression i>5
Saystring sell yyy, price negotiable.
endif
VBS I=I-1
Delay 10000
ENDfor
In fact, we use a small programming skills, is the size of the variable I control program direction. Visible 5 times before selling yyy, 5 times after selling xxx.
Or we first call XXX once, then call yyy once, and then repeat the previous action:
VBS I
VBS I=10
While I>0
Ifexpression I mod 2 = 0
saystring sell xxx, price negotiable.
endif
Ifexpression I mod 2 = 1
Saystring sell yyy, price negotiable.
endif
VBS I=I-1
Delay 10000
ENDfor
A method for running with I program is also used here. MoD is the same operation symbol as + 、-、 *, the function is to take the remainder. If mod 2 = 0 means 10 divided by 2, the remaining number is 0. Same 9 mod 2 = 1,8 mod 2 = 0,7 mod 2 = 1,6 mod 2 = 0,5 mod 2 = 1 ...
Alas, write here for the time being.

In fact, this script is the script under the Keystroke wizard, did not write clearly, sorry Ah, if you want to see the VBS tutorial, it is recommended to download a VBScript handbook, and then look at the cloud-dwelling community of the VBS column of the earlier post. In the beginning, the basis of the hair more.
Http://www.jb51.net/books/210.html
Microsoft's official VBScript reference manual

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.