General information
Category:
Forms & Form designer
Title:
Calculator style Textbox
There have been a number of postings regarding Calcualtor Style Numeric Textboxes.
The following is offered as a simple solution for anyone with this requirement.
This structure will allow the user to add or subtract from a present value in a TextBox simply by pressing the + or - key when the field gets focus. Or if the user enters a new value when the field gets focus, add or subtract from that new value. Eg., Enter 1000.25 press + key enter 1000.25 press any navigation key, result 2,000.50
Init of the Form
* Create a public variable
Public mvalue
mvalue=0
TextBox - Gotfocus Event
this.inputmask="" && removes the input mask until LostFocus
this.setfocus
* Allows for SelectOnEntry when the user enters the field by Mouse. Note - SelectOnEntry of the TextBox must be set to .T.
* Store the present value to a variable
if mvalue=0
mvalue=0.00
else
mvalue=this.value
endi
TextBox - LostFocus Event
* Restore the InputMask to show punctuation
this.inputmask="99,999,999.99"
* This is also in the properties of the textbox
TextBox - KeyPress Event
Lparameters nKeyCode, nShiftAltCtrl
do case
case nKeyCode=7
This.value=0.00
case nKeyCode=43 or nKeyCode=45
mvalue=mvalue+this.value
This.value=0.00
case nKeyCode=9 or nKeyCode=15 or nKeyCode=13;
or nKeyCode=24 or nKeyCode=5
This.value=mvalue+this.value
Endc
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only