我在计算代码中的余额时遇到了一些麻烦。
在这个节目(balance = balance * (1 + interestRate)
中。问题是我们在 2013 年,余额将计算 2015-2017 年,由用户在程序中单击的复选框选择,并且用户选择他们将拥有的帐户类型(即储蓄: 7% 的利息,公司:5% 的利息)。
然后,他们将单击该mediaEstimatedFund
按钮,并要求他们为他们选择的账户类型(储蓄、公司或两者)输入余额。然后它应该计算他们选择的(Year、Account和Balance amount)的余额。
这是我拥有的代码,它没有给我正确的余额(例如:如果用户选择 2000.00 美元,储蓄账户为 7% 和 2016 年,它应该给我 2621.60 美元的估计预算),但它不是!
Year Savings Account Corporate Account Saving + Corporate
2013 $2000.00 $1000.00 $3000.00
2014 $2140.00 $1050.00 $3190.00
2015 $2289.8 $1102.5 $3392.3
2016 $2450.086 $1157.625 $3607.711
2017 $2621.59202 $1215.50625 $3837.09827
Public Class Form1
Private Sub btnMediaEstimatedFund_Click(sender As Object, e As EventArgs) Handles btnMediaEstimatedFund.Click
Dim interestRate, initialBalanceSavings, initialBalanceCorporate, finalBalance, theYear, balance, subTotal As Double
txtBoxEstimatedBudget.Enabled = False
txtBoxAgenciesNeeded.Enabled = False
If radButtonTraditional.Checked Then
txtBoxAgenciesNeeded.Text = 3
ElseIf radButtonEMedia.Checked Then
txtBoxAgenciesNeeded.Text = 2
End If
If checkBoxSavings.Checked Then
interestRate = 0.07
ElseIf checkBoxCorporate.Checked Then
interestRate = 0.05
ElseIf checkBoxCorporate.Checked And checkBoxSavings.Checked Then
interestRate = 0.12
End If
If radButton2015.Checked Then
theYear = 2015
End If
If radButton2016.Checked Then
theYear = 2016
End If
If radButton2017.Checked Then
theYear = 2017
End If
Dim inputtedData As String
If checkBoxSavings.Checked Then
Do
inputtedData = InputBox("Please enter a balance for SAVINGS account between $500.00 and $3000.00", "Initial Savings Balance", "0.00")
If inputtedData = "" Then
MsgBox("User chose to cancel calculation!")
Exit Sub
Else
initialBalanceSavings = CType(inputtedData, Single)
If initialBalanceSavings > 3000 Or initialBalanceSavings < 500 Then MsgBox("Please enter a balance for SAVINGS account equal to or above $500.00 and no more than $3000.00", MsgBoxStyle.Critical, "Error")
End If
Loop Until initialBalanceSavings >= 500 And initialBalanceSavings <= 3000
End If
If checkBoxCorporate.Checked Then
Do
inputtedData = InputBox("Please enter a balance for CORPORATE account between $500.00 and $3000.00", "Initial Corporate Balance", "0.00")
If inputtedData = "" Then
MsgBox("User chose to Cancel calculation!")
Exit Sub
Else
initialBalanceCorporate = CType(inputtedData, Single)
If initialBalanceCorporate > 3000 Or initialBalanceCorporate < 500 Then MsgBox("Please enter a balance for CORPORATE account equal to or above $500.00 and no more than $3000.00", MsgBoxStyle.Critical, "Error")
End If
Loop Until initialBalanceCorporate >= 500 And initialBalanceCorporate <= 3000
End If
finalBalance = initialBalanceSavings + initialBalanceCorporate
For theYear = 2013 To 2017
subTotal = finalBalance * (1 + interestRate)
finalBalance = subTotal
Next
txtBoxEstimatedBudget.Text = FormatCurrency(finalBalance)
End Sub