Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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)

image text in transcribed

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:

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MySQL Crash Course A Hands On Introduction To Database Development

Authors: Rick Silva

1st Edition

1718503008, 978-1718503007

More Books

Students also viewed these Databases questions

Question

Describe five career management practices

Answered: 1 week ago

Question

1. Identify what positions are included in the plan.

Answered: 1 week ago

Question

2. Identify the employees who are included in the plan.

Answered: 1 week ago

Question

7. Discuss the implications of a skill-based pay plan for training.

Answered: 1 week ago