code errors

keep getting errors

Page 1 of 1

5 Replies - 8864 Views - Last Post: 16 May 2010 - 08:52 AM Rate Topic: -----

#1 shaira.adam  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 14-May 10

code errors

Posted 16 May 2010 - 05:55 AM

Hi
I was thinking anyone could help me in explaining the reason for the error in my codes that I wrote for the future value calculator and annuity schedule

The following is the code
using System;
using System.Windows.Forms;

public class frmMain : Form
{
    private Label label1;
    private RadioButton Fortnightly;
    private RadioButton Monthly;
    private TextBox PaymentAmount;
    private Label label2;
    private Label label3;
    private Label label4;
    private TextBox InterestRate;
    private TextBox PaymentPeriod;
    private TextBox FutureValue;
    private Button ShowAnnuitySchedule;
    private Button CalculateFutureValue;
    private Button Clear;
    private ListBox Schedule;
    private Button Close;
    private RadioButton Weekly;
    #region Windows Form Designer generated code

    private void InitializeComponent()
    {
        this.label1 = new System.Windows.Forms.Label();
        this.Weekly = new System.Windows.Forms.RadioButton();
        this.Fortnightly = new System.Windows.Forms.RadioButton();
        this.Monthly = new System.Windows.Forms.RadioButton();
        this.PaymentAmount = new System.Windows.Forms.TextBox();
        this.label2 = new System.Windows.Forms.Label();
        this.label3 = new System.Windows.Forms.Label();
        this.label4 = new System.Windows.Forms.Label();
        this.InterestRate = new System.Windows.Forms.TextBox();
        this.PaymentPeriod = new System.Windows.Forms.TextBox();
        this.FutureValue = new System.Windows.Forms.TextBox();
        this.ShowAnnuitySchedule = new System.Windows.Forms.Button();
        this.CalculateFutureValue = new System.Windows.Forms.Button();
        this.Clear = new System.Windows.Forms.Button();
        this.Schedule = new System.Windows.Forms.ListBox();
        this.Close = new System.Windows.Forms.Button();
        this.SuspendLayout();
        // 
        // label1
        // 
        this.label1.AutoSize = true;
        this.label1.Location = new System.Drawing.Point(36, 27);
        this.label1.Name = "label1";
        this.label1.Size = new System.Drawing.Size(86, 13);
        this.label1.TabIndex = 0;
        this.label1.Text = "Payment amount";
        // 
        // Weekly
        // 
        this.Weekly.AutoSize = true;
        this.Weekly.Location = new System.Drawing.Point(87, 64);
        this.Weekly.Name = "Weekly";
        this.Weekly.Size = new System.Drawing.Size(61, 17);
        this.Weekly.TabIndex = 1;
        this.Weekly.TabStop = true;
        this.Weekly.Text = "Weekly";
        this.Weekly.UseVisualStyleBackColor = true;
        // 
        // Fortnightly
        // 
        this.Fortnightly.AutoSize = true;
        this.Fortnightly.Location = new System.Drawing.Point(87, 104);
        this.Fortnightly.Name = "Fortnightly";
        this.Fortnightly.Size = new System.Drawing.Size(73, 17);
        this.Fortnightly.TabIndex = 2;
        this.Fortnightly.TabStop = true;
        this.Fortnightly.Text = "Fortnightly";
        this.Fortnightly.UseVisualStyleBackColor = true;
        // 
        // Monthly
        // 
        this.Monthly.AutoSize = true;
        this.Monthly.Location = new System.Drawing.Point(86, 146);
        this.Monthly.Name = "Monthly";
        this.Monthly.Size = new System.Drawing.Size(62, 17);
        this.Monthly.TabIndex = 3;
        this.Monthly.TabStop = true;
        this.Monthly.Text = "Monthly";
        this.Monthly.UseVisualStyleBackColor = true;
        // 
        // PaymentAmount
        // 
        this.PaymentAmount.Location = new System.Drawing.Point(128, 24);
        this.PaymentAmount.Name = "PaymentAmount";
        this.PaymentAmount.Size = new System.Drawing.Size(100, 20);
        this.PaymentAmount.TabIndex = 4;
        // 
        // label2
        // 
        this.label2.AutoSize = true;
        this.label2.Location = new System.Drawing.Point(39, 201);
        this.label2.Name = "label2";
        this.label2.Size = new System.Drawing.Size(63, 13);
        this.label2.TabIndex = 5;
        this.label2.Text = "Interest rate";
        // 
        // label3
        // 
        this.label3.AutoSize = true;
        this.label3.Location = new System.Drawing.Point(36, 237);
        this.label3.Name = "label3";
        this.label3.Size = new System.Drawing.Size(80, 13);
        this.label3.TabIndex = 6;
        this.label3.Text = "Payment period";
        // 
        // label4
        // 
        this.label4.AutoSize = true;
        this.label4.Location = new System.Drawing.Point(36, 282);
        this.label4.Name = "label4";
        this.label4.Size = new System.Drawing.Size(66, 13);
        this.label4.TabIndex = 7;
        this.label4.Text = "Future value";
        // 
        // InterestRate
        // 
        this.InterestRate.Location = new System.Drawing.Point(149, 201);
        this.InterestRate.Name = "InterestRate";
        this.InterestRate.Size = new System.Drawing.Size(100, 20);
        this.InterestRate.TabIndex = 8;
        // 
        // PaymentPeriod
        // 
        this.PaymentPeriod.Location = new System.Drawing.Point(149, 237);
        this.PaymentPeriod.Name = "PaymentPeriod";
        this.PaymentPeriod.Size = new System.Drawing.Size(100, 20);
        this.PaymentPeriod.TabIndex = 9;
        // 
        // FutureValue
        // 
        this.FutureValue.Location = new System.Drawing.Point(149, 282);
        this.FutureValue.Name = "FutureValue";
        this.FutureValue.Size = new System.Drawing.Size(100, 20);
        this.FutureValue.TabIndex = 10;
        // 
        // ShowAnnuitySchedule
        // 
        this.ShowAnnuitySchedule.Location = new System.Drawing.Point(329, 169);
        this.ShowAnnuitySchedule.Name = "ShowAnnuitySchedule";
        this.ShowAnnuitySchedule.Size = new System.Drawing.Size(149, 23);
        this.ShowAnnuitySchedule.TabIndex = 11;
        this.ShowAnnuitySchedule.Text = "Show annuity schedule";
        this.ShowAnnuitySchedule.UseVisualStyleBackColor = true;
        this.ShowAnnuitySchedule.Click += new System.EventHandler(this.listBox1_SelectedIndexChanged);
        // 
        // CalculateFutureValue
        // 
        this.CalculateFutureValue.Location = new System.Drawing.Point(329, 212);
        this.CalculateFutureValue.Name = "CalculateFutureValue";
        this.CalculateFutureValue.Size = new System.Drawing.Size(149, 23);
        this.CalculateFutureValue.TabIndex = 12;
        this.CalculateFutureValue.Text = "Calculate future value";
        this.CalculateFutureValue.UseVisualStyleBackColor = true;
        this.CalculateFutureValue.Click += new System.EventHandler(this.CalculateFuturevalue_Click);
        // 
        // Clear
        // 
        this.Clear.Location = new System.Drawing.Point(365, 253);
        this.Clear.Name = "Clear";
        this.Clear.Size = new System.Drawing.Size(75, 23);
        this.Clear.TabIndex = 13;
        this.Clear.Text = "Clear";
        this.Clear.UseVisualStyleBackColor = true;
        this.Clear.Click += new System.EventHandler(this.Clear_Click);
        // 
        // Schedule
        // 
        this.Schedule.FormattingEnabled = true;
        this.Schedule.Location = new System.Drawing.Point(42, 370);
        this.Schedule.Name = "Schedule";
        this.Schedule.Size = new System.Drawing.Size(436, 225);
        this.Schedule.TabIndex = 15;
        this.Schedule.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged);
        // 
        // Close
        // 
        this.Close.Location = new System.Drawing.Point(365, 299);
        this.Close.Name = "Close";
        this.Close.Size = new System.Drawing.Size(75, 23);
        this.Close.TabIndex = 16;
        this.Close.Text = "Close";
        this.Close.UseVisualStyleBackColor = true;
        this.Close.Click += new System.EventHandler(this.Close_Click);
        // 
        // frmMain
        // 
        this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(192)))));
        this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
        this.ClientSize = new System.Drawing.Size(516, 607);
        this.Controls.Add(this.Close);
        this.Controls.Add(this.Schedule);
        this.Controls.Add(this.Clear);
        this.Controls.Add(this.CalculateFutureValue);
        this.Controls.Add(this.ShowAnnuitySchedule);
        this.Controls.Add(this.FutureValue);
        this.Controls.Add(this.PaymentPeriod);
        this.Controls.Add(this.InterestRate);
        this.Controls.Add(this.label4);
        this.Controls.Add(this.label3);
        this.Controls.Add(this.label2);
        this.Controls.Add(this.PaymentAmount);
        this.Controls.Add(this.Monthly);
        this.Controls.Add(this.Fortnightly);
        this.Controls.Add(this.Weekly);
        this.Controls.Add(this.label1);
        this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
        this.Name = "frmMain";
        this.Text = "Annuity Calculator";
        this.ResumeLayout(false);
        this.PerformLayout();

    }
    #endregion

    public static void Main()
    {
        frmMain main = new frmMain();
        Application.Run(main);
    }

    public frmMain()
    {
        InitializeComponent();
    }


    private void CalculateFutureValue_Click(object sender, System.EventArgs e)
    {
        double paymentAmount;
        double interestRate;
        double paymentPeriod;
        int periodType;
        double futureValue;

        // Get the input value from the form and make sure each is the correct type

        try
        {
            paymentAmount = decimal.Parse(paymentAmount.Text);
        }
        catch
        {
            MessageBox.Show("Payment amount is required and must be numeric.", Text,
                MessageBoxButtons.OK, MessageBoxIcon.Information);
            paymentAmount.Focus();
            return;
        }


        try
        {
            paymentPeriod = decimal.Parse(PaymentPeriod.Text);
        }
        catch
        {
            MessageBox.Show("Payment period is required and must be numeric.", Text,
                MessageBoxButtons.OK, MessageBoxIcon.Information);
            paymentPeriod.Focus();
            return;
        }

        //Is radio button weekly selected?

        if (Weekly.Checked)
            periodType = 1;

        // is radio button fortnight selected?

        if (Fortnightly.Checked)
            periodType = 2;

        //Is radio button monthly selected?

        if (Monthly.Checked)
            periodType = 3;

        // Get the interest rate as decimal fraction

        interestRate = double.Parse(InterestRate.Text);

        switch (periodType)
        {
            case 1:
                {
                    return interestRate/5200;
                }
            case 2:
                {
                    return interestRate/2600;
                }

            case 3:
                {
                    return interestRate/1200;
                }
        }

        // Calculate the future value as per the financial calculator

        double Calc1 = Math.Pow ((1+interestRate), periodType);
        double Calc2 = Calc1 -1;
        double Calc3 = Calc2/interestRate;
        double Calc4 = Calc3 * paymentAmount;
        return Calc4;

    }
 
    private void Close_Click (object sender, System.EventArgs e)
    {
        Close();
    }

    private void Clear_Click(object sender, System.EventArgs e)
    {
        PaymentAmount.Text = "";
        InterestRate.Text = "";
        PaymentPeriod.Text = "";
        FutureValue.Text = "";
        Schedule.Items.Clear();
    }

    //private void showAnnuitySchedule_Click (object sender, System.EventArgs e)

    
     private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
    {
        ListBox.Items.Add("NumberOfPayments",     "PaymentAmount",      "Interest",     "Balance");
        int Count = 1;
        int numberOfPayments;
         int paymentAmount;
         int compInRate;
         double paymentPeriod;
         decimal interest;
         decimal balance;

         numberOfPayments = int.Parse(numberOfPayments.Text);

         numberOfPayments = 1;
         balance = 0;
         while (numberOfPayments <= PaymentPeriod)
         {
             interest = balance * compInRate;
             balance = balance + balance * compInRate + paymentAmount;
             numberOfPayments = numberOfPayments ++;
         }
     }
         
            
     
}

