librelist archives

« back to archive

How to calculate two values from input fields

How to calculate two values from input fields

From:
Fily
Date:
2012-01-06 @ 02:33
> Hi,
> 
> I have been trying to calculate two values enter in two textfields 
(edit_line) and I cannot figure this out. 
> 
> I have tried....
> 
>   Shoes.app do
>       @num1 = edit_line
>       @num1 = edit_line     
> 
>       button "Calculate" do      
>        total = @num1 * @num2
>            para total
>       end      
>     end
> 
> also...
> 
>       button "Calculate" do      
>        total = @num1.text * @num2.text
>            para total
>       end      
>     end
> 
> but nothing.
> 
> Can someone be so kind and help me understand this?
> 
> Thanks a lot

Re: [shoes] How to calculate two values from input fields

From:
Cecil Coupe
Date:
2012-01-06 @ 02:52
On Thu, 2012-01-05 at 20:33 -0600, Fily wrote:
>   Shoes.app do
> >       @num1 = edit_line
> >       @num1 = edit_line     
> > 

The second one should be @num2 

Re: [shoes] How to calculate two values from input fields

From:
Fily
Date:
2012-01-06 @ 04:11
Sorry it was a typo, but it doesnt work either way.

Thanks

On Jan 5, 2012, at 8:52 PM, Cecil Coupe <ccoupe@cableone.net> wrote:

> On Thu, 2012-01-05 at 20:33 -0600, Fily wrote:
>>  Shoes.app do
>>>      @num1 = edit_line
>>>      @num1 = edit_line     
>>> 
> 
> The second one should be @num2 
> 
> 

Re: [shoes] How to calculate two values from input fields

From:
J. Kaiden
Date:
2012-01-06 @ 04:50
hi Fily,

  try this:

Shoes.app do
num1 = edit_line
num2 = edit_line

button "Calculate" do
total = num1.text.to_f * num2.text.to_f
para total.to_s, stroke: white
end
end

  num1 and 2 don't have to be instance variables, unless you're going to
pass them to another method at some point...

  what you're after is not num1 and 2, which are the edit_lines, but the
text that has been entered in them - found with edit_line#text.  once
you've got that text, you've got to convert it into a number, with either
String#to_i, or #to_f (i used #to_f...)  once you've multiplied the numbers
together, you've got to convert the result back to a string with #to_s
before you can stick it in a `para`.

  pressing <alt /> will bring up the Shoes console, which often has useful
information when errors are thrown.  also, aside from the manual, you can
always check out the methods available to any given widget like this:

  el = edit_line
  el.methods.sort.each{|method| p method}

  ... the `method` method has been _extremely_ helpful to me ;)

  hth -

  Shoes On!

  - j

Re: [shoes] How to calculate two values from input fields

From:
Filemon Salas
Date:
2012-01-06 @ 11:01
It worked, Thanks a lot for the good information, it makes sense now.
Excuse my ingnorance but where can I find the list of methods available in
Shoes (not for Ruby)?  I know to_s, to_i and to_f are Ruby methods but I
would like t o know what methods are available in Shoes.

Thanks a lot for your help

On Thu, Jan 5, 2012 at 10:50 PM, J. Kaiden <jakekaiden@gmail.com> wrote:

> hi Fily,
>
>   try this:
>
> Shoes.app do
> num1 = edit_line
> num2 = edit_line
>
> button "Calculate" do
> total = num1.text.to_f * num2.text.to_f
>  para total.to_s, stroke: white
> end
> end
>
>   num1 and 2 don't have to be instance variables, unless you're going to
> pass them to another method at some point...
>
>   what you're after is not num1 and 2, which are the edit_lines, but the
> text that has been entered in them - found with edit_line#text.  once
> you've got that text, you've got to convert it into a number, with either
> String#to_i, or #to_f (i used #to_f...)  once you've multiplied the numbers
> together, you've got to convert the result back to a string with #to_s
> before you can stick it in a `para`.
>
>   pressing <alt /> will bring up the Shoes console, which often has useful
> information when errors are thrown.  also, aside from the manual, you can
> always check out the methods available to any given widget like this:
>
>   el = edit_line
>   el.methods.sort.each{|method| p method}
>
>   ... the `method` method has been _extremely_ helpful to me ;)
>
>   hth -
>
>   Shoes On!
>
>   - j
>
>

Re: [shoes] How to calculate two values from input fields

From:
J. Kaiden
Date:
2012-01-06 @ 13:18
hey there -

  well, you can use the `method` method as described above to see the
methods available to any widget.  this won't explain them or their
parameters however...

  there's also the manual, which you can view online -
http://shoesrb.com/manual/Hello.html - or by running ~/shoes/dist/shoes and
opening the manual.  the nice thing about the offline version is that
 there is a search box to the left that can be very useful indeed.

  either way, check out in particular Elements/Common Methods -
http://shoesrb.com/manual/Common.html - which gives you a list of methods
that can be called on anything in Shoes.  also look at the Built-In Methods
- http://shoesrb.com/manual/Built-in.html -, and the Styles Master List -
http://shoesrb.com/manual/Styles.html -, which shows the style parameters
that can be set with the #style method.

  it can be a little confusing at first - but you'll quickly get the hang
