当我选择列表框中的一个或多个列表时,我尝试向贷款添加一定金额,列表框中的每个项目都有不同或相同的金额。我希望代码能够工作,即使我没有选择或突出显示列表框中的任何项目。
'Extra Sevices
Dim extra As Integer
For i As Integer = 0 To ListBox1.SelectedItem.count
If ListBox1.SelectedItem = "insurance - O" Or
ListBox1.SelectedItem = "Hotel discount -O" Then
extra = 500
ElseIf ListBox1.SelectedItem = "One payment grace -F" Or
ListBox1.SelectedItem = "2-day late payment-F" Or
ListBox1.SelectedItem = "Frequent Borrowe benefits -F" Or
ListBox1.SelectedItem = "Online reversals -F" Or
ListBox1.SelectedItem = "GST waver -F" Then
extra = 500
ElseIf ListBox1.SelectedItem = "Face to face transactions -S" Or
ListBox1.SelectedItem = "Saturday visits -S" Or
ListBox1.SelectedItem = "Face to face consultations -S" Or
ListBox1.SelectedItem = "Phone reminders -S" Then
extra = 200
Else
extra = 0
End If
extra = extra + extra
Next
答案 0 :(得分:0)
您的代码中存在一些小问题
'Extra Sevices
Dim i As Integer
Dim extra As Integer
Dim value as Integer
extra = 0
For i = 0 To ListBox1.SelectedItems.count - 1
value = 0
'-> This line of code answered the ORIGINAL question
' Select case Listbox1.SelectedItem
'-> This line of code answeres your question in the comments
Select case Listbox1.SelectedItem(i)
Case "insurance - O", "Hotel discount -O"
value = 500
Case "One payment grace -F", "2-day late payment-F", "Frequent Borrowe benefits -F", "Online reversals -F", "GST waver -F"
value = 500
Case "Face to face transactions -S", "Saturday visits -S", "Face to face consultations -S", "Phone reminders -S"
value = 200
End Select
extra = extra + value
Next
这应该可以修复它们,您可以将代码与您的代码进行比较。
主要观点是循环,你以COUNT结束,列表为零,所以它计数-1