Chapter 13 Exploring Text Files and String Processing 331
TABLE 13-3 Visual Basic Relational Operators
Operator Meaning
<> Not equal to
= Equal to
< Less than
> Greater than
<= Less than or equal to
>= Greater than or equal to
A character is “greater than” another character if its ASCII code is higher. For example, the
ASCII value of the letter B is greater than the ASCII value of the letter A, so the expression:
"A" < "B"
is true, and the expression:
"A" > "B"
is false.
When comparing two strings that each contain more than one character, Visual Basic begins
by comparing the first character in the first string with the first character in the second string
and then proceeds character by character through the strings until it finds a difference. For
example, the strings Mike and Michael are the same up to the third characters (k and c).
Because the ASCII value of k is greater than that of c, the expression:
"Mike" > "Michael"
is true.
If no differences are found between the strings, they are equal. If two strings are equal
through several characters but one of the strings continues and the other one ends, the
longer string is greater than the shorter string. For example, the expression:
"AAAAA" > "AAA"
is true.
Sorting Strings in a Text Box
The following exercise demonstrates how you can use relational operators, concatenation,
and several string methods to sort lines of text in a text box. The program is a revision of the
Quick Note utility and features an Open command that opens an existing file and a Close
command that closes the file. There’s also a Sort Text command on the File menu that you
can use to sort the text currently displayed in the text box.