Question: Provided Code: Public Class frmFutureValue Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click Try If IsValidData() Then Dim monthlyInvestment As Decimal = Convert.ToDecimal(txtMonthlyInvestment.Text)

 Provided Code: Public Class frmFutureValue Private Sub btnCalculate_Click(sender As Object, e

Provided Code:

Public Class frmFutureValue

Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click Try If IsValidData() Then Dim monthlyInvestment As Decimal = Convert.ToDecimal(txtMonthlyInvestment.Text) Dim yearlyInterestRate As Decimal = Convert.ToDecimal(txtInterestRate.Text) Dim years As Integer = Convert.ToInt32(txtYears.Text)

Dim monthlyInterestRate As Decimal = yearlyInterestRate / 12 / 100 Dim months As Integer = years * 12

Dim futureValue As Decimal = Me.FutureValue( monthlyInvestment, monthlyInterestRate, months)

txtFutureValue.Text = FormatCurrency(futureValue) txtMonthlyInvestment.Select() End If Catch ex As Exception MessageBox.Show(ex.Message & vbCrLf & vbCrLf & ex.GetType.ToString & vbCrLf & vbCrLf & ex.StackTrace, "Exception") End Try End Sub

Private Function IsValidData() As Boolean Return _ IsPresent(txtMonthlyInvestment, "Monthly Investment") AndAlso IsDecimal(txtMonthlyInvestment, "Monthly Investment") AndAlso IsWithinRange(txtMonthlyInvestment, "Monthly Investment", 1, 1000) AndAlso IsPresent(txtInterestRate, "Yearly Interest Rate") AndAlso IsDecimal(txtInterestRate, "Yearly Interest Rate") AndAlso IsWithinRange(txtInterestRate, "Yearly Interest Rate", 1, 15) AndAlso IsPresent(txtYears, "Number of Years") AndAlso IsInt32(txtYears, "Number of Years") AndAlso IsWithinRange(txtYears, "Number of Years", 1, 50) End Function

Private Function IsPresent(textBox As TextBox, name As String) _ As Boolean If textBox.Text = "" Then MessageBox.Show(name & " is a required field.", "Entry Error") textBox.Select() Return False End If Return True End Function

Private Function IsDecimal(textBox As TextBox, name As String) _ As Boolean Dim number As Decimal = 0 If Decimal.TryParse(textBox.Text, number) Then Return True Else MessageBox.Show(name & " must be a decimal value.", "Entry Error") textBox.Select() textBox.SelectAll() Return False End If End Function

Private Function IsInt32(textBox As TextBox, name As String) _ As Boolean Dim number As Integer = 0 If Int32.TryParse(textBox.Text, number) Then Return True Else MessageBox.Show(name & " must be an integer.", "Entry Error") textBox.Select() textBox.SelectAll() Return False End If End Function

Private Function IsWithinRange(textBox As TextBox, name As String, min As Decimal, max As Decimal) As Boolean Dim number As Decimal = CDec(textBox.Text) If number max Then MessageBox.Show(name & " must be between " & min & " and " & max & ".", "Entry Error") textBox.Select() textBox.SelectAll() Return False End If Return True End Function

Private Function FutureValue(monthlyInvestment As Decimal, monthlyInterestRate As Decimal, months As Integer) _ As Decimal For i As Integer = 1 To months FutureValue = (FutureValue + monthlyInvestment) * (1 + monthlyInterestRate) Next End Function

Private Sub ClearFutureValue(sender As Object, e As EventArgs) Handles txtMonthlyInvestment.TextChanged, txtYears.TextChanged, txtInterestRate.TextChanged txtFutureValue.Text = "" End Sub

Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click Me.Close() End Sub End Class

UI:

As EventArgs) Handles btnCalculate.Click Try If IsValidData() Then Dim monthlyInvestment As Decimal

Section 2 he i Du Declare module-level variables for a row index and a rectangular array of strings that provides for 10 rows and 4 columns. Use a rectangular array to store future value calculations Add code that stores the values for each calculation in the next row of the array when the user clicks the Calculate button. Store th 3. e monthly investment and future value in currency format, and store the interest rate in percent format. Add code to display the elements in the array in a message box when the user clicks the Exit button. Use tab characters to format the message box so it looks like this: 4. Future Value Calculations Inv/Mo. Rate Years Future Value S100.00 4.0% 5 SI00-00 4.5% 5 S100.00 5.0% 5 $6,652.00 6,739.73 $6,82894 oK 5. Test the program by making up to 10 future value calculations. When you've got this working right, close the solution

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!