📄 frmanswer.frm
字号:
VERSION 5.00
Begin VB.Form answer
BackColor = &H00FF8080&
Caption = "问答题管理"
ClientHeight = 5775
ClientLeft = 60
ClientTop = 450
ClientWidth = 9540
LinkTopic = "Form1"
ScaleHeight = 5775
ScaleWidth = 9540
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox Txtanswer
Height = 2055
Left = 240
TabIndex = 15
Text = "Text1"
Top = 2400
Width = 9015
End
Begin VB.CommandButton cmdmove
Height = 255
Index = 3
Left = 6000
Picture = "frmanswer.frx":0000
Style = 1 'Graphical
TabIndex = 11
Top = 5040
Width = 255
End
Begin VB.CommandButton cmdmove
Height = 255
Index = 2
Left = 5760
Picture = "frmanswer.frx":0482
Style = 1 'Graphical
TabIndex = 10
Top = 5040
Width = 255
End
Begin VB.CommandButton cmdmove
Height = 255
Index = 1
Left = 2640
Picture = "frmanswer.frx":0948
Style = 1 'Graphical
TabIndex = 9
Top = 5040
Width = 255
End
Begin VB.CommandButton cmdmove
Height = 255
Index = 0
Left = 2400
Picture = "frmanswer.frx":0E0E
Style = 1 'Graphical
TabIndex = 8
Top = 5040
Width = 255
End
Begin VB.PictureBox Picnavigation
BackColor = &H80000009&
Height = 255
Left = 2880
ScaleHeight = 195
ScaleWidth = 2835
TabIndex = 6
Top = 5040
Width = 2895
Begin VB.TextBox txtnews
Height = 390
Left = 0
TabIndex = 7
Text = "Text7"
Top = 0
Width = 2895
End
End
Begin VB.CommandButton cmdexit
Caption = "退出"
Height = 375
Left = 5280
TabIndex = 5
Top = 4560
Width = 975
End
Begin VB.CommandButton cmdsave
Caption = "保存"
Height = 375
Left = 4320
TabIndex = 4
Top = 4560
Width = 975
End
Begin VB.CommandButton cmddelete
Caption = "删除"
Height = 375
Left = 3360
TabIndex = 3
Top = 4560
Width = 975
End
Begin VB.CommandButton cmdadd
Caption = "添加"
Height = 375
Left = 2400
TabIndex = 2
Top = 4560
Width = 975
End
Begin VB.TextBox txtpoint
BackColor = &H8000000E&
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 8520
TabIndex = 1
Text = "Text2"
Top = 1800
Width = 735
End
Begin VB.TextBox txtquestion
Height = 1095
Left = 240
TabIndex = 0
Text = "Text1"
Top = 480
Width = 9015
End
Begin VB.Label Label3
Alignment = 2 'Center
BackColor = &H8000000A&
BackStyle = 0 'Transparent
Caption = "参考分数"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 7560
TabIndex = 14
Top = 1920
Width = 975
End
Begin VB.Label Label2
BackColor = &H8000000A&
BackStyle = 0 'Transparent
Caption = "参考答案"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 240
TabIndex = 13
Top = 1920
Width = 975
End
Begin VB.Label Label1
BackColor = &H00C0C0FF&
BackStyle = 0 'Transparent
Caption = "题干内容"
BeginProperty Font
Name = "宋体"
Size = 14.25
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FF0000&
Height = 255
Left = 240
TabIndex = 12
Top = 120
Width = 1215
End
End
Attribute VB_Name = "answer"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim isadding As Boolean
Dim objanswer As Recordset
Dim objCn As Connection
Private Sub cmdadd_Click()
txtnews = "添加新记录"
txtquestion = ""
txtanswer = ""
txtpoint = "1"
isadding = True
txtquestion.SetFocus
End Sub
Private Sub cmddelete_Click()
'根据是否处于添加记录状态执行不同的操作
If isadding Then
'退出添加记录状态,显示当前记录
isadding = False
If objanswer.RecordCount <= 0 Then
txtnews = "记录:无"
Else
show_data
End If
Else
If objanswer.RecordCount > 0 Then
If MsgBox("是否删除记录?", vbYesNo + vbQuestion, "阅卷教师信息管理") = vbYes Then
'执行删除当前记录操作
objanswer.Delete
'显示下一条记录
cmdmove(2).Value = True
Else
'显示当前记录数据
show_data
'显示当前记录和记录总数
End If
End If
End If
End Sub
Private Sub cmdexit_Click()
Unload Me
End Sub
Private Sub cmdmove_Click(Index As Integer)
With objanswer
Select Case Index
Case 0
If .RecordCount > 0 And Not .BOF Then .MoveFirst
Case 1
If .RecordCount > 0 And Not .BOF Then
.MovePrevious
If .BOF Then .MoveFirst
End If
Case 2
If .RecordCount > 0 And Not .EOF Then
.MoveNext
If .EOF Then .MoveLast
End If
Case 3
If .RecordCount > 0 And Not .EOF Then .MoveLast
End Select
show_data
End With
If isadding Then isadding = False
End Sub
Private Sub cmdsave_Click()
Dim objcopy As New Recordset
'在当前表中无数据并且不是添加记录时,不执行保存操作
If Not isadding And objanswer.RecordCount < 1 Then Exit Sub
If Trim(txtquestion) = "" Then
MsgBox "题干不能为空!", vbCritical, "问答题管理"
txtquestion.SetFocus
txtquestion = ""
ElseIf Not txtpoint Like "[1-9]" Then
MsgBox "参考分数不符合要求!", vbCritical, "问答题管理"
txtpoint.SetFocus
txtpoint.SelStart = 0: txtpoint.SelLength = Len(txtpoint)
'如何设置四个题干不能为空呢?
Else
Set objcopy = objanswer.Clone
With objcopy
If .RecordCount > 0 Then
'检验题干是否重复
.MoveFirst
.Find "题干='" & Trim(txtquestion) & "'"
If (isadding And Not .EOF) Or (Not isadding And Not .EOF And .AbsolutePosition <> objanswer.AbsolutePosition) Then
MsgBox "试题重复,请修改!", vbCritical, "问答题管理"
txtquestion.SetFocus
txtquestion.SelStart = 0
txtquestion.SelLength = Len(txtquestion)
Exit Sub
End If
If isadding Then objanswer.AddNew
Else
'保存记录
If isadding Then objanswer.AddNew
End If
objanswer.Fields("题干") = Trim(txtquestion)
objanswer.Fields("分数") = Trim(txtpoint)
objanswer.Fields("答案") = Trim(txtanswer)
objanswer.Update
MsgBox "数据保存成功", vbInformation, "问答题管理"
isadding = False
'显示当前记录编号和记录总数
txtnews = "记录:" & objanswer.AbsolutePosition & "/" & objanswer.RecordCount
End With
End If
End Sub
Private Sub Form_Load()
'建立数据库连接
Set objCn = New Connection '定义并实例化连接对象
With objCn '建立连接
.Provider = "SQLOLEDB"
.ConnectionString = "user id=sa;data source=(local);" & _
"initial catalog=自测考试"
.Open
End With
'获取填空题记录
Set objanswer = New Recordset
With objanswer
Set .ActiveConnection = objCn
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockOptimistic
.Open "select * from 问答题"
End With
cmdmove(0).Value = True
End Sub
Private Sub show_data()
With objanswer
If .RecordCount < 1 Then
txtnews = "记录:无" '显示记录提示信息
txtquestion = ""
txtpoint = ""
txtanswer = ""
Else
'显示当前记录数据
txtquestion = .Fields("题干")
txtpoint = .Fields("分数")
txtanswer = .Fields("答案")
'显示当前记录编号和记录总数
txtnews = "记录" & .AbsolutePosition & "/" & .RecordCount
End If
End With
End Sub
Private Sub Form_Unload(Cancel As Integer)
objCn.Close
Set objCn = Nothing
Set objanswer = Nothing
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -