Hi Everybody!
I've
trying to create a simple calculator for users to determine Future
Value. I'm using a combination of textboxes, combo boxes and eventually
want to calculate FV to have it displayed in a listview. Below is my
criteria that I'm trying to meet and also is my code that I've tried to
implement. After users have entered and selected the proper
information. I'm using a button as a click event procedure that will
determine the FV. This is my first time trying to implement a C# sharp
project of this size as I'm currently still learning as I go along. I
hope that someone out there can help with my coding so that I can learn
how to achieve the requirements below.
1) Use a combobox to specify annual rate (0.05 to 0.12 with an increment of 0.01) or be able to enter other rates as well.
2) Use a comobox to specify the number of periods per year (1, 4, 12, 365)
3) Be able to enter in textboxes values for first year, last year, and amount.
4.) Use FV function to calculate given inputs and display FV in a listview
What
I'm having trouble most is calculating FV and getting the info to
display correctly in the listview. I'm getting conversion errors of string to integer errors. I know for sure that I may have declared the variables inncorrectly. I would greatly appreciate assistance in helping my learning process to understanding how to implement this project correctly.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Trial1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void btnCompute_Click(object sender, EventArgs e)
{
double amount;
double firstYear;
double lastYear;
decimal annualRate;
double period;
double life;
double futureValue;
ListViewItem row;
amount = int.Parse(txtAmt.Text);
firstYear = int.Parse(txtFirst.Text);
lastYear = int.Parse(txtLast.Text);
annualRate = double.Parse(cboRate.SelectedItem);
life= double.Parse(cboPer.SelectedItem);
lvwFV.Items.Clear();
for (period = 1; life <= 365; )
{
futureValue=fV(amount,annualRate,life);
FV= futureValue;
row = lvwFV.Items.Add(life);
row.SubItems.Add(FV.ToString("C"));
}
}
Loading
Scott LyslePosted Feb 12, 2008, 10:28 PM
Assuming that you are using Microsoft.VisualBasic.Financial.FV to perform the future value calculation, you should look at the data types required in that function's argument list.
They are: Rate as double, Pmt as Double, PV as Double, and Due as Microsoft.VisualBasic.DueDate.
In general, when converting values convert them to the same type; don't convert doubles to ints for example. When reading the selected item from the combobox, write cboAmt.SelectedItem.ToString().