我不明白为什么在线获得超出范围的索引错误:AssessmentRecord.ToList(RecordPosition)。考试 = Val(txtscore.正文)



进入持续评估的代码

Private Sub-bnloadrecords_Click(发送方为Object,e为EventArgs)处理bnloadrecords。点击

    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

将记录位置标注为整数

Private Sub bnenter_Click(sender As Object,e As EventArgs)处理bnenter。点击

    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(发送方为Object,e为EventArgs)处理bnloadrecords。点击

    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

将记录位置标注为整数

Private Sub bnenter_Click(sender As Object,e As EventArgs)处理bnenter。点击

    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()

结束子

计算持续评估和;检查

专用子bncomputerresults_Click(发送方为对象,e为EventArgs)处理bncomputerResults。点击

    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

最新更新