Using Keypress
Posted: Wednesday 11th September 2019 6:13am
This is a little routine to use the Sub Form_KeyPress to determine whether a
key was a numeric number or not. Might be a good routine to place into a
calculator program or a program where you can use keyboard numbers
entered.
key was a numeric number or not. Might be a good routine to place into a
calculator program or a program where you can use keyboard numbers
entered.
' Gambas class file
Public Sub Form_Open()
'*********************************
'Insert a label and text box
'on the default window
'and leave them as the default
'names
'*********************************
End
Public Sub Form_KeyPress()
Dim strChar As String
'*********************************
'Assign the keycode to strChar
'*********************************
strChar = String.Chr(Key.Code)
'**********************************
'If the Key.Code is Key.Esc then
'close the window.
'**********************************
If Key.Code = Key.Esc Then Me.Close
'***************************************
'Check to see if strChar is a number
'***************************************
If IsDigit(strChar) = False Then
'***********************************************
'If false then report not a number
'and report False
'************************************************
Label1.Text = "False"
TextBox1.Text = "Not a number "
Else
'*************************************
'If strChar is a number then display
'the number and reprot true
'*************************************
Label1.Text = "True"
TextBox1.Text = strChar
Endif
End