and the position of
To
within the string is 10, for a total of 7 characters. The 7
characters include the word
String
and the space that follows, which is the
reason for using the
Trim
function.
Using
numbers for calculations
Numbers form the basis for a lot of the information computers store. You
use numbers to perform tasks in a spreadsheet, to express quantities in a
database, and to show the current page in a document. Programs also use
numbers
to count things such as loops, to determine the position of items
such as characters in a string, and to check the truth value of a statement.
Finally, VBA uses numbers in myriad ways,
such as determining which
character to display onscreen or how to interact with your code.
Understanding the numeric types
You look at numbers as a single entity — a number is simply a number. The
computer views numbers in several different ways. The reason for this diver-
sity of viewpoints is that the processor actually works with different kinds of
numbers in different places: one for integer values (those
without a decimal
point) and another for floating-point values (those with a decimal point). At
one time, the math coprocessor that was used to work with money and num-
bers with decimal points was a separate chip within the computer. Today a
single processor performs both integer and floating-point (real) number cal-
culations. The four
basic number types include
Integer:
This is a number without a decimal. An
integer
can hold any
whole number, such as 5, but not a number with a decimal, such as 5.0.
Although these two numbers are the same,
the first is an integer, and the
second isn’t.
Real:
A
real
number is one that contains a decimal point. The decimal
portion doesn’t have to contain a value. The number 5.0 is a perfectly
acceptable real number. A real number is stored
in a completely differ-
ent format than an integer. (The storage technique only matters to the
processor — you don’t need to know it to use VBA.)
Currency:
Financial calculations usually require special accuracy. Even
a small error can cause problems. The
currency
numeric type stores
numbers with extreme precision but at an equally large cost in both
processing time and memory use.
Decimal:
Computers normally store information by using a base 2, or
binary, format. You use a base 10,
or decimal, format for working with
numbers. Small errors can occur when converting from one numbering
system to the other and accumulate to create huge errors. The
decimal
numeric system stores numbers in a simulated base 10 format, which
eliminates many computing errors. However, this system requires more
memory and processing time than any other numeric type.
92
Do'stlaringiz bilan baham: