?? frmanswer.frm
字號(hào):
VERSION 5.00
Begin VB.Form answer
BackColor = &H00FF8080&
Caption = "問(wèn)答題管理"
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 = "參考分?jǐn)?shù)"
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 = "題干內(nèi)容"
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()
'根據(jù)是否處于添加記錄狀態(tài)執(zhí)行不同的操作
If isadding Then
'退出添加記錄狀態(tài),顯示當(dāng)前記錄
isadding = False
If objanswer.RecordCount <= 0 Then
txtnews = "記錄:無(wú)"
Else
show_data
End If
Else
If objanswer.RecordCount > 0 Then
If MsgBox("是否刪除記錄?", vbYesNo + vbQuestion, "閱卷教師信息管理") = vbYes Then
'執(zhí)行刪除當(dāng)前記錄操作
objanswer.Delete
'顯示下一條記錄
cmdmove(2).Value = True
Else
'顯示當(dāng)前記錄數(shù)據(jù)
show_data
'顯示當(dāng)前記錄和記錄總數(shù)
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
'在當(dāng)前表中無(wú)數(shù)據(jù)并且不是添加記錄時(shí),不執(zhí)行保存操作
If Not isadding And objanswer.RecordCount < 1 Then Exit Sub
If Trim(txtquestion) = "" Then
MsgBox "題干不能為空!", vbCritical, "問(wèn)答題管理"
txtquestion.SetFocus
txtquestion = ""
ElseIf Not txtpoint Like "[1-9]" Then
MsgBox "參考分?jǐn)?shù)不符合要求!", vbCritical, "問(wèn)答題管理"
txtpoint.SetFocus
txtpoint.SelStart = 0: txtpoint.SelLength = Len(txtpoint)
'如何設(shè)置四個(gè)題干不能為空呢?
Else
Set objcopy = objanswer.Clone
With objcopy
If .RecordCount > 0 Then
'檢驗(yàn)題干是否重復(fù)
.MoveFirst
.Find "題干='" & Trim(txtquestion) & "'"
If (isadding And Not .EOF) Or (Not isadding And Not .EOF And .AbsolutePosition <> objanswer.AbsolutePosition) Then
MsgBox "試題重復(fù),請(qǐng)修改!", vbCritical, "問(wèn)答題管理"
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("分?jǐn)?shù)") = Trim(txtpoint)
objanswer.Fields("答案") = Trim(txtanswer)
objanswer.Update
MsgBox "數(shù)據(jù)保存成功", vbInformation, "問(wèn)答題管理"
isadding = False
'顯示當(dāng)前記錄編號(hào)和記錄總數(shù)
txtnews = "記錄:" & objanswer.AbsolutePosition & "/" & objanswer.RecordCount
End With
End If
End Sub
Private Sub Form_Load()
'建立數(shù)據(jù)庫(kù)連接
Set objCn = New Connection '定義并實(shí)例化連接對(duì)象
With objCn '建立連接
.Provider = "SQLOLEDB"
.ConnectionString = "user id=sa;data source=(local);" & _
"initial catalog=自測(cè)考試"
.Open
End With
'獲取填空題記錄
Set objanswer = New Recordset
With objanswer
Set .ActiveConnection = objCn
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockOptimistic
.Open "select * from 問(wèn)答題"
End With
cmdmove(0).Value = True
End Sub
Private Sub show_data()
With objanswer
If .RecordCount < 1 Then
txtnews = "記錄:無(wú)" '顯示記錄提示信息
txtquestion = ""
txtpoint = ""
txtanswer = ""
Else
'顯示當(dāng)前記錄數(shù)據(jù)
txtquestion = .Fields("題干")
txtpoint = .Fields("分?jǐn)?shù)")
txtanswer = .Fields("答案")
'顯示當(dāng)前記錄編號(hào)和記錄總數(shù)
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
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -