我正在编写一个程序,该程序应该使用给定信息计算余额(他们选择哪个复选框(储蓄(7%),公司(5%),或两者,然后他们选择的年份(2015,2016,2017),最后他们在提示输入余额时投入的金额(这取决于他们在第一步中选择的账户类型)。除了他们选择两种账户类型(储蓄和公司)。对我来说,如果两者都被选中,它们应该是一条只添加两个总数的行,但事实并非如此。至少对我来说不是。
如果我输入 2000 美元的储蓄余额并选择 2015 年,我得到的总额是 2289.80 美元,这是正确的,然后如果我为公司账户选择 2015 年并输入 1000 美元,那么总额是 1102.50 美元。因此,如果我选择了两个帐户并输入了相同的数字,但同时选中了两个复选框,我将得到 3434.70 美元,但我应该得到 3392.30 美元!
这是我的代码,任何帮助将不胜感激!(我认为它可能实际上只是一行代码,它正在杀死我!)
Public Class Form1
Private Sub btnMediaEstimatedFund_Click(sender As Object, e As EventArgs) Handles btnMediaEstimatedFund.Click
Dim interestRate, initialBalanceSavings, initialBalanceCorporate, finalBalance, year, theYear, subTotal As Double
Dim savingsInterestRate As Double = 0
Dim corporateInterestRate As Double = 0
Dim savingsSubTotal As Double = 0
Dim corporateSubTotal As Double = 0
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
savingsInterestRate = 0.07
ElseIf checkBoxCorporate.Checked Then
corporateInterestRate = 0.05
End If
If checkBoxSavings.Checked = False And checkBoxCorporate.Checked = False Then
MsgBox("Please chose an account type to proceed!", MsgBoxStyle.Critical, "Error")
End If
If radButton2015.Checked Then
theYear = 2015
ElseIf radButton2016.Checked Then
theYear = 2016
ElseIf 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
savingsSubTotal = initialBalanceSavings
corporateSubTotal = initialBalanceCorporate
For year = 2013 To theYear - 1
If savingsInterestRate > 0 Then
savingsSubTotal = savingsSubTotal * (1 + savingsInterestRate)
End If
If corporateInterestRate > 0 Then
corporateSubTotal = corporateSubTotal * (1 + corporateInterestRate)
End If
Next
finalBalance = savingsSubTotal + corporateSubTotal
txtBoxEstimatedBudget.Text = FormatCurrency(finalBalance)
End Sub