473,657 Members | 2,932 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Having some troubles with this script.

5 New Member
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 1401
anonymous
98 New Member
This is C# which should go to the .NET forum.
Sep 29 '07 #2
JosAH
11,448 Recognized Expert MVP
This is C# which should go to the .NET forum.
Consider it done.

kind regards,

Jos
Sep 29 '07 #3
kenobewan
4,871 Recognized Expert Specialist
Errors and line numbers please.
Sep 30 '07 #4
Jeffro
5 New Member
Error 1 A field initializer cannot reference the nonstatic field, method, or property 'Opdracht5.Form 1.stort' C:\Documents and Settings\Jeffro \Mijn documenten\Visu al Studio 2005\Projects\O pdracht5\Opdrac ht5\Form1.cs 16 42 Opdracht5
Error 2 A field initializer cannot reference the nonstatic field, method, or property 'Opdracht5.Form 1.rente' C:\Documents and Settings\Jeffro \Mijn documenten\Visu al Studio 2005\Projects\O pdracht5\Opdrac ht5\Form1.cs 17 42 Opdracht5
Error 3 A field initializer cannot reference the nonstatic field, method, or property 'Opdracht5.Form 1.jaren' C:\Documents and Settings\Jeffro \Mijn documenten\Visu al Studio 2005\Projects\O pdracht5\Opdrac ht5\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\Visu al Studio 2005\Projects\O pdracht5\Opdrac ht5\Form1.cs 28 20 Opdracht5



And also, not only errors but i want to know if the formula would work!
Sep 30 '07 #5
MasterOfTheDark
2 New Member
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 InitializeCompo nent 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 New Member
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 New Member
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 Recognized Expert Specialist
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 New Member
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
1963
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
2384
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, and the other user will append nothing. Is there a way to avoid this from happening? For example. Lets say the user opens up a cached version of the page then append to the actual file. For some reason I remember reading about something like...
5
4825
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 unavailable'). My code's fairly straight-forward, with much of it right out of the Python docs, so I'm not sure what I'm doing wrong. You can see it all at http://deadbeefbabe.org/paste/1525/0 Any help is immensely appreciated.
2
1248
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 an intermediate skill level in certain facets of the language. $thisFileName = 'test.txt'; $fp = fopen($thisFileName, "w"); $write = fputs($fp, "test"); fclose($fp); if (!file_exists($thisFileName))
2
2070
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 Situation: client side scripts make an ajax request for some data aspx page processes request and writes back an XML (not perfectly formed) file client side script receives data and attempts to parse the XML (this is where I'm having a hard...
2
3635
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 search I came up with this keyword: _configthreadlocale Read more at http://msdn2.microsoft.com/en-us/library//26c0tb7x(VS.80).aspx (beware, this page is very slow or their servers are anyway). Looks like this function exists since Windows 95 and...
0
949
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 cancel, it logs him out... i´m using java script to set the timeout alert, but when the user click ok, it dont work, it do nothing. <script language="JavaScript"> <!-- function getgoing() {
1
1692
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 is one solid color; a brownish red block. Why isn't this script only slightly increasing the values?? ??? ??? <?php $img = imagecreatefromgif('logo.gif');
4
1981
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.*; import java.io.*; public class Aster { private static String host = "172.20.20.247"; private static int port = 5038;
0
8384
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8302
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8718
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8499
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8601
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5630
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1601
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.