Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand VBS

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the relevant knowledge of "how to understand VBS". In the operation of actual cases, many people will encounter such a dilemma. Then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

I. Overview

In order for a computer to do things, it must be instructed by people. The original instructions were very complex, all 0011001 things like that, and then they were gradually simplified, and the instructions were closer to human language. VBS (Microsoft (R) Visual Basic (R) Scripting) is also a high-level language. Compared with other high-level languages, it is easy to learn, and it is a good entrance for computer beginners to get involved in the field of programming.

If the evolution from low-level language to high-level language is a strategic problem for human beings to control the computer, then the specific setting variables and loops are the specific tactical problems of controlling the computer. What we are learning now is the strategy of using VBS to make computers work for us.

Second, start with the simplest things.

Network hawking script:

Vbs i

Vbs iTunes 10

While I > 0

SayString sells XXX at a negotiable price.

Vbs i=i-1

Delay 10000

Endfor

Many people scoffed when they saw this script. There are many ways to achieve continuous hawking, some of which are several times simpler than this script. But as the lecture goes on, we will find that VBS provides us with a powerful tool. Let's start with what these lines mean.

Vbs I / / tells the computer that there is a variable called I.

Vbs iTunes 10 / / this variable is 10

While I > 0 / / when this variable is greater than 0, execute the following until you see the first endfor.

SayString sells XXX at a negotiable price. / / keystroke statement: output text

The variable vbs i=i-1 / / subtracts 1, and then takes the number minus 1 as the value of I.

Delay 10000 / / keystroke statement: pauses for 10 seconds (10000 milliseconds)

Endfor / / go back to while

Effect: it ends after 10 hawks.

Now I'm going to make some effort to explain why I have to make so much trouble.

The use and importance of variables

In fact, this program can be written as

SayString sells XXX at a negotiable price.

Delay 10000

SayString sells XXX at a negotiable price.

Delay 10000

…… Repeat N times

SayString sells XXX at a negotiable price.

Delay 10000

In fact, no matter how complex the program segment can be reduced to a sequential program, using a lot of complex things is not to show programming ability, but for their own convenience.

We may not feel anything when we keep selling XXX, but what about when we sell YYY? Do you want to change it all? Or do we have to repeat it 1000 times and then only repeat it 500 times? do we have to count it carefully and then delete the rest? Of course, it's more comfortable for us to edit this Mini Program. But in order to improve the development, we have to expand the program, and we must also rely on our variable friends.

A variable is actually a character code, like your name and mine, in order to distinguish each variable and let them work separately. You can name variables with numbers, characters, and underscores, but not with Chinese characters, spaces, and other strange symbols, and numbers cannot be used for the first character.

Before using variables, you have to write a statement like vbs I, which means that now I assign a variable, named I, to participate in the running of the program. In fact, you can directly use I somewhere in the program without going through such a registration procedure, but it has been proved to be a bad habit that makes it difficult for you to write a big program.

Then vbs iTunes 10 tells the program that the variable I now has a value of 10, and that whenever I is used later, it is equivalent to 10 there. For example, vbs j=i+1 is actually the equivalent of jdeclare 10, so the value of j is 11.

The charm of a variable is that it can not only replace numbers, but also characters, but characters have their own particularity compared with numbers.

For example:

Vbs I = "character"

Vbs j = "concatenation"

Vbs Aguili & j

At this point, an is string concatenation. Notice the two new symbols that appear here: the sign and the & symbol. Someone may have guessed their role. " The contents between the symbols are characters. Computers have a completely incompatible understanding of vbs iTunes 10 and vbs I = "10". The & sign is a string connection. If axij & I, then an is a concatenated character.

Once we know the use of variables, we can make the hawking program more interesting. For example, if we want the program to say different things, first say 10 times to sell XXX, then 10 times to sell YYY. Then we can write as follows:

Vbs i

Vbs iTunes 10

While I > 0

Ifexpression i5

SayString sells YYY at a negotiable price.

Endif

Vbs i=i-1

Delay 10000

Endfor

In fact, we use a little programming technique, which is to use the size of the variable I to control the direction of the program. It can be seen that the first 5 times sold YYY, the last 5 times sold XXX.

Or we can call XXX once, then YYY again, and then repeat the previous action:

Vbs i

Vbs iTunes 10

While I > 0

Ifexpression i mod 2 = 0

SayString sells XXX at a negotiable price.

Endif

Ifexpression i mod 2 = 1

SayString sells YYY at a negotiable price.

Endif

Vbs i=i-1

Delay 10000

Endfor

A method of running the I control program is also used here. Mod is the same operation symbol as +, -, and *, which serves to take the remainder. For example, 10 mod 2 = 0 means 10 divided by 2, and the rest is 0. Similarly 9 mod 2 = 1 mod 8 mod 2 = 0 mod 7 mod 2 = 1 mod 6 mod 2 = 1...

This is the end of "how to understand VBS". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report