How to make math operations from 2 Gadgets??

Just starting out? Need help? Post your questions and find answers here.
User avatar
LESTROSO
Enthusiast
Enthusiast
Posts: 124
Joined: Thu Nov 03, 2005 12:30 pm
Location: Italy
Contact:

How to make math operations from 2 Gadgets??

Post 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 :oops: :oops: :oops:
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: How to make math operations from 2 Gadgets??

Post by netmaestro »

Code: Select all

SetGadgetText(3, Str(Val(GetGadgetText(2))*Val(GetGadgetText(1))))
Looks pretty close if I haven't forgotten a bracket.
BERESHEIT
User avatar
LESTROSO
Enthusiast
Enthusiast
Posts: 124
Joined: Thu Nov 03, 2005 12:30 pm
Location: Italy
Contact:

Re: How to make math operations from 2 Gadgets??

Post by LESTROSO »

Dear netmaestro ,

I thank you a lot very much!!! I'll try as soon as possible your code...Best regards, Lestroso :D :D :D
User avatar
LESTROSO
Enthusiast
Enthusiast
Posts: 124
Joined: Thu Nov 03, 2005 12:30 pm
Location: Italy
Contact:

Re: How to make math operations from 2 Gadgets??

Post 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 :oops:
User avatar
HeX0R
Addict
Addict
Posts: 1189
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: How to make math operations from 2 Gadgets??

Post by HeX0R »

There is a manual included in PB...
ValF(), StrF(), ValD(), StrD(), Int(), Round()
User avatar
Lord
Addict
Addict
Posts: 900
Joined: Tue May 26, 2009 2:11 pm

Re: How to make math operations from 2 Gadgets??

Post 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.
Image
Little John
Addict
Addict
Posts: 4777
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: How to make math operations from 2 Gadgets??

Post by Little John »

HeX0R wrote:There is a manual included in PB...
ValF(), StrF(), ValD(), StrD(), Int(), Round()
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))
User avatar
LESTROSO
Enthusiast
Enthusiast
Posts: 124
Joined: Thu Nov 03, 2005 12:30 pm
Location: Italy
Contact:

Re: How to make math operations from 2 Gadgets??

Post by LESTROSO »

Hi....thank you to everybody!!!
I have appriciated so much your ideas....
i'll try...
thanks again for the help...Lestroso :D
User avatar
LESTROSO
Enthusiast
Enthusiast
Posts: 124
Joined: Thu Nov 03, 2005 12:30 pm
Location: Italy
Contact:

Re: How to make math operations from 2 Gadgets??

Post 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 :D
infratec
Always Here
Always Here
Posts: 7582
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: How to make math operations from 2 Gadgets??

Post 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.
User avatar
LESTROSO
Enthusiast
Enthusiast
Posts: 124
Joined: Thu Nov 03, 2005 12:30 pm
Location: Italy
Contact:

Re: How to make math operations from 2 Gadgets??

Post by LESTROSO »

Dear Infratec,

you helped me so much!!! Thanks a lot ...I have succeded to build my app...thanks again..Lestroso :D
Post Reply