I have a text entry field that needs to be a number.
Here is the code for the entry field.
on keyDown theKey
if theKey is not a number and theKey is not "." then beep
else pass keyDown
end keyDown
I perform a multiplication on this field on exitField and this works fine only allowing numbers and the decimal point to be entered.
If I allow the comma to be entered in the proper locations ie 400,000.00 then the multiplication gives an error as the comma causes the field to not be evaluated as a number.
How can I allow commas and still do a multiplication?
Tom
Displaying a number with commas 400,000.00
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: Displaying a number with commas 400,000.00
Hi.
I guess you will have to think of this as two separate "threads", one of which is the number you display, and the other the number you calculate with. Try this function in the card script:
You could then say:
put goodNumber( "123,456,789.99") + goodNumber("3,000") into fld "answers"
Craig Newman
I guess you will have to think of this as two separate "threads", one of which is the number you display, and the other the number you calculate with. Try this function in the card script:
Code: Select all
function goodNumber tText
repeat for each char tChar in tText
if tChar is in ".0123456789" then put tChar after temp
end repeat
return temp
end goodNumber
put goodNumber( "123,456,789.99") + goodNumber("3,000") into fld "answers"
Craig Newman
Re: Displaying a number with commas 400,000.00
Craig
Thanks, that is close to what I expected, but I didn't know how to implement.
Tom
Thanks, that is close to what I expected, but I didn't know how to implement.
Tom
Re: Displaying a number with commas 400,000.00
Since your field already filters out non-numerical entries, you can shorten the function this way:
And since that is only one line of code, you probably don't need a function, you can just put it directly into the processing handler before you do the multiplication.
Code: Select all
function goodNumber tText
replace comma with empty in tText
return tText
end goodNumber
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com