主题:求助 求VB高手解释程序
Option Explicit
''答案显示项目之间的距离
Private Const mcsinSpace As Single = 200
Private mintCurrentSubject As Integer ''当前的试题
Private rstMain As Recordset
Private rstDetail As Recordset
Private isProgChangeValue As Boolean
Private Sub chkAnswer_Click(Index As Integer)
Dim i As Integer
Dim strAnswer As String
Static isBusy As Boolean
Dim rst As Recordset
If isProgChangeValue Then GoTo Proc_Exit
If Not isBusy Then
isBusy = True
If Not rstMain![题目类型] Then
For i = 0 To chkAnswer.UBound
If i <> Index Then
chkAnswer(i).Value = 0
Else
chkAnswer(i).Value = 1
strAnswer = chkAnswer(i).Caption
End If
Next i
Else
For i = 0 To chkAnswer.UBound
If chkAnswer(i).Value = 1 Then
strAnswer = strAnswer & chkAnswer(i).Caption
End If
Next i
End If
Set rst = New Recordset
rst.ActiveConnection = pCN
rst.Source = "select * from 考生答案 where 准考证号='" & pudtStudent.准考证号 & "' and 题目编号='" & rstMain![题目编号] & "'"
rst.CursorLocation = adUseClient
rst.CursorType = adOpenStatic
rst.LockType = adLockBatchOptimistic
rst.Open
rst![考生答案] = strAnswer
rst.UpdateBatch
Set rst = Nothing
isBusy = False
End If
Proc_Exit:
End Sub
''下一题
Private Sub Command1_Click()
If Not rstMain.EOF Then
Command1.Enabled = True
Command2.Enabled = True
rstMain.MoveNext
If rstMain.RecordCount = rstMain.Bookmark Then
Command1.Enabled = False
Command2.Enabled = True
End If
Else
rstMain.MoveLast
End If
Call RefreshSubject
End Sub
Private Sub RefreshSubject()
Dim i As Integer
Dim rstAnswer As Recordset
lblDescription.Caption = rstMain![题目内容]
Frame1.Caption = IIf(rstMain![题目类型], "多选题", "单选题")
Me.Caption = "准考证号: " & pudtStudent.准考证号 & " 姓名: " & pudtStudent.考生姓名 & " 当前 第 " & rstMain.Bookmark & " 条"
''得到答题的数据
Call SetDetail
''首先卸载当前加载的对象
For i = 1 To lblAnswer.UBound
Unload lblAnswer(i)
Unload chkAnswer(i)
Next i
isProgChangeValue = True
chkAnswer(0).Value = 0
For i = 1 To rstDetail.RecordCount - 1
Load chkAnswer(i)
chkAnswer(i).Left = chkAnswer(0).Left
Load lblAnswer(i)
lblAnswer(i).Width = lblAnswer(0).Width
lblAnswer(i).Height = lblAnswer(0).Height
lblAnswer(i).Left = lblAnswer(0).Left
Next i
rstDetail.MoveFirst
chkAnswer(0).Caption = rstDetail![题目编码]
'lblAnswer(i).Left = 10
lblAnswer(0).Caption = rstDetail![备选答案]
rstDetail.MoveNext
For i = 1 To rstDetail.RecordCount - 1
chkAnswer(i).Caption = rstDetail![题目编码]
chkAnswer(i).Top = lblAnswer(i - 1).Top + lblAnswer(i - 1).Height + mcsinSpace
lblAnswer(i).Top = chkAnswer(i).Top
lblAnswer(i).Caption = rstDetail![备选答案]
lblAnswer(i).Visible = True
chkAnswer(i).Visible = True
rstDetail.MoveNext
Next i
''如果该题已经做过了,则加载该题的答案
Set rstAnswer = New Recordset
rstAnswer.CursorLocation = adUseClient
rstAnswer.LockType = adLockBatchOptimistic
rstAnswer.CursorType = adOpenStatic
rstAnswer.Source = "select * from 考生答案 where 准考证号='" & pudtStudent.准考证号 & "' and 题目编号='" & rstMain![题目编号] & "'"
rstAnswer.ActiveConnection = pCN
rstAnswer.Open
If Len(rstAnswer![考生答案] & "") > 0 Then
For i = 0 To chkAnswer.UBound
If InStr(1, UCase(rstAnswer![考生答案]), UCase(chkAnswer(i).Caption)) > 0 Then
chkAnswer(i).Value = 1
End If
Next i
End If
isProgChangeValue = False
End Sub
''上一题
Private Sub Command2_Click()
Command1.Enabled = True
Command2.Enabled = True
rstMain.MovePrevious
If rstMain.Bookmark = 1 Then
Command2.Enabled = False
Command1.Enabled = True
End If
Call RefreshSubject
End Sub
''交卷
Private Sub Command3_Click()
Dim rst As Recordset
If MsgBox("交卷后将不能在进行考试,你真的要交卷了吗?", vbQuestion + vbYesNo) = vbYes Then
''整理进行交卷动作
Set rst = New Recordset
rst.LockType = adLockBatchOptimistic
rst.CursorLocation = adUseClient
rst.CursorType = adOpenStatic
Set rst.ActiveConnection = pCN
rst.Source = "select * from 考生 where 准考证号='" & pudtStudent.准考证号 & "'"
rst.Open
rst![考生状态] = "已交卷"
rst.UpdateBatch
Unload Me
End If
End
End Sub
Private Sub Command4_Click()
frmClient.Show 1
End Sub
Private Sub Form_Load()
frmAnswer.Height = 0
Command2.Enabled = False
Set rstMain = New Recordset
rstMain.ActiveConnection = pCN
rstMain.Source = "select * from 题库主表 where 题目套号=" & pintSetNumber
rstMain.LockType = adLockBatchOptimistic
rstMain.CursorLocation = adUseClient
rstMain.CursorType = adOpenStatic
rstMain.Open
Call RefreshSubject
End Sub
''设置答案信息
Private Sub SetDetail()
Set rstDetail = Nothing
Set rstDetail = New Recordset
rstDetail.ActiveConnection = pCN
rstDetail.Source = "select * from 题目明细 where 题目编号='" & rstMain![题目编号] & "'"
rstDetail.LockType = adLockPessimistic
rstDetail.CursorLocation = adUseClient
rstDetail.CursorType = adOpenStatic
rstDetail.Open
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set rstMain = Nothing
Set rstDetail = Nothing
End Sub
Private Sub lblAnswer_Click(Index As Integer)
Call chkAnswer_Click(Index)
End Sub
Private Sub Timer1_Timer()
If frmAnswer.Height < 6945 Then
frmAnswer.Height = frmAnswer.Height + 100
End If
End Sub
''答案显示项目之间的距离
Private Const mcsinSpace As Single = 200
Private mintCurrentSubject As Integer ''当前的试题
Private rstMain As Recordset
Private rstDetail As Recordset
Private isProgChangeValue As Boolean
Private Sub chkAnswer_Click(Index As Integer)
Dim i As Integer
Dim strAnswer As String
Static isBusy As Boolean
Dim rst As Recordset
If isProgChangeValue Then GoTo Proc_Exit
If Not isBusy Then
isBusy = True
If Not rstMain![题目类型] Then
For i = 0 To chkAnswer.UBound
If i <> Index Then
chkAnswer(i).Value = 0
Else
chkAnswer(i).Value = 1
strAnswer = chkAnswer(i).Caption
End If
Next i
Else
For i = 0 To chkAnswer.UBound
If chkAnswer(i).Value = 1 Then
strAnswer = strAnswer & chkAnswer(i).Caption
End If
Next i
End If
Set rst = New Recordset
rst.ActiveConnection = pCN
rst.Source = "select * from 考生答案 where 准考证号='" & pudtStudent.准考证号 & "' and 题目编号='" & rstMain![题目编号] & "'"
rst.CursorLocation = adUseClient
rst.CursorType = adOpenStatic
rst.LockType = adLockBatchOptimistic
rst.Open
rst![考生答案] = strAnswer
rst.UpdateBatch
Set rst = Nothing
isBusy = False
End If
Proc_Exit:
End Sub
''下一题
Private Sub Command1_Click()
If Not rstMain.EOF Then
Command1.Enabled = True
Command2.Enabled = True
rstMain.MoveNext
If rstMain.RecordCount = rstMain.Bookmark Then
Command1.Enabled = False
Command2.Enabled = True
End If
Else
rstMain.MoveLast
End If
Call RefreshSubject
End Sub
Private Sub RefreshSubject()
Dim i As Integer
Dim rstAnswer As Recordset
lblDescription.Caption = rstMain![题目内容]
Frame1.Caption = IIf(rstMain![题目类型], "多选题", "单选题")
Me.Caption = "准考证号: " & pudtStudent.准考证号 & " 姓名: " & pudtStudent.考生姓名 & " 当前 第 " & rstMain.Bookmark & " 条"
''得到答题的数据
Call SetDetail
''首先卸载当前加载的对象
For i = 1 To lblAnswer.UBound
Unload lblAnswer(i)
Unload chkAnswer(i)
Next i
isProgChangeValue = True
chkAnswer(0).Value = 0
For i = 1 To rstDetail.RecordCount - 1
Load chkAnswer(i)
chkAnswer(i).Left = chkAnswer(0).Left
Load lblAnswer(i)
lblAnswer(i).Width = lblAnswer(0).Width
lblAnswer(i).Height = lblAnswer(0).Height
lblAnswer(i).Left = lblAnswer(0).Left
Next i
rstDetail.MoveFirst
chkAnswer(0).Caption = rstDetail![题目编码]
'lblAnswer(i).Left = 10
lblAnswer(0).Caption = rstDetail![备选答案]
rstDetail.MoveNext
For i = 1 To rstDetail.RecordCount - 1
chkAnswer(i).Caption = rstDetail![题目编码]
chkAnswer(i).Top = lblAnswer(i - 1).Top + lblAnswer(i - 1).Height + mcsinSpace
lblAnswer(i).Top = chkAnswer(i).Top
lblAnswer(i).Caption = rstDetail![备选答案]
lblAnswer(i).Visible = True
chkAnswer(i).Visible = True
rstDetail.MoveNext
Next i
''如果该题已经做过了,则加载该题的答案
Set rstAnswer = New Recordset
rstAnswer.CursorLocation = adUseClient
rstAnswer.LockType = adLockBatchOptimistic
rstAnswer.CursorType = adOpenStatic
rstAnswer.Source = "select * from 考生答案 where 准考证号='" & pudtStudent.准考证号 & "' and 题目编号='" & rstMain![题目编号] & "'"
rstAnswer.ActiveConnection = pCN
rstAnswer.Open
If Len(rstAnswer![考生答案] & "") > 0 Then
For i = 0 To chkAnswer.UBound
If InStr(1, UCase(rstAnswer![考生答案]), UCase(chkAnswer(i).Caption)) > 0 Then
chkAnswer(i).Value = 1
End If
Next i
End If
isProgChangeValue = False
End Sub
''上一题
Private Sub Command2_Click()
Command1.Enabled = True
Command2.Enabled = True
rstMain.MovePrevious
If rstMain.Bookmark = 1 Then
Command2.Enabled = False
Command1.Enabled = True
End If
Call RefreshSubject
End Sub
''交卷
Private Sub Command3_Click()
Dim rst As Recordset
If MsgBox("交卷后将不能在进行考试,你真的要交卷了吗?", vbQuestion + vbYesNo) = vbYes Then
''整理进行交卷动作
Set rst = New Recordset
rst.LockType = adLockBatchOptimistic
rst.CursorLocation = adUseClient
rst.CursorType = adOpenStatic
Set rst.ActiveConnection = pCN
rst.Source = "select * from 考生 where 准考证号='" & pudtStudent.准考证号 & "'"
rst.Open
rst![考生状态] = "已交卷"
rst.UpdateBatch
Unload Me
End If
End
End Sub
Private Sub Command4_Click()
frmClient.Show 1
End Sub
Private Sub Form_Load()
frmAnswer.Height = 0
Command2.Enabled = False
Set rstMain = New Recordset
rstMain.ActiveConnection = pCN
rstMain.Source = "select * from 题库主表 where 题目套号=" & pintSetNumber
rstMain.LockType = adLockBatchOptimistic
rstMain.CursorLocation = adUseClient
rstMain.CursorType = adOpenStatic
rstMain.Open
Call RefreshSubject
End Sub
''设置答案信息
Private Sub SetDetail()
Set rstDetail = Nothing
Set rstDetail = New Recordset
rstDetail.ActiveConnection = pCN
rstDetail.Source = "select * from 题目明细 where 题目编号='" & rstMain![题目编号] & "'"
rstDetail.LockType = adLockPessimistic
rstDetail.CursorLocation = adUseClient
rstDetail.CursorType = adOpenStatic
rstDetail.Open
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set rstMain = Nothing
Set rstDetail = Nothing
End Sub
Private Sub lblAnswer_Click(Index As Integer)
Call chkAnswer_Click(Index)
End Sub
Private Sub Timer1_Timer()
If frmAnswer.Height < 6945 Then
frmAnswer.Height = frmAnswer.Height + 100
End If
End Sub