Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - Help: a simple question about long VB overflow. . .
Help: a simple question about long VB overflow. . .
The thing is this: VB will decide in advance what type of numerical value to use to save the operation result according to the types of each numerical value involved in the operation (note that this has nothing to do with what type of variable the operation result is assigned to, because the above process takes place before assignment), 4000 and 10 are integers, so VB is very smart to handle the operation result by integer operation. However, the actual operation result of 40000 is greater than 32767 (the maximum allowed by integer), so there is a sad "overflow" error.

Try the following two sentences, and everything will be clear:

E = 32767 * 10' error, because 32767 is an integer, but the operation result is a long one.

E = 32768 * 10' is not wrong, because 32768 is long and the operation result is also long.

It can't be said that this is a Bug of VB, because in fact VB is intentional! The reason is also very simple, which can save memory resources and improve the operation speed, and the effect is very obvious when performing a large number of small data operations (integer operations with operation results less than 32768).

To avoid this error, you can force a number involved in the operation to be a long number (only one number is needed), for example:

e = 4000 & amp* 10

e = 4000 * 10 & amp;

e = CLng(4000) * 10

Well, after the lecture, let's assign homework and say the following four sentences, which one will go wrong without computer testing:

e = 32767 + 10

e = 32767 - 10

e = 32767 * 10

e = 32767 / 10