The following is a key event handler for a custom entryfield that handles dates. It recognizes special keystrokes to move the date forward or backward one day, to the first and last day of the month, and so forth:

function key(nChar, nPosition)

   local c1 

   c1 = upper(chr(nChar)) 

   do case 

      case c1 == "T" // Today 

         this.value := date() 

      case c1 == "-" or c1 == "_" // Next day 

         this.value-- 

      case c1 == "+" or c1 == "=" // Previous day 

         this.value++ 

      case c1 == "M" // First day of the month 

         this.value := FDoM(iif( this.lastKey == "M", --this.value, this.value)) 

      case c1 == "H" // Last day of the month 

         this.value := LDoM(iif(this.lastKey == "H", ++this.value, this.value)) 

      case c1 == "Y" // First day of the year 

         this.value := FDoY(iif(this.lastKey == "Y", --this.value, this.value)) 

      case c1 == "R" // Last day of the year 

         this.value := LDoY(iif(this.lastKey == "R", ++this.value, this.value)) 

      otherwise 

         this.lastKey := null // Clear stored keystroke 

         return true // Handle key normally 

   endcase 

   this.lastKey := c1 // Store as property for comparison next time 

 return false // Ignore key 

The functions FDoM( ), LDoM( ), FDoY( ), and LDoY( ) are defined elsewhere.