This post has been edited by JackOfAllTrades: 16 May 2010 - 06:09 AM
Reason for edit:: Fixed code tags.


Is This A Good Question/Topic? 0
  • +

Replies To: code errors

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6078
  • View blog
  • Posts: 23,548
  • Joined: 23-August 08

Re: code errors

Posted 16 May 2010 - 06:10 AM

Moved to C#. How about actually telling us what the errors are???
Was This Post Helpful? 0
  • +
  • -

#3 shaira.adam  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 14-May 10

Re: code errors

Posted 16 May 2010 - 06:29 AM

Hi there
I keep getting 12 error messages. I did not know how to fix it. it has been frustrating

the following are

Warning 1 'frmMain.Close' hides inherited member 'System.Windows.Forms.Form.Close()'. Use the new keyword if hiding was intended. E:\MUMs study\Intro Programing\Assignment\FV Calculator\FV Calculator\frmMain.cs 20 20 FV Calculator

Error 2 'frmMain' does not contain a definition for 'CalculateFuturevalue_Click' and no extension method 'CalculateFuturevalue_Click' accepting a first argument of type 'frmMain' could be found (are you missing a using directive or an assembly reference?) E:\MUMs study\Intro Programing\Assignment\FV Calculator\FV Calculator\frmMain.cs 159 73 FV Calculator

