Character variables store a single Unicode character in two bytes. In effect, characters are Unsigned Short integers (UInt16), but the Framework provides all the tools you need to work with characters without having to resort to their numeric values (a very common practice for the older among us).
To declare a Character variable, use the Char data type:
Dim char1, char2 As Char
You can initialize a Char variable by assigning either a character or a string to it. In the latter case, only the first character of the string is assigned to the variable. The following statements will print the characters a and A to the Output window:
Dim char1 As Char = "a", char2 As Char = "ABC" Debug.WriteLine(char1) Debug.WriteLine(char2)
These statements will work only if the Strict option is off. If it’s on, the values assigned to the char1 and char2 variables will be marked in error and the code will not compile. To fix the error, change the Dim statement as follows:
Dim char1 As Char = "a"c, char2 As Char = "A"c
(This tells the compiler to treat the values of the variables as characters, not strings.) When the Strict option is on, you can’t assign a string to a Char variable and expect that only the first character of the string will be used.