1

我正在尝试创建一个处理医院患者文件的应用程序。它给了我一个错误并告诉我PatientView = PatientCollection(counter) - ArgumentOutOfRangeException 未处理。这是什么意思,我该如何解决?

Public Class SelectPatient

Private Sub SelectPatient_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Label1.Text = "Select Patient"

    Dim counter As Integer = 0

    ComboBox1.Items.Clear()
    For counter = 0 To PatientCollection.Count
        Dim PatientView As New PatientObject4
        PatientView = PatientCollection(counter)
        ComboBox1.Items.Add(PatientView.LastName & "," & PatientView.Firstname)
    Next
End Sub

Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged

    CollectionIndexValue = ComboBox1.SelectedIndex

    Globals.NewPatientData()



End Sub
End Class

非常感谢你花时间陪伴。非常感激

4

1 回答 1

4

NET Framework 中的数组从索引 0 开始,到 Count - 1 结束。

在你的循环中

For counter = 0 To PatientCollection.Count

您停在 Count 处,因此假定的最后一个值counter无效。
您需要将该循环更改为

For counter = 0 To PatientCollection.Count - 1

数组的属性 Count 表示数组中包含的项目数。因此,如果第一个索引为零,则最后一个索引应为 Count - 1

于 2013-11-25T17:52:57.073 回答