Error 3 'double' does not contain a definition for 'Text' and no extension method 'Text' accepting a first argument of type 'double' could be found (are you missing a using directive or an assembly reference?) E:\MUMs study\Intro Programing\Assignment\FV Calculator\FV Calculator\frmMain.cs 244 57 FV Calculator

Error 4 'double' does not contain a definition for 'Focus' and no extension method 'Focus' accepting a first argument of type 'double' could be found (are you missing a using directive or an assembly reference?) E:\MUMs study\Intro Programing\Assignment\FV Calculator\FV Calculator\frmMain.cs 250 27 FV Calculator

Error 5 Cannot implicitly convert type 'decimal' to 'double'. An explicit conversion exists (are you missing a cast?) E:\MUMs study\Intro Programing\Assignment\FV Calculator\FV Calculator\frmMain.cs 257 29 FV Calculator

Error 6 'double' does not contain a definition for 'Focus' and no extension method 'Focus' accepting a first argument of type 'double' could be found (are you missing a using directive or an assembly reference?) E:\MUMs study\Intro Programing\Assignment\FV Calculator\FV Calculator\frmMain.cs 263 27 FV Calculator

Error 7 Since 'frmMain.CalculateFutureValue_Click(object, System.EventArgs)' returns void, a return keyword must not be followed by an object expression E:\MUMs study\Intro Programing\Assignment\FV Calculator\FV Calculator\frmMain.cs 290 21 FV Calculator

