Keyboard Events: Example
In this section, we will develop a small program
that converts every lowercase letter typed into the
text box to uppercase letter. Start a new project
and place one text box and one label control. Your
application should look like this.
Control |
Property |
Value |
Form |
Name
|
frmKeyboard
|
Form |
Caption
|
Handling Keyboard
|
Text Box |
Name |
txtKeyPress |
Text Box |
Text |
Empty |
Label |
Caption |
Keyboard Events |
The source code needed for this example is stored
in the
"Source Code\Chapter9\Keyboard" directory
available in the CD. To open the project double click
the "Keyboard.vbp" file.
Private Sub txtKeyPress_KeyPress(KeyAscii
As Integer)
If (KeyAscii >= 97) And (KeyAscii <= 122)
Then
KeyAscii = KeyAscii - 32
End If
End Sub
The ASCII value range for lowercase letters is 97
"for a" to 122 "for z". The ASCII
value difference between the uppercase letters and
lowercase letters is 32. If the user types a lowercase
letter, the KeyPress event converts it into an uppercase
letter.
|
|
In this chapter, you were introduced
to internal functions. You will learn about
more internal functions in the coming chapters.
VB supplies these functions so that you don't
have to write tedious code yourself.
|
|