Based on another conversation here today, I decided to relieve my boredom by tackling this custom control.
As a result I have a working prototype that duplicates the functionality described in https://forum.xojo.com/40662-textedit-calculator
it consists of TWO custom controls that work together, and is 100% Xojo code with no declares or platform specific code.
The first control is a subclass of TextField (qmTextField)
it accepts ONLY valid numeric entries (+,-, 0-9 and “.”)
optionally it can have a qmTAPEFIELD attached, which is activated by pressing the “=” key
The second control is a subclass a listbox (qmTapeField)
this emulates a paper tape calculator attached to a qmTextField (it is NOT a standalone control, like qmTextField is)
only one instance of this control is required per window and is “shared” by all qmTextFields , and by default it is NOT visible
has only ONE property … visibleRows (default and minimum is 4)
qmTextField can stand alone if required and used as a numeric only entry field (in which case “=” is ignored
by adding a line in its open event, you can attach a qmTapeField
me.attachTapeField(qmTapeField1) // nothing more is required to "related" the two controls
The qmTapeField accepts the following keys
0 to 9, and “.” for numeric entry
, - , / , * for mathematical operations (done in the ordered ENTERED, not using equation priority rules)
‘C’ will clear the current entry in progress
‘=’ will display the current answer, and continue without affecting the qmTextField
[Esc] will cancel all operations and return the original value (if any) to the qmTextField
[Enter], [Return], [Tab] close the qmTapeField and return the current “answer” to the qmTextField
qmTapeField automatically positions itself to the location of the qmTextField that called it, and adjusts its own width and height, as well as font
keystrokes involved
3.14159 [entered that value into qmTextField]
= [activated the qmTapeField, 2nd picture]
/ 2 = [ results is the 2nd picture]
[ENTER] closed the qmTapeFiled and returned value to the original qmTextField (3rd picture)
Neil, remember, Quickbooks integrates Quickmath directly to THEIR forms… so the ability to move within the “spreadsheet” AND alter calculations to another cell is at a level totally beyound a custom TextField control…
[quote=331705:@Neil Burkholder]QB doesn’t allow typing % into the Quick Math, but if the original number was a percentage the answer is returned as a percentage.
QB allows commas to be typed in, but it essentially strips the commas and re-formats. So 1,1234 becomes 11,234.[/quote]
commas and decimal points can be problematic since some locales swap the meaning
my control determins which is used as the “decimal point” and allows that to be typed in…
Note : both these controls totally override KEYDOWN and decide what characters are or are not allowed
[quote=331697:@Dave S]Negative Numbers… yes
% … thought about it… not sure exactly how it should work
270 % 50 = 135?
[/quote]
it should be
270 + 50 % = 405
270 - 50 % = 135
[quote=331712:@Jean-Yves Pochez]it should be
270 + 50 % = 405
270 - 50 % = 135[/quote]
no can do… this control is INFIX operators only, (ie X+Y)
it looks at the last result, the current operator, and the current entry
so in you example , it would be waiting for another number
In my use case it is necessary to allow a % sign for percentage based discounts, although the same field can also be used for a dollar amount. Granted most times I wouldn’t expect the user to use the Quick Math to calculate a percentage but who knows… And it QuickBooks it does work.
My users are using QB everyday and expect my app to work just like QB as it really is designed to become part of QuickBooks.