Error 8 Since 'frmMain.CalculateFutureValue_Click(object, System.EventArgs)' returns void, a return keyword must not be followed by an object expression E:\MUMs study\Intro Programing\Assignment\FV Calculator\FV Calculator\frmMain.cs 294 21 FV Calculator

Error 9 Since 'frmMain.CalculateFutureValue_Click(object, System.EventArgs)' returns void, a return keyword must not be followed by an object expression E:\MUMs study\Intro Programing\Assignment\FV Calculator\FV Calculator\frmMain.cs 299 21 FV Calculator

Error 10 Since 'frmMain.CalculateFutureValue_Click(object, System.EventArgs)' returns void, a return keyword must not be followed by an object expression E:\MUMs study\Intro Programing\Assignment\FV Calculator\FV Calculator\frmMain.cs 309 9 FV Calculator

Error 11 An object reference is required for the non-static field, method, or property 'System.Windows.Forms.ListBox.Items.get' E:\MUMs study\Intro Programing\Assignment\FV Calculator\FV Calculator\frmMain.cs 332 9 FV Calculator

Error 12 'int' does not contain a definition for 'Text' and no extension method 'Text' accepting a first argument of type 'int' could be found (are you missing a using directive or an assembly reference?) E:\MUMs study\Intro Programing\Assignment\FV Calculator\FV Calculator\frmMain.cs 341 56 FV Calculator

Error 13 Operator '<=' cannot be applied to operands of type 'int' and 'System.Windows.Forms.TextBox' E:\MUMs study\Intro Programing\Assignment\FV Calculator\FV Calculator\frmMain.cs 345 17 FV Calculator
Was This Post Helpful? 0
  • +
  • -

#4 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 445
  • View blog
  • Posts: 1,501
  • Joined: 28-April 09

Re: code errors

Posted 16 May 2010 - 06:56 AM

Did you handwrite this code or make changes to it? You have capitalization errors in code that is generated for you if you're using visual studio or even sharpdevelop.
such as...

this.CalculateFutureValue.Click += new System.EventHandler(this.CalculateFuturevalue_Click);



that should be

this.CalculateFutureValue.Click += new System.EventHandler(this.CalculateFutureValue_Click);



