title: I don' t understand why am getting an index out of range error on line: AssessmentRecord.ToList(RecordPosition).Exams = Val(txtscore.Text)
body: <p><strong>Code for Entering Continuous Assessments</strong> </p>
  
  <p>Private Sub bnloadrecords_Click(sender As Object, e As EventArgs) Handles bnloadrecords.Click</p>
  
  <pre><code>    If cboclass.Text = "" Or cbostream.Text = "" Or cbosubject.Text = "" Then
      MsgBox("Please select a class, stream and subject to proceed!", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly)
      Exit Sub
      End If
  
  Dim db As New SMSDataContext
  Dim AssessmentRecords = From p In db.Assessments
  
  
  
      Where p.Class = cboclass.Text And p.Stream = cbostream.Text And p.Subject = cbosubject.Text
      Select p
      If AssessmentRecords.Count &lt;&gt; 0 Then
      Me.AssessmentsTableAdapter.FillByClass(Me.SMS.Assessments, cboclass.Text, cbostream.Text, cbosubject.Text)
  
  Else
  
  
  Dim StudentRecords = From p In db.Students                            
  Where p.Class = cboclass.Text And p.Stream = cbostream.Text
  Select p
  
  
  
      If StudentRecords.Count = 0 Then
      MsgBox("No student' records in the system that match your criteria!", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly)
      Exit Sub
      Else
  
  
      For j = 1 To StudentRecords.Count
  
  Dim NewAssessmentRecord As New Assessment With {.CA = 0, .Class = cboclass.Text, .Full_Name = StudentRecords.ToList(j - 1).Full_Name, .Registration_Number = StudentRecords.ToList(j - 1).Registration_Number, .Stream = cbostream.Text, .Subject = cbosubject.Text}
  
  db.Assessments.InsertOnSubmit(NewAssessmentRecord)
  db.SubmitChanges()
  
  Next
  
  
          Me.AssessmentsTableAdapter.FillByClass(Me.SMS.Assessments, cboclass.Text, cbostream.Text, cbosubject.Text)           
      lblcurrentStudent.Text = AssessmentRecords.FirstOrDefault.Full_Name
      RecordPosition = 0
      txtscore.Focus()
      End If
  End If
  
  End Sub
  </code></pre>
  
  <p>Dim RecordPosition As Integer</p>
  
  <p>Private Sub bnenter_Click(sender As Object, e As EventArgs) Handles bnenter.Click</p>
  
  <pre><code>    If txtscore.Text = "" Then
      MsgBox("Continous Assessment cannot be empty!", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly)
      Exit Sub
       End If
  
      If Not IsNumeric(txtscore.Text) Then
      MsgBox("Score must be numeric!", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly)
      Exit Sub
      End If
  
      If Val(txtscore.Text) &gt; 25 Then
      MsgBox("CA Score cannot be above 25 marks!", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly)
      Exit Sub
      End If
  Dim db As New SMSDataContext
  Dim AssessmentRecord = From p In db.Assessments
  
      Where p.Class = cboclass.Text And p.Stream = cbostream.Text And p.Subject = cbosubject.Text
      Select p
  
      If RecordPosition &lt; (AssessmentRecord.Count - 1) Then
      MsgBox("End of Records Reached!", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly)
      Exit Sub
      End If
  
  AssessmentRecord.ToList(RecordPosition).CA = Val(txtscore.Text)
  db.SubmitChanges()
  RecordPosition += 1
  
      If RecordPosition = (AssessmentRecord.Count - 1) Then
      MsgBox("End of Record Reached!", MsgBoxStyle.Exclamation +MsgBoxStyle.OkOnly)
      Exit Sub 
      End If
  
  txtscore.Clear()
  txtscore.Focus()
  End Sub
  </code></pre>
  
  <p><strong>Code for Entering Exams</strong></p>
  
  <p>Private Sub bnloadrecords_Click(sender As Object, e As EventArgs) Handles bnloadrecords.Click</p>
  
  <pre><code>    If cboclass.Text = "" Or cbostream.Text = "" Or cbosubject.Text = "" Then
          MsgBox("Please select a class, stream and subject to proceed!",MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly)
      Exit Sub
      End If
  
  Dim db As New SMSDataContext
  Dim AssessmentRecords = From p In db.Assessments
  
  
      Where p.Class = cboclass.Text And p.Stream = cbostream.Text And p.Subject = cbosubject.Text
                         Select p
  
  
  
      If AssessmentRecords.Count &lt;&gt; 0 Then   Me.AssessmentsTableAdapter.FillByClass(Me.SMS.Assessments,cboclass.Text,cbostream.Text, cbosubject.Text)
       Else
  
  
  Dim StudentRecords = From p In db.Students
  
   Where p.Class = cboclass.Text And p.Stream = cbostream.Text
                            Select p
  
  
  
      If StudentRecords.Count = 0 Then
          MsgBox("No student' records in the system that match your criteria!", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly)
      Exit Sub
      Else
  
  
      For j = 1 To StudentRecords.Count
  
      Dim NewAssessmentRecord As New Assessment With {.Class = cboclass.Text, .Exams = 0, .Full_Name = StudentRecords.ToList(j - 1).Full_Name, .Registration_Number = StudentRecords.ToList(j - 1).Registration_Number, .Stream = cbostream.Text, .Subject = cbosubject.Text}
  
                              db.Assessments.InsertOnSubmit(NewAssessmentRecord)
                              db.SubmitChanges()
  
  
      Next
                      Me.AssessmentsTableAdapter.FillByClass(Me.SMS.Assessments, cboclass.Text, cbostream.Text, cbosubject.Text)        
  
   lblcurrentStudent.Text = AssessmentRecords.FirstOrDefault.Full_Name
   RecordPosition = 0
   txtscore.Focus()
  End If     
  End If
  End Sub
  </code></pre>
  
  <p>Dim RecordPosition As Integer</p>
  
  <p>Private Sub bnenter_Click(sender As Object, e As EventArgs) Handles bnenter.Click</p>
  
  <pre><code>    If txtscore.Text = "" Then
         MsgBox("Exams cannot be empty!", MsgBoxStyle.Exclamation +   MsgBoxStyle.OkOnly)
         Exit Sub
      End If
  
  
      If Not IsNumeric(txtscore.Text) Then
      MsgBox("Score must be numeric!", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly)
      Exit Sub
      End If
  
  
      If Val(txtscore.Text) &gt; 75 Then
      MsgBox("Exams Score cannot be above 75 marks!", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly)
      Exit Sub
      End If
  
  Dim db As New SMSDataContext
  Dim AssessmentRecord = From p In db.Assessments
  
      Where p.Class = cboclass.Text And p.Stream = cbostream.Text And p.Subject = cbosubject.Text
      Select p
  
      If RecordPosition &lt; (AssessmentRecord.Count - 1) Then
      MsgBox("End of Records Reached!", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly)
      Exit Sub
      End If
  
  
  AssessmentRecord.ToList(RecordPosition).Exams = Val(txtscore.Text)
  db.SubmitChanges()
  RecordPosition += 1
  
      If RecordPosition = (AssessmentRecord.Count - 1) Then
      MsgBox("End of Record Reached!", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly)
      Exit Sub
      End If
  
  txtscore.Clear()
  txtscore.Focus()
  </code></pre>
  
  <p>End Sub</p>
  
  <p><strong>Code for Computing both Continuous Assessments &amp; Exams</strong></p>
  
  <p>Private Sub bncomputeresults_Click(sender As Object, e As EventArgs) Handles bncomputeresults.Click</p>
  
  <pre><code>    If cboclass.Text = "" Or cbostream.Text = "" Then
      MsgBox("Select a class and stream to proceed!", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly)
      Exit Sub
      End If
  
  
  
  Dim db As New SMSDataContext
  Dim AssessmentRecords = From p In db.Assessments
  
      Where p.Class = cboclass.Text And p.Stream = cbostream.Text
      Select p
  
  
  
      If AssessmentRecords.Count = 0 Then
      MsgBox("No records found, Please select a new set of options to proceed!", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly)
      Exit Sub
      End If
  
  
  
      For j = 1 To AssessmentRecords.Count
      AssessmentRecords.ToList(j - 1).Exams = Val(AssessmentRecords.ToList(j - 1).CA) + Val(AssessmentRecords.ToList(j - 1).Exams)
  
  
      If Val(AssessmentRecords.ToList(j - 1).Exams) &gt;= 80 Then
      AssessmentRecords.ToList(j - 1).Grade = "1"
      AssessmentRecords.ToList(j - 1).Remarks = "DISTINCTION"
  
  
      ElseIf Val(AssessmentRecords.ToList(j - 1).Exams) &gt;= 79 Then
      AssessmentRecords.ToList(j - 1).Grade = "2"
      AssessmentRecords.ToList(j - 1).Remarks = "MERIT"
  
  
      ElseIf Val(AssessmentRecords.ToList(j - 1).Exams) &gt;= 69 Then
      AssessmentRecords.ToList(j - 1).Grade = "3"
      AssessmentRecords.ToList(j - 1).Remarks = "CREDIT"
  
  
      ElseIf Val(AssessmentRecords.ToList(j - 1).Exams) &gt;= 59 Then
      AssessmentRecords.ToList(j - 1).Grade = "4"
      AssessmentRecords.ToList(j - 1).Remarks = "PASS"
  Else
  
      AssessmentRecords.ToList(j - 1).Grade = "F"
      AssessmentRecords.ToList(j - 1).Remarks = "FAIL"
      End If
  
  Next
  
  
  db.SubmitChanges()
  Dim TotaledRecords = From p In db.Assessments    
  
      Where p.Class = cboclass.Text And p.Stream = cbostream.Text
      Select p
      Order By p.Total Descending
  
  
  
  
  
      For j = 1 To TotaledRecords.Count
       TotaledRecords.ToList(j - 1).Position = j
  
   Next
  
  
  db.SubmitChanges()
  Me.AssessmentsTableAdapter.FillByClassStream(Me.SMS.Assessments, cboclass.Text, cbostream.Text)
  
  End Sub
  </code></pre>