Page 139 - Excel Progamming Weekend Crash Course
P. 139

h540629 ch09.qxd  9/2/03  9:34 AM  Page 114




                114                                                         Saturday Morning

                  Val(“1,000”)               ‘ returns the value 1
                  Val(“A123”)                ‘ Returns the value 0.

                          Some areas of the world use a comma instead of a period as a decimal point.
                          Val will not recognize this even if the operating system is set to the proper
                   Tip    locale. In this case you can use the CDbl function to convert a string such as
                          “1,234” to a numerical value. Unlike Val, however, CDbl will generate an
                          error if there are any nonnumeric characters in the string.



               The Str Function
               The Str function converts a numerical value into a string. Specifically, it returns a type
               Variant containing a string representation of the number. The syntax is:

                  Str(value)
                  Value is any numeric expression. The returned string includes a leading space for posi-
               tive numbers.


               Working with ASCII Values
               Computers use numerical values internally for all data. Text is represented by assigning a
               numerical value to each letter, digit, and symbol. Obviously, for computers to be able to
               share text data, they have to all use the same codes. The first widely adopted standard was
               the ASCII character set which used the values 0 to 127 to represent the letters, numerals,
               and commonly used punctuation marks and characters. For example, lowercase letters a
               through z are represented by the values 97 to 122. The ANSI (American National Standards
               Institute Code) expanded on the ASCII code by adding values 128 to 255 to represent less
               frequently used symbols as well as letters with diacritical marks (such as _ and é) that are
               used in many languages. ANSI is sometimes called extended ASCII.

                          The ASCII codes 0 to 31 represent nonprinting characters such as line feed,
                          carriage return, and tab. (ASCII stands for American Standard Code for
                   Note   Information Interchange and is pronounced “ass-key.”)
                  It soon became apparent that the 255 possible ANSI values were not sufficient for the
               number of characters that computers needed to work with. As a result, the Unicode standard
               was developed, using values from 0 to 65,535 to represent a much wider range of characters,
               including mathematical symbols and dingbats. Only about 39,000 of these codes are currently
               assigned, leaving plenty of room for future expansion.
                  VBA provides functions for working with both ASCII and Unicode character codes.
   134   135   136   137   138   139   140   141   142   143   144