KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Ways to filter numbers in an object variable
PRODUCT: 4D | VERSION: 13.2 | PLATFORM: Mac & Win
Published On: February 15, 2013

There are a couple of ways to filter keystrokes such that only numbers will be displayed in an object variable. The most simple way to do this is via the object Property List using the Entry Filter property as shown:



Another way is to use the form event On Before Keystroke. Once the user enters a character in the input variable the form event will fire and the following code can be executed:

Case of
   : (Form event=On Before Keystroke)
   //Get the character entered in the variable
   $input:=Keystroke
   //If the character is "0" or a backspace, don't do anything special
   If ($input#"0") & (Character code(Keystroke)#Backspace)
      //If the character entered is not a number, Num will return 0
      $temp:=Num($input)
      //If the character entered is not a number,
      //filter the keystroke such that nothing is entered
      If ($temp=0)
         FILTER KEYSTROKE("")
      End if
   End if
End case