Page 1 of 1
How to make math operations from 2 Gadgets??
Posted: Mon May 04, 2020 8:53 pm
by LESTROSO
hi,...
i'm a newbie... i would like to know how i can for example take the number value of a gadget and another gadget multiply them (forexample) and put the results in a third gadgettext......
I thank you a lot..in advance..Lestroso

Re: How to make math operations from 2 Gadgets??
Posted: Mon May 04, 2020 8:59 pm
by netmaestro
Code: Select all
SetGadgetText(3, Str(Val(GetGadgetText(2))*Val(GetGadgetText(1))))
Looks pretty close if I haven't forgotten a bracket.
Re: How to make math operations from 2 Gadgets??
Posted: Tue May 05, 2020 12:51 pm
by LESTROSO
Dear netmaestro ,
I thank you a lot very much!!! I'll try as soon as possible your code...Best regards, Lestroso

Re: How to make math operations from 2 Gadgets??
Posted: Tue May 05, 2020 6:29 pm
by LESTROSO
Hi to everyone....
i have 2 other questions to solve.....
i need to divide like below a gadget /1 but this don't work...
Code: Select all
SetGadgetText(3, Str(Val(GetGadgetText(2))/1
and another problem a little more complicated :
Code: Select all
SetGadgetText(3, roundup (Str(Val(1/GetGadgetText(2))/Val(GetGadgetText(1)*Val(GetGadgetText(4)))))-0,5
I'm a little confused....can somebody help me please???
Best regards,
Lestroso

Re: How to make math operations from 2 Gadgets??
Posted: Tue May 05, 2020 6:48 pm
by HeX0R
There is a manual included in PB...
ValF(),
StrF(),
ValD(),
StrD(),
Int(),
Round()
Re: How to make math operations from 2 Gadgets??
Posted: Tue May 05, 2020 7:04 pm
by Lord
LESTROSO wrote:..
i need to divide like below a gadget /1 but this don't work...
Code: Select all
SetGadgetText(3, Str(Val(GetGadgetText(2))/1
...
You can't divide like that: SetGadgetText(...)
/1
And you have 4 openig brackets and only 2 closing brackets.
Re: How to make math operations from 2 Gadgets??
Posted: Tue May 05, 2020 7:11 pm
by Little John
And an additional remark:
Writing text to gadgets, reading text from gadgets and math operations are completely independent from each other. So asking questions like these is not only a strange approach, but also makes things look more convoluted than necessary.
Better use some variables, e.g.:
Code: Select all
a = Val(GetGadgetText(1))
b = Val(GetGadgetText(2))
c = (a + b) * 27
SetGadgetText(3, Str(c))
Re: How to make math operations from 2 Gadgets??
Posted: Tue May 05, 2020 8:27 pm
by LESTROSO
Hi....thank you to everybody!!!
I have appriciated so much your ideas....
i'll try...
thanks again for the help...Lestroso

Re: How to make math operations from 2 Gadgets??
Posted: Tue May 05, 2020 9:38 pm
by LESTROSO
hI..i'm sorry...but i'm a new to purebasic...i don't see examples of this kind..
i have problems with syntax of this formula...can you help me please??
Code: Select all
TOT1= (Round((1/B4/D6*C1)-0,5),#PB_Round_Up))
Thanks a lot, Lestroso

Re: How to make math operations from 2 Gadgets??
Posted: Tue May 05, 2020 10:16 pm
by infratec
Hm...
you have 5 fingers on one hand (I hope).
So please count the opening brackets and the closing brackets with the help of your fingers.
If you do it like this, you will see that they don't match.
You know the rule: multiplications and divisions have a higher priority than minus and plus?
You know that float values in a programming language uses a dot as decimal point?
You know, that a variable in PB is an integer if it is not defined?
You know what an integer is?
If you know all these, than you know why your code is not working as expected.
Maybe this is what you want:
Code: Select all
TOT1.f = Round(1 / B4 / D6 * C1 - 0.5, #PB_Round_Up)
But without the original formula, this is only a guess.
Re: How to make math operations from 2 Gadgets??
Posted: Wed May 06, 2020 12:22 pm
by LESTROSO
Dear Infratec,
you helped me so much!!! Thanks a lot ...I have succeded to build my app...thanks again..Lestroso
