Adding fields with £ signs

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
bsouthuk
Posts: 261
Joined: Fri Dec 05, 2008 7:25 pm

Adding fields with £ signs

Post by bsouthuk »

Wonder if someone can help.

I'm working on a commission calculator and want certain fields with numbers in them to show the £ sign. The problem is, I use the fields with £ signs to + and subtract with other fields with £ signs and when I get a coding error which I assume is because Rev sees the £ sign as not a digit!

How do I get around this?

Cheers

Dan
RRobert
Posts: 151
Joined: Sat Feb 28, 2009 8:20 pm

Re: Adding fields with £ signs

Post by RRobert »

Hello Dan,

why you do not add and remove the british pound sign before you do the calculation?

Robert
bsouthuk
Posts: 261
Joined: Fri Dec 05, 2008 7:25 pm

Re: Adding fields with £ signs

Post by bsouthuk »

I have tried this using code:

Code: Select all

put "£" & field "A" + field "B" into field "C"
However, I then have to use field C to + to field D but as the £ is in field C I get a coding error
bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4219
Joined: Sun Jan 07, 2007 9:12 pm

Re: Adding fields with £ signs

Post by bn »

Dan,
you could take out the £ sign temporarily.

Code: Select all

put field "x" into tData
replace "£" with empty in tData
put tData + tWhatToAdd into tData
put "£" && tdata into field "result"
regards
Bernd
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10502
Joined: Wed May 06, 2009 2:28 pm

Re: Adding fields with £ signs

Post by dunbarx »

It might be easier to manage if you use a function when this arises:

Code: Select all

function goodNumber tText
   repeat for each char theChar in tText
      if theChar is in ".0123456789" then put theChar after temp
   end repeat
   return temp
end goodNumber
So you can say get "£" & goodNumber(firstData) + goodNumber(secondData).

This makes sure that ANY errant character that might hang rev up is eliminated. I get these now and then due to typos, some of which are invisible.

Craig Newman
bsouthuk
Posts: 261
Joined: Fri Dec 05, 2008 7:25 pm

Re: Adding fields with £ signs

Post by bsouthuk »

That seems are better way thank you Craig.

Are you saying to place this script in the stact script, therefore whenever there is a £ sign in fields that are involved in calculations with other fields that have the £ sign then the stack script will mitigate any code errors and the £ sign will be ignored?

Cheers

Dan
Post Reply