Question

I am trying to create an application that handles patient files in a hospital. It gives me an error and tells me PatientView = PatientCollection(counter) - ArgumentOutOfRangeException was unhandled. What does this mean and how do I fix this?

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

Thanks very much for your time. Much appreciated

Was it helpful?

Solution

Arrays in NET Framework start at index zero and end at Count - 1.

In your loop

For counter = 0 To PatientCollection.Count

you stop at Count, so the last valued assumed by counter is not valid.
You need to change that loop to

For counter = 0 To PatientCollection.Count - 1

The property Count for an array represents the number of items contained in the array. So, if the first index is zero, the last one should be Count - 1

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top