field and variable

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
propeller
Posts: 22
Joined: Sat Oct 13, 2018 12:22 pm
Location: Austria

field and variable

Post by propeller » Wed Nov 14, 2018 7:50 pm

hi there, am i stupid?

i have two fields. in these two fields i type in some numbers. then i have a button. the script of the button should multiply the numbers of the fields. what am i doing wrong? do i have to tell the app that the fields contain numbers? if yes, please how :)

Code: Select all

on mouseUp pButtonNumber
   put fld "Felda" into tFelda
   put fld "Feldb" into tFeldb
   put Felda*Feldb into tErgebnis
   
   end mouseUp


thank you for your help
have a nice evening.

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: field and variable

Post by jmburnod » Wed Nov 14, 2018 8:04 pm

Hi,
You have some type in your script (Felda*Feldb)
This should work

Code: Select all

on mouseUp pButtonNumber
   put fld "Felda" into tFelda
   put fld "Feldb" into tFeldb
   put tFelda * tFeldb into tErgebnis
   put tErgebnis
end mouseUp
Best regards
Jean-Marc
https://alternatic.ch

propeller
Posts: 22
Joined: Sat Oct 13, 2018 12:22 pm
Location: Austria

Re: field and variable

Post by propeller » Wed Nov 14, 2018 10:30 pm

does still give me the same error: Operators *: error in left operand. i checked if the fields are named correctly and they are.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4000
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: field and variable

Post by bn » Wed Nov 14, 2018 10:55 pm

Hi Propeller,

do you use decimals? If so do you use comma or colon?

a correct decimal would look like

5.2

Do you have any other text/characters in the left field?

Try to clear both fields and then type in the numbers you want.

Kind regards
Bernd

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

Re: field and variable

Post by SparkOut » Wed Nov 14, 2018 11:07 pm

As bernd suggests, this error indicates that the contents of field "Felda" is not a number. (Perhaps using a comma as a decimal separator, where LC needs a point. Or, if you have a field with a single line height, someone has entered a value, then hit the return key, so the field looks empty, then a new value is typed in the field. Or something else has happened to put other content into the field so the multiplication operator cannot interpret the first value as a number.)
You need to validate the contents in order to ensure a genuine mathematical operation can be performed.

propeller
Posts: 22
Joined: Sat Oct 13, 2018 12:22 pm
Location: Austria

Re: field and variable

Post by propeller » Thu Nov 15, 2018 9:02 pm

dear people, bn was right - i did use , instead of . :D

thank you for helping me an beeing kind to a noob.

Klaus
Posts: 13828
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: field and variable

Post by Klaus » Thu Nov 15, 2018 9:44 pm

Hi Michael,

I ususally use two little function to compute (german) numbers in LC fields:.
Put these into the stack script and use them anywhere you need to:

Code: Select all

function ohnekomma tNumber
  ## ohne komma = german for: without comma
  replace COMMA with "." in tNumber
  return tNumber
end ohnekomma

function mitkomma tNumber
  ## with komma = german for: with comma
  replace "." with COMMA in tNumber
  return tNumber
end mitkomma
Then use them before computing and again before dispklaying to german users:

Code: Select all

...
put fld "a decimal number in german" into tFa
put fld "another decimal number in german" into tFb

## Before computing:
put ohnekomma(tFa) intoi tFa
put ohnekomma(tFb) into tFb

## Now compoute witn english numbers
put tFa * tFb into tResult

## "convert" back to german before displaying
put mitkomma(tResult) into fld "ergebnis"
...
Best

Klaus

propeller
Posts: 22
Joined: Sat Oct 13, 2018 12:22 pm
Location: Austria

Re: field and variable

Post by propeller » Thu Nov 15, 2018 9:48 pm

Coooool. Thank you, Klaus

mrcoollion
Posts: 720
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: field and variable

Post by mrcoollion » Fri Nov 16, 2018 8:38 am

put mitkomma(ohnekomma(tFa) * ohnekomma(tFb)) into fld "ergebnis" :D

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”