Dim index As Integer
Dim choice As String
Dim total As Integer
total = 0
index = NumericUpDown1.Value
Dim arr(4) As Integer
arr(0) = 10
arr(1) = 5
arr(2) = 21
arr(3) = 33
If index > 0 Then
choice = (Combobox1.SelectedItem.ToString + " x " + NumericUpDown1.Value.ToString)
ListBox1.Items.Add(choice)
CheckedListBox1.Items.Add(choice)
total += arr(Combobox1.SelectedIndex) * index
TotalLabel.Text = total.ToString()
Else
MsgBox("error.")
End If
我可以计算单项选择的总数,但无法累计求和。代码有什么问题?
当前情况: 第1步: 选择arr(0),index = 2 total = 20
第 2 步: 选择 arr(2),索引 = 1 总计 = 21
正确情况: 第1步: 选择arr(0), index = 2 total = 20
第 2 步: 选择 arr(2),索引 = 1 总计 = 41