Having some troubles with this script.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jeffro
    New Member
    • Sep 2007
    • 5

    Having some troubles with this script.

    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:

    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    
    namespace Opdracht5
    {
        public partial class Form1 : Form
        {
            double geld;
            double geldtemp;
            int teller;
            double stort2 = Convert.ToDouble(stort.Text);
            double rente2 = Convert.ToDouble(rente.Text);
            int jaren2 = int.Parse(jaren.Text);
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                geldtemp = rente2 + 100;
                geldtemp = geldtemp / 100;
                while (teller < jaren)
                {
                    geld = stort2 + geld;
                    geld = geld * geldtemp;
                    teller++;
                }
                output.Text = "" + geld;
            }
        }
    }
  • anonymous
    Banned
    New Member
    • Sep 2005
    • 99

    #2
    This is C# which should go to the .NET forum.

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Originally posted by anonymous
      This is C# which should go to the .NET forum.
      Consider it done.

      kind regards,

      Jos

      Comment

      • kenobewan
        Recognized Expert Specialist
        • Dec 2006
        • 4871

        #4
        Errors and line numbers please.

        Comment

        • Jeffro
          New Member
          • Sep 2007
          • 5

          #5
          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!

          Comment

          • MasterOfTheDark
            New Member
            • Sep 2007
            • 2

            #6
            Jeffro -

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

            Originally posted by Jeffro
            Code:
                    double stort2 = Convert.ToDouble(stort.Text);
                    double rente2 = Convert.ToDouble(rente.Text);
                    int jaren2 = int.Parse(jaren.Text);
            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:
            Originally posted by Jeffro
            Code:
                        while (teller < jaren)
            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.

            Comment

            • Jeffro
              New Member
              • Sep 2007
              • 5

              #7
              but using double is initializing them right?

              or do i have to make a int first and then convert them to double ?

              Comment

              • Jeffro
                New Member
                • Sep 2007
                • 5

                #8
                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 ;)

                Comment

                • kenobewan
                  Recognized Expert Specialist
                  • Dec 2006
                  • 4871

                  #9
                  Originally posted by Jeffro
                  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 ;)
                  Originally posted by Jeffro
                  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.

                  Comment

                  • Jeffro
                    New Member
                    • Sep 2007
                    • 5

                    #10
                    You guys can close this as my problems are fixed and my application works now!

                    Thank you for your support!

                    Comment

                    Working...