Then you are making use of variables that are never assigned a value. You also are using a completely wrong name for one of your controls, specifically the listbox.

EDIT: Almost forgot, you're also trying to return a value from a button_click Event.
And then in a few places you're trying to parse a string into a decimal and store it in a double.
paymentPeriod = decimal.Parse(PaymentPeriod.Text);

This post has been edited by Nakor: 16 May 2010 - 07:04 AM

Was This Post Helpful? 0
  • +
  • -

#5 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 445
  • View blog
  • Posts: 1,501
  • Joined: 28-April 09

Re: code errors

Posted 16 May 2010 - 07:33 AM

Ok, I've made enough changes to it that it will at least load the form now, however you still have some work to do to get everything calculating and displaying correctly

using System;
using System.Windows.Forms;

public class frmMain : Form
{
    private Label label1;
    private RadioButton Fortnightly;
    private RadioButton Monthly;
    private TextBox PaymentAmount;
    private Label label2;
    private Label label3;
    private Label label4;
    private TextBox InterestRate;
    private TextBox PaymentPeriod;
    private TextBox FutureValue;
    private Button ShowAnnuitySchedule;
    private Button CalculateFutureValue;
    private Button Clear;
    private ListBox Schedule;
    private Button Close;
    private RadioButton Weekly;
    #region Windows Form Designer generated code

