Dollar value defined fields

Something you want to see in a LiveCode product? Want a new forum set up for a specific topic? Talk about it here.

Moderator: Klaus

Post Reply
mikemc
Posts: 60
Joined: Sun May 10, 2015 5:42 pm

Dollar value defined fields

Post by mikemc » Sun May 24, 2015 3:06 am

I wish there was a simple was to define fields as dollar values with $ signs and commas inserted by the system, Thanks

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Dollar value defined fields

Post by dunbarx » Sun May 24, 2015 3:57 am

Hi.

Kind of how Excel does it? As a textStyle?

This would be a convenience, I suppose, but is so simple to implement as a function that it is not likely to excite the LC team. Do you need any help at all in writing such a function, or storing it in a place where it would be accessible across LC?

Craig Newman

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10081
Joined: Fri Feb 19, 2010 10:17 am

Re: Dollar value defined fields

Post by richmond62 » Sun May 24, 2015 12:40 pm

I wonder what would "excite the LC team" as almost none of the feature requests seem to be even acknowledged.

mikemc
Posts: 60
Joined: Sun May 10, 2015 5:42 pm

Re: Dollar value defined fields

Post by mikemc » Sun May 24, 2015 2:23 pm

Yes like excel would be great. But if that can't happen I do need some help
I use this complicated code to display the field properly as a dollar value then when I go to use it on a later card
the commas and $ don't allow it to be recogonized as a number so I don't know what to do

on mouseUp --format number with commas
put fld c1 && MoneyFormat(fld money) into fld money
end mouseUp

function MoneyFormat TheValue --123456789.9876 to $123,456,789.99
local TheDecimal
set the numberFormat to "0.00" --money
put TheValue * 1 into TheValue --calc to convert
set the itemDel to "."
if item -1 of TheValue <> empty then
put item -1 of TheValue into TheDecimal
delete item -1 of TheValue --decimal number
end if
set the itemDel to "," --default
repeat with i = length(TheValue)-3 down to 3 step -3
put comma after char i of TheValue
end repeat
set the numberFormat to "0.######" --default
return "$"& TheValue &"."& TheDecimal --money
end MoneyFormat

There must be an easier way my app uses large $ values HELP!

SparkOut
Posts: 2943
Joined: Sun Sep 23, 2007 4:58 pm

Re: Dollar value defined fields

Post by SparkOut » Sun May 24, 2015 3:14 pm

use a setProp handler to store the numeric value and the display value on the field together, as per this thread

http://forums.livecode.com/phpBB2/viewt ... 696#p12696

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Dollar value defined fields

Post by FourthWorld » Sun May 24, 2015 4:09 pm

SparkOut wrote:use a setProp handler to store the numeric value and the display value on the field together, as per this thread

http://forums.livecode.com/phpBB2/viewt ... 696#p12696
GetProp/setProp are handy, but only work if no script locks messages. This is slated to be fixed, but it's been a while since that was decided so I don't know when we'll see it implemented.

So in the meantime, as much as I like the idea of property triggers, I stick with humble getter/setter functions and commands for now.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

mikemc
Posts: 60
Joined: Sun May 10, 2015 5:42 pm

Re: Dollar value defined fields

Post by mikemc » Sun May 24, 2015 4:35 pm

It will take me some time to sort out this new code and where to put it. This is just my first month
so on dollar fields I am using a separate field to display the $ sign and rounding off the decimal values and ignoring the
commas. Its simple but works good with the exemption of the missing commas
the rounding is OK because the cents don't matter for the application.

Thanks for the homework when I get some time I will try to figure out how to do it right :)

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Dollar value defined fields

Post by dunbarx » Sun May 24, 2015 9:56 pm

Hi.

Make a field "arg" with this in its script. You will also need another field "f1". You mentioned homework. That is my bailiwick.

Your homework is to play with the code and learn as much as you can about it.

Code: Select all

on returnInField
    put digitToWord(fld "arg") into fld "f1"
end returnInField

function digitToWord theDigits
   put "One,Two,Three,Four,Five,Six,Seven,Eight,Nine" into ones
   put "Ten,Eleven,Twelve,Thirteen,Fourteen,Fifteen,Sixteen,Seventeen,Eighteen,Nineteen" into teens
   put ",Twenty,Thirty,Forty,Fifty,Sixty,Seventy,Eighty,Ninety" into tens
   set numberformat to "#.00"
    if "."is not in theDigits then put ".00" after theDigits
      get offset(".",theDigits)
      if it > 7 then
            answer "You can't afford to write this check"
            exit to top
      end if
   get offset(".",theDigits)
   if char it + 1 of theDigits = "" then put "00" after theDigits
   if it <> 0 then put " Dollars and" && char it + 1 to it + 2 of theDigits & "/100" into temp
   delete char it to it + 2 of theDigits
   get number(chars of theDigits)
   if char it - 1 of theDigits = 1 then put item char it of theDigits + 1 of teens before temp
   else
      put item char it of theDigits of ones before temp
      put item char it - 1 of theDigits of tens & space before temp
   end if
   
   if it >= 3 and char it - 2 of theDigits <> 0 then put item char it - 2 of theDigits of ones && "Hundred" & space before temp
   if it = 4 then put item char it - 3 of theDigits of ones && "Thousand" & space before temp
   if it = 5 and char 1 of theDigits = 1 then put item (char it - 3 of theDigits + 1) of teens  && "Thousand" & space before temp
   else if it = 5 then put item char it - 4 of theDigits of tens && item char it - 3 of theDigits of ones && "Thousand" & space before temp
   if it = 6 then put item char 1 of theDigits of ones && "Hundred" && item char 2 of theDigits of tens && item char 3 of theDigits of ones & " Thousand "  before temp
   
   return temp
end digitToWord
Craig
Last edited by dunbarx on Mon May 25, 2015 5:49 am, edited 1 time in total.

mikemc
Posts: 60
Joined: Sun May 10, 2015 5:42 pm

Re: Dollar value defined fields

Post by mikemc » Mon May 25, 2015 12:01 am

thanks I'll give it a try

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Dollar value defined fields

Post by dunbarx » Mon May 25, 2015 7:03 am

Mike.

The gadget I gave you does sort of the opposite of what you asked for. It is something to step through when you have nothing better to do. It is possibly useful if you want to go all around your original feature request. Take your time...

Craig

Post Reply