330 Part II Programming Fundamentals
In the 1980s, IBM extended ASCII with codes 128 through 255, which represent accented,
Greek, and graphic characters, as well as miscellaneous symbols. ASCII and these additional
characters and symbols are typically known as the IBM extended character set.
The ASCII character set is still the most important numeric code for beginning programmers
to learn, but it isn’t the only character set. As the market for computers and application
software has become more global, a more comprehensive standard for character
representation called Unicode has emerged. Unicode can hold up to 65,536 symbols—plenty
of space to represent the traditional symbols in the ASCII character set plus most (written)
international languages and symbols. A standards body maintains the Unicode character
set and adds symbols to it periodically. Windows XP, Windows Vista, Windows 7, and Visual
Studio have been specifically designed to manage ASCII and Unicode character sets. (For
more information about the relationship between Unicode, ASCII, and Visual Basic data
types, see the section entitled “Working with Specific Data Types” in Chapter 5 .)
In the following sections, you’ll learn more about using the ASCII character set to process
strings in your programs. As your applications become more sophisticated and you start
planning for the global distribution of your software, you’ll need to learn more about
Unicode and other international settings.
Working with ASCII Codes
To determine the ASCII code of a particular letter, you can use the Visual Basic Asc function.
For example, the following program statement assigns the number 122 (the ASCII code for
the lowercase letter z) to the AscCode short integer variable:
Dim AscCode As Short
AscCode = Asc("z")
Conversely, you can convert an ASCII code to a letter with the Chr function. For example, this
program statement assigns the letter z to the letter character variable:
Dim letter As Char
letter = Chr(122)
The same result could also be achieved if you used the AscCode variable just declared, as
shown here:
letter = Chr(AscCode)
How can you compare one text string or ASCII code with another? You simply use one of the
six relational operators Visual Basic supplies for working with textual and numeric elements.
These relational operators are shown in Table 13-3.