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
-
Samuele
- Posts: 282
- Joined: Mon Oct 11, 2021 7:05 pm
- Location: Italy
Post
by Samuele » Tue Mar 15, 2022 9:10 pm
Hi how can i put two subtracted variables in a third variable? for example
Code: Select all
put (Var1 - Var2) into Var3 #(this doesn't work)
Thanks!
Samuele.
-
Klaus
- Posts: 13829
- Joined: Sat Apr 08, 2006 8:41 am
- Location: Germany
-
Contact:
Post
by Klaus » Tue Mar 15, 2022 9:15 pm
Leave out the parenthesis:
-
dunbarx
- VIP Livecode Opensource Backer
- Posts: 9670
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Post
by dunbarx » Tue Mar 15, 2022 9:16 pm
Samuele.
It sure should. Sure you have it exactly right? Are you sure that each variable contains ONLY a number???
Craig
-
andresdt
- Posts: 146
- Joined: Fri Aug 16, 2019 7:51 pm
Post
by andresdt » Tue Mar 15, 2022 9:16 pm
Samuele wrote: ↑Tue Mar 15, 2022 9:10 pm
Hi how can i put two subtracted variables in a third variable? for example
Code: Select all
put (Var1 - Var2) into Var3 #(this doesn't work)
Thanks!
that should work if both of your variables contain a number.
Code: Select all
if Var1 is a number and Var2 is a number then
put Var1 - Var2 into Var3
end if
-
dunbarx
- VIP Livecode Opensource Backer
- Posts: 9670
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Post
by dunbarx » Tue Mar 15, 2022 9:17 pm
Klaus.
The parens do not harm the line of code.
Craig
-
Klaus
- Posts: 13829
- Joined: Sat Apr 08, 2006 8:41 am
- Location: Germany
-
Contact:
Post
by Klaus » Tue Mar 15, 2022 9:19 pm
Yes, I was not sure and had to make a quick test.
True, parens do not make a difference.
-
dunbarx
- VIP Livecode Opensource Backer
- Posts: 9670
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Post
by dunbarx » Tue Mar 15, 2022 9:22 pm
OK.
So I am betting a dollar that the variables have non-numeric trash mixed in. Anyone?
Craig
-
FourthWorld
- VIP Livecode Opensource Backer
- Posts: 9842
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
-
Contact:
Post
by FourthWorld » Tue Mar 15, 2022 9:27 pm
dunbarx wrote: ↑Tue Mar 15, 2022 9:22 pm
So I am betting a dollar that the variables have non-numeric trash mixed in. Anyone?
Sanuele, do you have Suppress Errors turned on?
Normally an issue with addition should throw a script error telling you exactly which variable is preventing the arithmetic from happening.
-
Samuele
- Posts: 282
- Joined: Mon Oct 11, 2021 7:05 pm
- Location: Italy
Post
by Samuele » Wed Mar 16, 2022 12:15 am
FourthWorld wrote: ↑Tue Mar 15, 2022 9:27 pm
dunbarx wrote: ↑Tue Mar 15, 2022 9:22 pm
So I am betting a dollar that the variables have non-numeric trash mixed in. Anyone?
Sanuele, do you have Suppress Errors turned on?
Normally an issue with addition should throw a script error telling you exactly which variable is preventing the arithmetic from happening.
ahh, it did throw an error that i didn't understand, but i have changed the script to
and now it seems to be working.
Samuele.
-
dunbarx
- VIP Livecode Opensource Backer
- Posts: 9670
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Post
by dunbarx » Wed Mar 16, 2022 2:16 am
Samuele.
I cannot see any way that adorning with parentheses fixed the problem. In fact, as we know, you do not need any at all.
Have you tried what andresdt suggested, that is, to validate that the two variables contain only pure numbers before you try to do any arithmetic with them?
Craig
Last edited by
dunbarx on Wed Mar 16, 2022 3:01 pm, edited 1 time in total.
-
Klaus
- Posts: 13829
- Joined: Sat Apr 08, 2006 8:41 am
- Location: Germany
-
Contact:
Post
by Klaus » Wed Mar 16, 2022 9:47 am
Samuele wrote: ↑Wed Mar 16, 2022 12:15 am
...
ahh, it did throw an error that i didn't understand, but i have changed the script to
and now it seems to be working.
Don't you think that it might be a good idea to ask here what the error means?
-
Samuele
- Posts: 282
- Joined: Mon Oct 11, 2021 7:05 pm
- Location: Italy
Post
by Samuele » Wed Mar 16, 2022 9:58 am
Nuuu what it means?
Samuele.
-
Klaus
- Posts: 13829
- Joined: Sat Apr 08, 2006 8:41 am
- Location: Germany
-
Contact:
Post
by Klaus » Wed Mar 16, 2022 12:23 pm
Samuele wrote: ↑Wed Mar 16, 2022 9:58 am
Nuuu what it means?
???