我不明白为什么会出现索引超出范围的在线错误:AssessmentRecord.ToList(RecordPosition).Exams = Val(txtscore.Text)
I don' t understand why am getting an index out of range error on line: AssessmentRecord.ToList(RecordPosition).Exams = Val(txtscore.Text)
进入连续评估的代码
Private Sub bnloadrecords_Click(sender As Object, e As EventArgs) 句柄 bnloadrecords.Click
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 <> 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
将 RecordPosition 调暗为整数
Private Sub bnenter_Click(sender As Object, e As EventArgs) 句柄 bnenter.Click
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) > 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 < (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
进入考试代码
Private Sub bnloadrecords_Click(sender As Object, e As EventArgs) 句柄 bnloadrecords.Click
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 <> 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
将 RecordPosition 调暗为整数
Private Sub bnenter_Click(sender As Object, e As EventArgs) 句柄 bnenter.Click
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) > 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 < (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()
结束子
计算连续评估和考试的代码
Private Sub bncomputeresults_Click(sender As Object, e As EventArgs) 句柄 bncomputeresults.Click
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) >= 80 Then
AssessmentRecords.ToList(j - 1).Grade = "1"
AssessmentRecords.ToList(j - 1).Remarks = "DISTINCTION"
ElseIf Val(AssessmentRecords.ToList(j - 1).Exams) >= 79 Then
AssessmentRecords.ToList(j - 1).Grade = "2"
AssessmentRecords.ToList(j - 1).Remarks = "MERIT"
ElseIf Val(AssessmentRecords.ToList(j - 1).Exams) >= 69 Then
AssessmentRecords.ToList(j - 1).Grade = "3"
AssessmentRecords.ToList(j - 1).Remarks = "CREDIT"
ElseIf Val(AssessmentRecords.ToList(j - 1).Exams) >= 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
我怀疑他的块是为了防止 RecordPosition
成为无效索引,但它恰恰相反。
If RecordPosition < (AssessmentRecord.Count - 1) Then
MsgBox("End of Records Reached!", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly)
Exit Sub
End If
第一行可能应该使用 >
而不是 <
以便在 RecordPosition
超过列表末尾时停止。
If RecordPosition > (AssessmentRecord.Count - 1) Then
进入连续评估的代码
Private Sub bnloadrecords_Click(sender As Object, e As EventArgs) 句柄 bnloadrecords.Click
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 <> 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
将 RecordPosition 调暗为整数
Private Sub bnenter_Click(sender As Object, e As EventArgs) 句柄 bnenter.Click
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) > 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 < (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
进入考试代码
Private Sub bnloadrecords_Click(sender As Object, e As EventArgs) 句柄 bnloadrecords.Click
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 <> 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
将 RecordPosition 调暗为整数
Private Sub bnenter_Click(sender As Object, e As EventArgs) 句柄 bnenter.Click
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) > 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 < (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()
结束子
计算连续评估和考试的代码
Private Sub bncomputeresults_Click(sender As Object, e As EventArgs) 句柄 bncomputeresults.Click
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) >= 80 Then
AssessmentRecords.ToList(j - 1).Grade = "1"
AssessmentRecords.ToList(j - 1).Remarks = "DISTINCTION"
ElseIf Val(AssessmentRecords.ToList(j - 1).Exams) >= 79 Then
AssessmentRecords.ToList(j - 1).Grade = "2"
AssessmentRecords.ToList(j - 1).Remarks = "MERIT"
ElseIf Val(AssessmentRecords.ToList(j - 1).Exams) >= 69 Then
AssessmentRecords.ToList(j - 1).Grade = "3"
AssessmentRecords.ToList(j - 1).Remarks = "CREDIT"
ElseIf Val(AssessmentRecords.ToList(j - 1).Exams) >= 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
我怀疑他的块是为了防止 RecordPosition
成为无效索引,但它恰恰相反。
If RecordPosition < (AssessmentRecord.Count - 1) Then
MsgBox("End of Records Reached!", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly)
Exit Sub
End If
第一行可能应该使用 >
而不是 <
以便在 RecordPosition
超过列表末尾时停止。
If RecordPosition > (AssessmentRecord.Count - 1) Then