of it, and i think/hope that you'll like it!  i was used to gtk2 when i
started using Shoes, and i remember being amazed that things that took
dozens of lines of code to do in gtk2 could be done in just a few lines in
Shoes...

  good luck -

  Shoes On!

  - j


On Fri, Jan 6, 2012 at 12:01 PM, Filemon Salas <fs.dolphin@gmail.com> wrote:

> It worked, Thanks a lot for the good information, it makes sense now.
> Excuse my ingnorance but where can I find the list of methods available in
> Shoes (not for Ruby)?  I know to_s, to_i and to_f are Ruby methods but I
> would like t o know what methods are available in Shoes.
>
> Thanks a lot for your help
>
>
> On Thu, Jan 5, 2012 at 10:50 PM, J. Kaiden <jakekaiden@gmail.com> wrote:
>
>> hi Fily,
>>
>>   try this:
>>
>> Shoes.app do
>> num1 = edit_line
>>  num2 = edit_line
>>
>> button "Calculate" do
>> total = num1.text.to_f * num2.text.to_f
>>  para total.to_s, stroke: white
>> end
>> end
>>
>>   num1 and 2 don't have to be instance variables, unless you're going to
>> pass them to another method at some point...
>>
>>   what you're after is not num1 and 2, which are the edit_lines, but the
>> text that has been entered in them - found with edit_line#text.  once
>> you've got that text, you've got to convert it into a number, with either
>> String#to_i, or #to_f (i used #to_f...)  once you've multiplied the numbers
>> together, you've got to convert the result back to a string with #to_s
>> before you can stick it in a `para`.
>>
>>   pressing <alt /> will bring up the Shoes console, which often has
>> useful information when errors are thrown.  also, aside from the manual,
>> you can always check out the methods available to any given widget like
>> this:
>>
>>   el = edit_line
>>   el.methods.sort.each{|method| p method}
>>
>>   ... the `method` method has been _extremely_ helpful to me ;)
>>
>>   hth -
>>
>>   Shoes On!
>>
>>   - j
>>
>>
>

Re: [shoes] How to calculate two values from input fields

From:
Filemon Salas
Date:
2012-01-06 @ 13:58
Oh, sorry I didn't get it the first time, urrrr.

el = edit_line
el.methods.sort.each{|method| p method}

This will help, thanks a LOT



On Fri, Jan 6, 2012 at 7:18 AM, J. Kaiden <jakekaiden@gmail.com> wrote:
>
> hey there -
>
>   well, you can use the `method` method as described above to see the 
methods available to any widget.  this won't explain them or their 
parameters however...
>
>   there's also the manual, which you can view online 
- http://shoesrb.com/manual/Hello.html - or by running ~/shoes/dist/shoes 
and opening the manual.  the nice thing about the offline version is that 
 there is a search box to the left that can be very useful indeed.
>
>   either way, check out in particular Elements/Common Methods 
- http://shoesrb.com/manual/Common.html - which gives you a list of 
methods that can be called on anything in Shoes.  also look at the 
Built-In Methods - http://shoesrb.com/manual/Built-in.html -, and the 
Styles Master List - http://shoesrb.com/manual/Styles.html -, which shows 
the style parameters that can be set with the #style method.
>
>   it can be a little confusing at first - but you'll quickly get the 
hang of it, and i think/hope that you'll like it!  i was used to gtk2 when
i started using Shoes, and i remember being amazed that things that took 
dozens of lines of code to do in gtk2 could be done in just a few lines in
Shoes...
>
>   good luck -
>
>   Shoes On!
>
>   - j
>
>
> On Fri, Jan 6, 2012 at 12:01 PM, Filemon Salas <fs.dolphin@gmail.com> wrote:
>>
>> It worked, Thanks a lot for the good information, it makes sense now.  
Excuse my ingnorance but where can I find the list of methods available in
Shoes (not for Ruby)?  I know to_s, to_i and to_f are Ruby methods but I 
would like t o know what methods are available in Shoes.
>>
>> Thanks a lot for your help
>>
>>
>> On Thu, Jan 5, 2012 at 10:50 PM, J. Kaiden <jakekaiden@gmail.com> wrote:
>>>
>>> hi Fily,
>>>
>>>   try this:
>>>
>>> Shoes.app do
>>> num1 = edit_line
>>> num2 = edit_line
>>>
>>> button "Calculate" do
>>> total = num1.text.to_f * num2.text.to_f
>>> para total.to_s, stroke: white
>>> end
>>> end
>>>
>>>   num1 and 2 don't have to be instance variables, unless you're going 
to pass them to another method at some point...
>>>
>>>   what you're after is not num1 and 2, which are the edit_lines, but 
the text that has been entered in them - found with edit_line#text.  once 
you've got that text, you've got to convert it into a number, with either 
String#to_i, or #to_f (i used #to_f...)  once you've multiplied the 
numbers together, you've got to convert the result back to a string with 
#to_s before you can stick it in a `para`.
>>>
>>>   pressing <alt /> will bring up the Shoes console, which often has 
useful information when errors are thrown.  also, aside from the manual, 
you can always check out the methods available to any given widget like 
this:
>>>
>>>   el = edit_line
>>>   el.methods.sort.each{|method| p method}
>>>
>>>   ... the `method` method has been _extremely_ helpful to me ;)
>>>
>>>   hth -
>>>
>>>   Shoes On!
>>>
>>>   - j
>>>
>>
>