わかったので、私が見つけたすべての答えはサブプロシージャを扱っています。コンボボックスの選択に基づいて配列からリストボックスを作成する必要はありません。btnCalculate ブロックによってアクティブ化する必要があります
たとえば、コンボボックスの選択が3の場合、リストボックスにfutureValueArray(0) futureValueArray(1) futureValueArray(2)を入力する必要があります
ここに btnCalculate プロシージャのコードがあります
Private Sub btnCalculate_Click(ByVal sender As System.Object,
ByVal e As System.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(cboYears.Text)
Dim monthlyInterestRate As Decimal = yearlyInterestRate / 12 / 100
Dim months As Integer = years * 12
Dim futureValue As Decimal = Me.FutureValue(
monthlyInvestment, monthlyInterestRate, months)
Dim futureValueArray(19) As String
futureValueArray(0) = "Year 1: " & CStr((monthlyInvestment * 12) * yearlyInterestRate)
futureValueArray(1) = "Year 2: " & CStr(((monthlyInvestment * 12) * yearlyInterestRate) * 2)
futureValueArray(2) = "Year 3: " & CStr(((monthlyInvestment * 12) * yearlyInterestRate) * 3)
futureValueArray(3) = "Year 4: " & CStr(((monthlyInvestment * 12) * yearlyInterestRate) * 4)
futureValueArray(4) = "Year 5: " & CStr(((monthlyInvestment * 12) * yearlyInterestRate) * 5)
futureValueArray(5) = "Year 6: " & CStr(((monthlyInvestment * 12) * yearlyInterestRate) * 6)
futureValueArray(6) = "Year 7: " & CStr(((monthlyInvestment * 12) * yearlyInterestRate) * 7)
futureValueArray(7) = "Year 8: " & CStr(((monthlyInvestment * 12) * yearlyInterestRate) * 8)
futureValueArray(8) = "Year 9: " & CStr(((monthlyInvestment * 12) * yearlyInterestRate) * 9)
futureValueArray(9) = "Year 10: " & CStr(((monthlyInvestment * 12) * yearlyInterestRate) * 10)
futureValueArray(10) = "Year 11: " & CStr(((monthlyInvestment * 12) * yearlyInterestRate) * 11)
futureValueArray(11) = "Year 12: " & CStr(((monthlyInvestment * 12) * yearlyInterestRate) * 12)
futureValueArray(12) = "Year 13: " & CStr(((monthlyInvestment * 12) * yearlyInterestRate) * 13)
futureValueArray(13) = "Year 14: " & CStr(((monthlyInvestment * 12) * yearlyInterestRate) * 14)
futureValueArray(14) = "Year 15: " & CStr(((monthlyInvestment * 12) * yearlyInterestRate) * 15)
futureValueArray(15) = "Year 16: " & CStr(((monthlyInvestment * 12) * yearlyInterestRate) * 16)
futureValueArray(16) = "Year 17: " & CStr(((monthlyInvestment * 12) * yearlyInterestRate) * 17)
futureValueArray(17) = "Year 18: " & CStr(((monthlyInvestment * 12) * yearlyInterestRate) * 18)
futureValueArray(18) = "Year 19: " & CStr(((monthlyInvestment * 12) * yearlyInterestRate) * 19)
futureValueArray(19) = "Year 20: " & CStr(((monthlyInvestment * 12) * yearlyInterestRate) * 20)
ListBoxFutureValue.Text = FormatCurrency(futureValue)
txtMonthlyInvestment.Select()
ListBoxFutureValue.Items.Add(futureValue)
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 Sub frmFutureValue_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim items() As String =
{"Please select a number: ", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20"}
For Each item As String In items
cboYears.Items.Add(item)
Next
If cboYears.Items.Count > 0 Then
cboYears.SelectedIndex = 3 ' The first item has index 0 '
End If
End Sub
私の考えでは、 for while ループが必要ですが、2つを比較してリストボックスにデータを入力する方法がわかりません。私は非常に混乱しています。脳が働かない