Generic Procedure to Increment Number or Date GET Fields

ID: Q96350

2.00 2.50 2.50a MS-DOS kbprg

The information in this article applies to:

SUMMARY

In FoxPro, a generic procedure can be used to increment any numeric or date GET during a program. This procedure can also be used to emulate the spinner (spin box) control used in Windows-based applications.

MORE INFORMATION

The following example shows how a procedure defined in an ON KEY LABEL routine for the PLUS SIGN (+) key can increment a number or date by 1:

   ON KEY LABEL + DO increment WITH VARREAD()
   * pass the variable or field of the current GET
   SET TALK OFF
   CLEAR
   @ 5,5 GET num1 SIZE 1,5 DEFAULT 100
   @ 6,5 GET num2 SIZE 1,8 DEFAULT {01/01/93}
   @ 8,5 GET choice PICTURE "@*hn OK" SIZE 1,4 ;
      DEFAULT "OK" VALID    done()
   READ CYCLE
   ON KEY LABEL +

   FUNCTION done
   CLEAR READ
   RETURN .t.

   PROCEDURE increment
   PARAMETER field
   num = EVALUATE(field)
   * store the contents of the current GET to num
   num = num + 1          && increment the number or date
   STORE num TO &field
   * store the new number back to the current GET variable or field
   SHOW GETS
   RETURN

This procedure is generic and would apply to any GET that is in effect. The VARREAD() function will be able to determine the current GET and increment only that number.

If a spinner type of control is desired, this procedure can be used as a VALID clause on invisible or push buttons to simulate the operation of a spinner control.

Additional reference words: FoxDos 2.00 2.50 2.50a KBCategory: kbprg KBSubcategory:

Last Reviewed: June 18, 1998