# Begginer needs help

**URL:** <https://www.ruby-forum.com/t/begginer-needs-help/195590>\
**Category:** Ruby\
**Created:** [September 26, 2010, 2:36am UTC](https://www.ruby-forum.com/t/begginer-needs-help/195590 "2010-09-26T02:36:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jake\_1637](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a88e4f/32.png) [@jake\_1637](https://www.ruby-forum.com/u/jake_1637)\
**Post date:** [September 26, 2010, 2:36am UTC](https://www.ruby-forum.com/t/begginer-needs-help/195590/1 "2010-09-26T02:36:51Z")

</div>

Hi i’m in a programming a class and i’m doing an assignment i’ve gotten  
it to work but one of the entries is messed up it takes the place of a  
diffrent one

Here’s the code

require ‘gtk2’

window = Gtk::Window.new  
window.border\_width = 10  
window.title = “Future Value Investment Calculator”  
window.resize(450,200)

convertButton = Gtk::Button.new(“Convert”)  
closeButton = Gtk::Button.new(“Close”)  
oink = Gtk::Image.new(Gdk::Pixbuf.new(“piggybank.gif”, 150, 200))  
promptLabel = Gtk::Label.new(“Enter amount invested in U.S Dollars:”)  
tempEntry = Gtk::Entry.new  
promptLabel2 = Gtk::Label.new(“Enter Rate of return as a decimal(e.g.  
enter 8% as .08):”)  
tempEntry2 = Gtk::Entry.new  
promptLabel3 = Gtk::Label.new(“Enter number of years the money will be  
invested:”)  
tempEntry3 = Gtk::Entry.new  
resultLabel = Gtk::Label.new("")

vbox1 = Gtk::VBox.new(false, 0)  
hbox1 = Gtk::HBox.new(false, 0)  
hbox2 = Gtk::HBox.new(false, 0)

hbox1.pack\_start(convertButton, true, false)  
hbox1.pack\_start(closeButton, true, false)

vbox1.pack\_start(promptLabel, true, true)  
vbox1.pack\_start(tempEntry, true, true)  
vbox1.pack\_start(promptLabel2, true, true)  
vbox1.pack\_start(tempEntry2, true, true)  
vbox1.pack\_start(promptLabel3, true, true)  
vbox1.pack\_start(tempEntry3, true, true)  
vbox1.pack\_start(resultLabel, true, true)  
vbox1.pack\_start(hbox1, true, true)

hbox2.pack\_start(vbox1, true, true)  
hbox2.pack\_start(oink, true, true)

window.add(hbox2)  
window.show\_all

convertButton.signal\_connect(“clicked”) {

dollars = tempEntry.text.to\_f

rate = tempEntry.text.to\_f

time = tempEntry.text.to\_i

fv = dollars\*(1+rate)\*\*time

output= " In " + time.to\_s + " years your investment will be worth " +  
fv.to\_s

resultLabel.set\_label( output )  
}

closeButton.signal\_connect(“clicked”) {  
Gtk.main\_quit  
}

window.signal\_connect(“destroy”) {  
Gtk.main\_quit  
}

Gtk.main

if u could help i would really appreciate it

---

<div class="post-metadata">

**Author:** ![jake\_1637](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a88e4f/32.png) [@jake\_1637](https://www.ruby-forum.com/u/jake_1637)\
**Post date:** [September 26, 2010, 2:51am UTC](https://www.ruby-forum.com/t/begginer-needs-help/195590/2 "2010-09-26T02:51:10Z")

</div>

Hi,

On 26.09.2010 02:36, Jake Alucard wrote:

> convertButton.signal\_connect(“clicked”) {
> 
> dollars = tempEntry.text.to\_f
> 
> rate = tempEntry.text.to\_f
> 
> time = tempEntry.text.to\_i

Look carefully which gtk widgets you access. You always access  
“tempEntry” but you named the others “tempEntry2” and “tempEntry3”.

Lesson you should learn here: use distinctive naming 😉

- Markus

---

<div class="post-metadata">

**Author:** ![jake\_1637](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a88e4f/32.png) [@jake\_1637](https://www.ruby-forum.com/u/jake_1637)\
**Post date:** [September 26, 2010, 2:56am UTC](https://www.ruby-forum.com/t/begginer-needs-help/195590/3 "2010-09-26T02:56:27Z")

</div>

thank you so much 😃