    private void InitializeComponent()
    {
        this.label1 = new System.Windows.Forms.Label();
        this.Weekly = new System.Windows.Forms.RadioButton();
        this.Fortnightly = new System.Windows.Forms.RadioButton();
        this.Monthly = new System.Windows.Forms.RadioButton();
        this.PaymentAmount = new System.Windows.Forms.TextBox();
        this.label2 = new System.Windows.Forms.Label();
        this.label3 = new System.Windows.Forms.Label();
        this.label4 = new System.Windows.Forms.Label();
        this.InterestRate = new System.Windows.Forms.TextBox();
        this.PaymentPeriod = new System.Windows.Forms.TextBox();
        this.FutureValue = new System.Windows.Forms.TextBox();
        this.ShowAnnuitySchedule = new System.Windows.Forms.Button();
        this.CalculateFutureValue = new System.Windows.Forms.Button();
        this.Clear = new System.Windows.Forms.Button();
        this.Schedule = new System.Windows.Forms.ListBox();
        this.Close = new System.Windows.Forms.Button();
        this.SuspendLayout();
        // 
        // label1
        // 
        this.label1.AutoSize = true;
        this.label1.Location = new System.Drawing.Point(36, 27);
        this.label1.Name = "label1";
        this.label1.Size = new System.Drawing.Size(86, 13);
        this.label1.TabIndex = 0;
        this.label1.Text = "Payment amount";
        // 
        // Weekly
        // 
        this.Weekly.AutoSize = true;
        this.Weekly.Location = new System.Drawing.Point(87, 64);
        this.Weekly.Name = "Weekly";
        this.Weekly.Size = new System.Drawing.Size(61, 17);
        this.Weekly.TabIndex = 1;
        this.Weekly.TabStop = true;
        this.Weekly.Text = "Weekly";
        this.Weekly.UseVisualStyleBackColor = true;
        // 
        // Fortnightly
        // 
        this.Fortnightly.AutoSize = true;
        this.Fortnightly.Location = new System.Drawing.Point(87, 104);
        this.Fortnightly.Name = "Fortnightly";
        this.Fortnightly.Size = new System.Drawing.Size(73, 17);
        this.Fortnightly.TabIndex = 2;
        this.Fortnightly.TabStop = true;
        this.Fortnightly.Text = "Fortnightly";
        this.Fortnightly.UseVisualStyleBackColor = true;
        // 
        // Monthly
        // 
        this.Monthly.AutoSize = true;
        this.Monthly.Location = new System.Drawing.Point(86, 146);
        this.Monthly.Name = "Monthly";
        this.Monthly.Size = new System.Drawing.Size(62, 17);
        this.Monthly.TabIndex = 3;
        this.Monthly.TabStop = true;
        this.Monthly.Text = "Monthly";
        this.Monthly.UseVisualStyleBackColor = true;
        // 
        // PaymentAmount
        // 
        this.PaymentAmount.Location = new System.Drawing.Point(128, 24);
        this.PaymentAmount.Name = "PaymentAmount";
        this.PaymentAmount.Size = new System.Drawing.Size(100, 20);
        this.PaymentAmount.TabIndex = 4;
        // 
        // label2
        // 
        this.label2.AutoSize = true;
        this.label2.Location = new System.Drawing.Point(39, 201);
        this.label2.Name = "label2";
        this.label2.Size = new System.Drawing.Size(63, 13);
        this.label2.TabIndex = 5;
        this.label2.Text = "Interest rate";
        // 
        // label3
        // 
        this.label3.AutoSize = true;
        this.label3.Location = new System.Drawing.Point(36, 237);
        this.label3.Name = "label3";
        this.label3.Size = new System.Drawing.Size(80, 13);
        this.label3.TabIndex = 6;
        this.label3.Text = "Payment period";
        // 
        // label4
        // 
        this.label4.AutoSize = true;
        this.label4.Location = new System.Drawing.Point(36, 282);
        this.label4.Name = "label4";
        this.label4.Size = new System.Drawing.Size(66, 13);
        this.label4.TabIndex = 7;
        this.label4.Text = "Future value";
        // 
        // InterestRate
        // 
        this.InterestRate.Location = new System.Drawing.Point(149, 201);
        this.InterestRate.Name = "InterestRate";
        this.InterestRate.Size = new System.Drawing.Size(100, 20);
        this.InterestRate.TabIndex = 8;
        // 
        // PaymentPeriod
        // 
        this.PaymentPeriod.Location = new System.Drawing.Point(149, 237);
        this.PaymentPeriod.Name = "PaymentPeriod";
        this.PaymentPeriod.Size = new System.Drawing.Size(100, 20);
        this.PaymentPeriod.TabIndex = 9;
        // 
        // FutureValue
        // 
        this.FutureValue.Location = new System.Drawing.Point(149, 282);
        this.FutureValue.Name = "FutureValue";
        this.FutureValue.Size = new System.Drawing.Size(100, 20);
        this.FutureValue.TabIndex = 10;
        // 
        // ShowAnnuitySchedule
        // 
        this.ShowAnnuitySchedule.Location = new System.Drawing.Point(329, 169);
        this.ShowAnnuitySchedule.Name = "ShowAnnuitySchedule";
        this.ShowAnnuitySchedule.Size = new System.Drawing.Size(149, 23);
        this.ShowAnnuitySchedule.TabIndex = 11;
        this.ShowAnnuitySchedule.Text = "Show annuity schedule";
        this.ShowAnnuitySchedule.UseVisualStyleBackColor = true;
        this.ShowAnnuitySchedule.Click += new System.EventHandler(this.listBox1_SelectedIndexChanged);
        // 
        // CalculateFutureValue
        // 
        this.CalculateFutureValue.Location = new System.Drawing.Point(329, 212);
        this.CalculateFutureValue.Name = "CalculateFutureValue";
        this.CalculateFutureValue.Size = new System.Drawing.Size(149, 23);
        this.CalculateFutureValue.TabIndex = 12;
        this.CalculateFutureValue.Text = "Calculate future value";
        this.CalculateFutureValue.UseVisualStyleBackColor = true;
        this.CalculateFutureValue.Click += new System.EventHandler(this.CalculateFutureValue_Click);
        // 
        // Clear
        // 
        this.Clear.Location = new System.Drawing.Point(365, 253);
        this.Clear.Name = "Clear";
        this.Clear.Size = new System.Drawing.Size(75, 23);
        this.Clear.TabIndex = 13;
        this.Clear.Text = "Clear";
        this.Clear.UseVisualStyleBackColor = true;
        this.Clear.Click += new System.EventHandler(this.Clear_Click);
        // 
        // Schedule
        // 
        this.Schedule.FormattingEnabled = true;
        this.Schedule.Location = new System.Drawing.Point(42, 370);
        this.Schedule.Name = "Schedule";
        this.Schedule.Size = new System.Drawing.Size(436, 225);
        this.Schedule.TabIndex = 15;
        this.Schedule.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged);
        // 
        // Close
        // 
        this.Close.Location = new System.Drawing.Point(365, 299);
        this.Close.Name = "Close";
        this.Close.Size = new System.Drawing.Size(75, 23);
        this.Close.TabIndex = 16;
        this.Close.Text = "Close";
        this.Close.UseVisualStyleBackColor = true;
        this.Close.Click += new System.EventHandler(this.Close_Click);
        // 
        // frmMain
        // 
        this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(192)))));
        this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
        this.ClientSize = new System.Drawing.Size(516, 607);
        this.Controls.Add(this.Close);
        this.Controls.Add(this.Schedule);
        this.Controls.Add(this.Clear);
        this.Controls.Add(this.CalculateFutureValue);
        this.Controls.Add(this.ShowAnnuitySchedule);
        this.Controls.Add(this.FutureValue);
        this.Controls.Add(this.PaymentPeriod);
        this.Controls.Add(this.InterestRate);
        this.Controls.Add(this.label4);
        this.Controls.Add(this.label3);
        this.Controls.Add(this.label2);
        this.Controls.Add(this.PaymentAmount);
        this.Controls.Add(this.Monthly);
        this.Controls.Add(this.Fortnightly);
        this.Controls.Add(this.Weekly);
        this.Controls.Add(this.label1);
        this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
        this.Name = "frmMain";
        this.Text = "Annuity Calculator";
        this.ResumeLayout(false);
        this.PerformLayout();

    }
    #endregion

    public static void Main()
    {
        frmMain main = new frmMain();
        Application.Run(main);
    }

    public frmMain()
    {
        InitializeComponent();
    }


    private void CalculateFutureValue_Click(object sender, System.EventArgs e)
    {
        double paymentAmount;
        double interestRate;
        double paymentPeriod;
        int periodType = 0;
        double futureValue;

        // Get the input value from the form and make sure each is the correct type

        try
        {
        	paymentAmount = Convert.ToDouble(PaymentAmount.Text);
        }
        catch
        {
            MessageBox.Show("Payment amount is required and must be numeric.", Text,
                MessageBoxButtons.OK, MessageBoxIcon.Information);
            PaymentAmount.Focus();
            return;
        }


        try
        {
            paymentPeriod = Convert.ToDouble(PaymentPeriod.Text);
        }
        catch
        {
            MessageBox.Show("Payment period is required and must be numeric.", Text,
                MessageBoxButtons.OK, MessageBoxIcon.Information);
            PaymentPeriod.Focus();
            return;
        }

        //Is radio button weekly selected?

        if (Weekly.Checked)
            periodType = 1;

        // is radio button fortnight selected?

        if (Fortnightly.Checked)
            periodType = 2;

        //Is radio button monthly selected?

        if (Monthly.Checked)
            periodType = 3;

        // Get the interest rate as decimal fraction

        interestRate = double.Parse(InterestRate.Text);

        switch (periodType)
        {
            case 1:
                interestRate = interestRate/5200;
                break;
            case 2:
                interestRate = interestRate/2600;
                break;

            case 3:
                interestRate = interestRate/1200;
                break;
        }

        // Calculate the future value as per the financial calculator

        double Calc1 = Math.Pow ((1+interestRate), periodType);
        double Calc2 = Calc1 -1;
        double Calc3 = Calc2/interestRate;
        futureValue = Calc3 * paymentAmount;
    }
 
    private void Close_Click (object sender, System.EventArgs e)
    {
        Close();
    }

    private void Clear_Click(object sender, System.EventArgs e)
    {
        PaymentAmount.Text = "";
        InterestRate.Text = "";
        PaymentPeriod.Text = "";
        FutureValue.Text = "";
        Schedule.Items.Clear();
    }

    //private void showAnnuitySchedule_Click (object sender, System.EventArgs e)

    
     private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
    {
     	 Schedule.Items.Add("NumberOfPayments");
     	 Schedule.Items.Add("PaymentAmount");
     	 Schedule.Items.Add("Interest");
     	 Schedule.Items.Add("Balance");
         int Count = 1;
         int numberOfPayments;
         int compInRate = 1;
         decimal interest;
         decimal balance;

         numberOfPayments = 1;
         balance = 0;
         
         while (numberOfPayments <= Convert.ToInt32(PaymentPeriod.Text))
         {
             interest = balance * compInRate;
             balance = balance + (balance * (compInRate + Convert.ToDecimal(PaymentAmount.Text)));
             numberOfPayments ++;
         }
     }     
}


Was This Post Helpful? 0
  • +
  • -

#6 shaira.adam  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 14-May 10

Re: code errors

Posted 16 May 2010 - 08:52 AM

D.I.C Head
Thank you so much.
saved my life
Appreciate your help
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1