Using Keypress

Post Reply
cage
Posts: 32
Joined: Monday 02nd September 2019 5:47am
Location: Phoenix Arizona

Using Keypress

Post by cage » 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.
' 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

User avatar
cogier
Site Admin
Posts: 344
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Using Keypress

Post by cogier » Wednesday 11th September 2019 2:02pm

Hi cage,

Have a look at: -

IsNumber
IsLetter

In fact there are quite a few interesting 'Is' commands
IsAlnum
IsAscii
IsBlank
IsDigit
IsLCase
IsLetter
IsLower
IsNumber
IsPunct
IsSpace
IsUCase
IsUpper

Post Reply