473,387 Members | 1,590 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Having some troubles with this script.

5
Ok I have some troubles with my code. I don't need a full solution. I just want to know what i should do best for this situation.

The idea is to calculate the amount of money that will be on the bank. I think my formula is right but there are errors i just cant fix. Mostly concerning doubles. Please look at my code and tell me what i did wrong:

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8.  
  9. namespace Opdracht5
  10. {
  11.     public partial class Form1 : Form
  12.     {
  13.         double geld;
  14.         double geldtemp;
  15.         int teller;
  16.         double stort2 = Convert.ToDouble(stort.Text);
  17.         double rente2 = Convert.ToDouble(rente.Text);
  18.         int jaren2 = int.Parse(jaren.Text);
  19.         public Form1()
  20.         {
  21.             InitializeComponent();
  22.         }
  23.  
  24.         private void button1_Click(object sender, EventArgs e)
  25.         {
  26.             geldtemp = rente2 + 100;
  27.             geldtemp = geldtemp / 100;
  28.             while (teller < jaren)
  29.             {
  30.                 geld = stort2 + geld;
  31.                 geld = geld * geldtemp;
  32.                 teller++;
  33.             }
  34.             output.Text = "" + geld;
  35.         }
  36.     }
  37. }
  38.  
Sep 29 '07 #1
9 1385
This is C# which should go to the .NET forum.
Sep 29 '07 #2
JosAH
11,448 Expert 8TB
This is C# which should go to the .NET forum.
Consider it done.

kind regards,

Jos
Sep 29 '07 #3
kenobewan
4,871 Expert 4TB
Errors and line numbers please.
Sep 30 '07 #4
Jeffro
5
Error 1 A field initializer cannot reference the nonstatic field, method, or property 'Opdracht5.Form1.stort' C:\Documents and Settings\Jeffro\Mijn documenten\Visual Studio 2005\Projects\Opdracht5\Opdracht5\Form1.cs 16 42 Opdracht5
Error 2 A field initializer cannot reference the nonstatic field, method, or property 'Opdracht5.Form1.rente' C:\Documents and Settings\Jeffro\Mijn documenten\Visual Studio 2005\Projects\Opdracht5\Opdracht5\Form1.cs 17 42 Opdracht5
Error 3 A field initializer cannot reference the nonstatic field, method, or property 'Opdracht5.Form1.jaren' C:\Documents and Settings\Jeffro\Mijn documenten\Visual Studio 2005\Projects\Opdracht5\Opdracht5\Form1.cs 18 32 Opdracht5
Error 4 Operator '<' cannot be applied to operands of type 'int' and 'System.Windows.Forms.TextBox' C:\Documents and Settings\Jeffro\Mijn documenten\Visual Studio 2005\Projects\Opdracht5\Opdracht5\Form1.cs 28 20 Opdracht5



And also, not only errors but i want to know if the formula would work!
Sep 30 '07 #5
Jeffro -

Looks like your first errors come from these lines of code:

Expand|Select|Wrap|Line Numbers
  1.         double stort2 = Convert.ToDouble(stort.Text);
  2.         double rente2 = Convert.ToDouble(rente.Text);
  3.         int jaren2 = int.Parse(jaren.Text);
  4.  
This is because these are initialized in the first line of the constructor (effectively, before the brackets are even entered) - stort, rente, and jaren aren't even initialized until your InitializeComponent method.

I recommend moving your variable declarations to inside your button click event handler rather than as class-level variables; you probably want to re-load them after each click anyway.

As for this line of code:
Expand|Select|Wrap|Line Numbers
  1.             while (teller < jaren)
  2.  
I think you want jaren2.

I'm not sure if the algorithm works -- I can't see your form so I don't know what all the text-boxes are labeled, so I'm not exactly sure what it is you're trying to do.

Hope it helps you get rid of the errors at least.
Sep 30 '07 #6
Jeffro
5
but using double is initializing them right?

or do i have to make a int first and then convert them to double ?
Sep 30 '07 #7
Jeffro
5
Ok i got rid of the errors.

Here is the project: http://jeffro.no-ip.info/Opdracht5.rar

stort = the amount of money I put on my bank each year.
Rente = the rent that your banks gives you each year.
Jaren = the amount of years that i'm going to put money on it.

I dont know if the formula is good so can someone please check it for me. I really want to learn if its right ;)
Sep 30 '07 #8
kenobewan
4,871 Expert 4TB
Ok i got rid of the errors.

Here is the project: http://jeffro.no-ip.info/Opdracht5.rar

stort = the amount of money I put on my bank each year.
Rente = the rent that your banks gives you each year.
Jaren = the amount of years that i'm going to put money on it.

I dont know if the formula is good so can someone please check it for me. I really want to learn if its right ;)
Ok I have some troubles with my code. I don't need a full solution. I just want to know what i should do best for this situation.
I dont know about anyone else, but I refuse to test applications - that's what testing servers are for. Suggest the OP learn something about application and project management.

Congratulations MasterOfTheDark for a job well done.
Oct 3 '07 #9
Jeffro
5
You guys can close this as my problems are fixed and my application works now!

Thank you for your support!
Oct 4 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: lmckaha | last post by:
Hi, Mysql version: 3.23.49 Solaris version: 2.7 gcc compiler version: 2.95.2 Python : 2.2.2 I'm evaluating the C and C++ API to decide which one to bye but I have many troubles.
9
by: Kelly Vernon | last post by:
I have a standard ASP page that appends to an xml page. Currently if there is more than one person attempting to append to the same XML file at a time. One user will have the ability to append,...
5
by: Chris Spencer | last post by:
I've written a simple class to manage P2P socket connections. However, whenever I try to receive data, the socket raises an exception with the error message (11, 'Resource temporarily...
2
by: Jolly Green Giant | last post by:
I'm trying to use PHP to create a text file. Simple right? I've done it before. I don't know why it's not working now. It's not rocket science. In general, I'd say I'm a PHP beginner, but with...
2
by: sklett | last post by:
** I tried to find a more suitable NG for this issue but didn't find much (on the MS server) the ones I did find haven't had posts in a loooong time. Sorry for the somewhat off topic post ** My...
2
by: Daniele C. | last post by:
I will report a snippet from http://php.net/setlocale I spent about 2 seconds before thinking: can it really be? I mean, is there no way to set locale info per thread? And after a brief web...
0
by: Fernandopoiato | last post by:
Hi everybody, i have a trouble with the timeout, i want my page expires in 20 minutes, but before it log out, i want ask the user if he wants to save the form, if he click ok, it saves, if click...
1
by: Taorluath | last post by:
I'm trying to make a PHP script that increases the blue value of each pixel in an image by 1. It's important that the script goes pixel by pixel. For some reason, however, it outputs an image that...
4
by: XiNoID | last post by:
Hello, thanks for reading my topic...I'm just pre-beginner in java, i have been studying it for 3 weeks...So..Thats enough for prologue ;) I have troubles with this script: import java.net.*;...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.