Page 1 of 1

subtracting two variables

Posted: Tue Mar 15, 2022 9:10 pm
by Samuele
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!

Re: subtracting two variables

Posted: Tue Mar 15, 2022 9:15 pm
by Klaus
Leave out the parenthesis:

Code: Select all

put Var1 - Var2 into Var3

Re: subtracting two variables

Posted: Tue Mar 15, 2022 9:16 pm
by dunbarx
Samuele.

It sure should. Sure you have it exactly right? Are you sure that each variable contains ONLY a number???

Craig

Re: subtracting two variables

Posted: Tue Mar 15, 2022 9:16 pm
by andresdt
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

Re: subtracting two variables

Posted: Tue Mar 15, 2022 9:17 pm
by dunbarx
Klaus.

The parens do not harm the line of code.

Craig

Re: subtracting two variables

Posted: Tue Mar 15, 2022 9:19 pm
by Klaus
Yes, I was not sure and had to make a quick test.
True, parens do not make a difference.

Re: subtracting two variables

Posted: Tue Mar 15, 2022 9:22 pm
by dunbarx
OK.

So I am betting a dollar that the variables have non-numeric trash mixed in. Anyone?

Craig

Re: subtracting two variables

Posted: Tue Mar 15, 2022 9:27 pm
by FourthWorld
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.

Re: subtracting two variables

Posted: Wed Mar 16, 2022 12:15 am
by Samuele
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

Code: Select all

put (Var1 - (Var2)) into Var3
and now it seems to be working.

Re: subtracting two variables

Posted: Wed Mar 16, 2022 2:16 am
by dunbarx
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

Re: subtracting two variables

Posted: Wed Mar 16, 2022 9:47 am
by Klaus
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

Code: Select all

put (Var1 - (Var2)) into Var3
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?

Re: subtracting two variables

Posted: Wed Mar 16, 2022 9:58 am
by Samuele
Nuuu what it means?

Re: subtracting two variables

Posted: Wed Mar 16, 2022 12:23 pm
by Klaus
Samuele wrote:
Wed Mar 16, 2022 9:58 am
Nuuu what it means?
???