I'm making a program which you can input a student name and 3 exam scores and then have it added to an array of students which is printed on a list. But I get this error on the 'Exam1(Index) = Mark1' line of code and i don't know how to fix it: System.NullReferenceException: 'Object reference not set to an instance of an object.'
Public Class Form1
Dim StudentName(), Identity() As String
Dim Exam1(), Exam2(), Exam3() As Integer
Dim Index As Integer = 0
Private Sub btnDetails_Click(sender As Object, e As EventArgs) Handles btnDetails.Click
For Index = 0 To Index
lstStudent.Items.Add(Identity(Index))
Next Index
End Sub
Dim Average As Decimal
Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
Dim Mark1, Mark2, Mark3 As Integer
Mark1 = CInt(txtMark1.Text)
Mark2 = CInt(txtMark2.Text)
Mark3 = CInt(txtMark3.Text)
StudentName(Index) = txtStudentName.Text
Exam1(Index) = Mark1
Exam2(Index) = Mark2
Exam3(Index) = Mark3
Index = Index + 1
Identity(Index) = StudentName(Index) & Exam1(Index) & Exam2(Index) * Exam3(Index)
End Sub
End Class