Operators *: error in left operand

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

Operators *: error in left operand

Post by jalz » Tue Feb 10, 2015 8:30 pm

Hey all,

I'm having trouble with the following line of code. Its says (Operators *: error in left operand), char 12. field fld_rate contains values like $ 1,250.50 and field hours could have 5.5. I'm using the function bn suggested in my last threadhttp://forums.livecode.com/viewtopic.php?f=7&t=22898 to remove special characters and return the result so I can perform this multiplication.

Thanks as always

Code: Select all

put (accountancyFormatRemove(field "fld_rate")) * (accountancyFormatRemove(field "fld_hours")) into tCost

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

Re: Operators *: error in left operand

Post by dunbarx » Tue Feb 10, 2015 8:49 pm

Hi.

Well, what happens if you test each operand in some way, like:

Code: Select all

answer (accountancyFormatRemove(field "fld_rate")) is a number
That sort of thing.

If you want a validating gadget, then whatever Bernd offered is obviously fine. I wrote a function in about 1989 that strips all chars but "0-9" and the decimal point. Likely everyone on the planet has written something similar. I have it loaded as a library handler. It is not rocket science, but:

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
Craig

jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

Re: Operators *: error in left operand

Post by jalz » Tue Feb 10, 2015 9:20 pm

Hi Craig,

Thanks, I seem to make things more complicated then they have to be. Dont know why. The line of code you posted earlier (below) producing false so I guess the function isn't quite stripping out everything I was expecting. Thanks for the snippet of info.

Code: Select all

 answer (accountancyFormatRemove(field "fld_rate")) is a number 

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

Re: Operators *: error in left operand

Post by dunbarx » Tue Feb 10, 2015 9:28 pm

Better than what I do, which is to make things sillier than they have to be.

Craig

Post Reply