I am new to Ruby and Shoes, I think I have everything. the program appears to work correctly except when I get to the last step. I, enter the loan amount, interest rate, in to edit_lines, when I press the calculate button, it performs the calculations, stores the calculated numbers to a variable. The last step is dividing the total loan (loan and interest) by the length of the loan in months to ge the monthly payment, so I can make a payment table for the entire loan, but I either get in-corredt results or I get no reeults. I think I converted the integers to floats, etc. , but... not sure. It appears to add, multiply, subtrct, except it will not divide 2 qbjects. If I enter numbers it works ok. What am I doing wrong. It does seem like it is that difficult. Example code of dividng the values in a varible by the value of another varible?
Asked
Active
Viewed 405 times
1
-
Could you please provide the related code? – polarblau Jan 22 '11 at 22:56
-
Here's the code I used. Seeing how, I am a beginner, I started with the shoes calculator sample. – Wayne Jan 23 '11 at 22:01
-
The text will not alow me to paste the code. Can I email it to you? – Wayne Jan 23 '11 at 22:09
-
Here is the ppart that does not work – Wayne Jan 23 '11 at 22:27
-
part that does not work. @totalloan = @totalinterest @totalloan << "+" @totalloan << @loanamount #Total Loan amount @totalloan << "*" @totalloan << "1.0000000" @numberbox3.text = eval(@totalloan.to_s) @monthlypayment = @totalloan / @lengthyears @numberbox5.text = eval(@monthlypayment.to_s) – Wayne Jan 23 '11 at 22:32
-
Can you please paste the entire code on a pastebin site like http://gist.github.com ? – sarahhodne Jan 26 '11 at 05:36
1 Answers
1
It looks like you're using eval(), which you almost never, ever want to use. You can do the exact same thing in normal ruby. I'm just guessing right now since the code I can see in your comment is lacking newlines, but I think this code would work:
@numberbox3.text = @totalinterest + @loadamount
@numberbox5.text = @totalloan / @lengthyears
Hope this helps!

sarahhodne
- 9,796
- 3
- 39
- 44
-
Thank you so much. I am using more evals, so will replace those also. So why is not a good idea to use eval? Does it cause errors? – Wayne Jan 26 '11 at 16:51
-
Mostly because it can be a security issue, creates ugly code and is hard to read. See http://stackoverflow.com/questions/637421/is-eval-supposed-to-be-nasty for more info. Also, if you like my answer please upvote it (or set it as your "accepted answer" if you think it's the best answer). The little box in the lower right on the corner says how many times you set an accepted answer, and the more times you do it the more people want to answer your questions. – sarahhodne Feb 08 '11 at 16:41