Using Keypress

Post

Posted
Rating:
#1 (In Topic #312)
Avatar
Regular
cage is in the usergroup ‘Regular’
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.

Code (gambas)

  1. ' Gambas class file
  2.  
  3. Public Sub Form_Open()
  4. '*********************************
  5. 'Insert a label and text box
  6. 'on the default window
  7. 'and leave them as the default
  8. 'names
  9. '*********************************
  10.  
  11. Public Sub Form_KeyPress()
  12.  
  13. Dim strChar As String
  14. '*********************************
  15. 'Assign the keycode to strChar
  16. '*********************************
  17. strChar = String.Chr(Key.Code)
  18. '**********************************
  19. 'If the Key.Code is Key.Esc then
  20. 'close the window.
  21. '**********************************
  22. If Key.Code = Key.Esc Then Me.Close
  23.  
  24. '***************************************
  25. 'Check to see if strChar is a number
  26. '***************************************
  27. If IsDigit(strChar) = False Then
  28.   '***********************************************
  29.  'If false then report not a number
  30.  'and report False
  31.  '************************************************
  32.   Label1.Text = "False"
  33.   TextBox1.Text = "Not a number "
  34. '*************************************
  35. 'If strChar is a number then display
  36. 'the number and reprot true
  37. '*************************************
  38.     Label1.Text = "True"
  39.    TextBox1.Text = strChar
  40.  
  41.  
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Guru
cogier is in the usergroup ‘Guru’
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
Online now: No Back to the top
1 guest and 0 members have just viewed this.