?? frmprofill.frm
字號:
VERSION 5.00
Begin VB.Form ProgramFilling
BorderStyle = 1 'Fixed Single
Caption = "程序填空題題庫管理"
ClientHeight = 6150
ClientLeft = 45
ClientTop = 330
ClientWidth = 11025
LinkTopic = "Form1"
MaxButton = 0 'False
MDIChild = -1 'True
MinButton = 0 'False
ScaleHeight = 6150
ScaleWidth = 11025
Begin VB.Frame Frame1
Caption = "參考答案"
Height = 1785
Left = 6060
TabIndex = 20
Top = 330
Width = 4470
Begin VB.TextBox txtA
Height = 270
Left = 690
MaxLength = 50
TabIndex = 1
Top = 270
Width = 3375
End
Begin VB.TextBox txtB
Height = 270
Left = 690
MaxLength = 50
TabIndex = 2
Top = 645
Width = 3375
End
Begin VB.TextBox txtC
Height = 270
Left = 690
MaxLength = 50
TabIndex = 3
Top = 990
Width = 3375
End
Begin VB.TextBox txtD
Height = 270
Left = 690
MaxLength = 50
TabIndex = 4
Top = 1350
Width = 3375
End
Begin VB.Label Label2
AutoSize = -1 'True
Caption = "空1"
Height = 180
Left = 345
TabIndex = 24
Top = 315
Width = 270
End
Begin VB.Label Label4
AutoSize = -1 'True
Caption = "空3"
Height = 180
Left = 360
TabIndex = 23
Top = 1020
Width = 270
End
Begin VB.Label Label3
AutoSize = -1 'True
Caption = "空2"
Height = 180
Left = 345
TabIndex = 22
Top = 675
Width = 270
End
Begin VB.Label Label5
AutoSize = -1 'True
Caption = "空4"
Height = 180
Left = 360
TabIndex = 21
Top = 1395
Width = 270
End
End
Begin VB.TextBox txtPoint
Height = 270
Left = 6930
MaxLength = 1
TabIndex = 5
Text = "2"
Top = 2250
Width = 630
End
Begin VB.TextBox txtParse
Height = 2160
Left = 6060
MaxLength = 300
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 6
Top = 2910
Width = 4470
End
Begin VB.TextBox txtQuestion
Height = 4545
Left = 495
MaxLength = 800
MultiLine = -1 'True
ScrollBars = 3 'Both
TabIndex = 0
Top = 525
Width = 5055
End
Begin VB.CommandButton cmdSave
Caption = "保存"
Height = 300
Left = 5460
TabIndex = 9
Top = 5400
Width = 735
End
Begin VB.CommandButton cmdExit
Cancel = -1 'True
Caption = "退出"
Height = 300
Left = 6210
TabIndex = 10
Top = 5400
Width = 735
End
Begin VB.CommandButton cmdDelete
Caption = "刪除"
Height = 300
Left = 4710
TabIndex = 8
Top = 5400
Width = 735
End
Begin VB.CommandButton cmdAdd
Caption = "添加"
Height = 300
Left = 3975
TabIndex = 7
Top = 5400
Width = 735
End
Begin VB.PictureBox picNavigation
AutoSize = -1 'True
BorderStyle = 0 'None
Height = 350
Left = 4380
ScaleHeight = 345
ScaleWidth = 2415
TabIndex = 15
Top = 5715
Width = 2410
Begin VB.CommandButton cmdMove
Height = 270
Index = 1
Left = 270
Picture = "frmProFill.frx":0000
Style = 1 'Graphical
TabIndex = 12
Top = 0
Width = 300
End
Begin VB.CommandButton cmdMove
Height = 270
Index = 0
Left = -15
Picture = "frmProFill.frx":0044
Style = 1 'Graphical
TabIndex = 11
Top = 0
Width = 300
End
Begin VB.CommandButton cmdMove
Height = 270
Index = 3
Left = 2010
Picture = "frmProFill.frx":0091
Style = 1 'Graphical
TabIndex = 14
Top = -15
Width = 300
End
Begin VB.CommandButton cmdMove
Height = 270
Index = 2
Left = 1725
Picture = "frmProFill.frx":00DD
Style = 1 'Graphical
TabIndex = 13
Top = -15
Width = 300
End
Begin VB.TextBox txtNews
Height = 270
Left = 555
Locked = -1 'True
TabIndex = 16
TabStop = 0 'False
Top = 0
Width = 1185
End
End
Begin VB.Label Label8
AutoSize = -1 'True
Caption = "試題解析"
Height = 180
Left = 6060
TabIndex = 19
Top = 2640
Width = 720
End
Begin VB.Label Label7
AutoSize = -1 'True
Caption = "參考分數"
Height = 180
Left = 6060
TabIndex = 18
Top = 2295
Width = 720
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "題干內容"
Height = 180
Left = 540
TabIndex = 17
Top = 330
Width = 720
End
End
Attribute VB_Name = "ProgramFilling"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim isAdding As Boolean '定義操作狀態標志
Dim objBlank As Recordset '用于保存程序填空題數據表記錄
Dim objCn As Connection '用于建立數據庫聯接
Private Sub cmdExit_Click()
Unload Me '關閉程序填空題管理窗體
End Sub
Private Sub Form_Load()
'建立數據庫聯接
Set objCn = New Connection '實例化聯接對象
With objCn '建立數據庫聯接
.Provider = "SQLOLEDB"
.ConnectionString = "User ID=sa;PWD=123;Data Source=(local);" & _
"Initial Catalog=自測考試"
.Open
End With
'獲取程序填空題記錄
Set objBlank = New Recordset '實例化objBlank對象
With objBlank
Set .ActiveConnection = objCn
.CursorLocation = adUseClient '指定使用客戶端游標
.CursorType = adOpenStatic '指定使用靜態游標
.LockType = adLockOptimistic
.Open "SELECT * FROM 程序填空" '獲取程序填空題數據
End With
cmdMove(0).Value = True '觸發按鈕單擊事件,顯示第一個記錄
End Sub
Private Sub cmdMove_Click(Index As Integer)
With objBlank
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 cmdAdd_Click()
txtNews = "添加新記錄"
txtQuestion = ""
txtA = "": txtB = "": txtC = ""
txtD = "": txtPoint = "2": txtParse = ""
isAdding = True
txtQuestion.SetFocus
End Sub
Private Sub cmdDelete_Click()
'根據是否處于添加記錄狀態執行不同的操作
If isAdding Then
'退出添加記錄狀態,顯示當前記錄
isAdding = False
If objBlank.RecordCount <= 0 Then
txtNews = "記錄:無" '顯示無記錄提示
Else
Show_Data '顯示當前記錄數據
End If
Else
If objBlank.RecordCount > 0 Then
If MsgBox("是否刪除當前記錄?", vbYesNo + vbQuestion, _
"程序填空題管理") = vbYes Then
objBlank.Delete '執行刪除當前記錄操作
cmdMove(2).Value = True '顯示下一記錄數據
Else
Show_Data '顯示當前記錄數據
End If
End If
End If
End Sub
Private Sub cmdSave_Click()
Dim objCopy As New Recordset
'在當前表中無數據和不是添加記錄時,不執行保存操作
If Not isAdding And objBlank.RecordCount < 1 Then Exit Sub
If Trim(txtQuestion) = "" Then
MsgBox "題干不能為空!", vbCritical, "程序填空題管理"
txtQuestion.SetFocus
txtQuestion = ""
ElseIf Trim(txtA) = "" Then
MsgBox "請輸入空1參考答案!", vbCritical, "程序填空題管理"
txtA.SetFocus
txtA = ""
ElseIf Trim(txtB) = "" Then
MsgBox "請輸入空2參考答案!", vbCritical, "程序填空題管理"
txtB.SetFocus
txtB = ""
ElseIf Not txtPoint Like "[1-9]" Then
MsgBox "請輸入有效的分數!", vbCritical, "程序填空題管理"
txtPoint.SetFocus
txtPoint.SelStart = 0
txtPoint.SelLength = Len(txtPoint)
Else
Set objCopy = objBlank.Clone
With objCopy
If .RecordCount > 0 Then
'檢查題干是否重復
.MoveFirst
.Find "題干='" & Trim(txtQuestion) & "'"
If (isAdding And Not .EOF) Or _
(Not isAdding And Not .EOF And _
.AbsolutePosition <> objBlank.AbsolutePosition) Then
MsgBox "試題重復,請修改!", vbCritical, "程序填空題管理"
txtQuestion.SetFocus
txtQuestion.SelStart = 0
txtQuestion.SelLength = Len(txtQuestion)
Exit Sub
End If
End If
If isAdding Then objBlank.AddNew '添加新記錄
objBlank.Fields("題干") = Trim(txtQuestion)
objBlank.Fields("空a") = Trim(txtA)
objBlank.Fields("空b") = Trim(txtB)
objBlank.Fields("空c") = Trim(txtC)
objBlank.Fields("空d") = Trim(txtD)
objBlank.Fields("分數") = Trim(txtPoint)
objBlank.Fields("解析") = Trim(txtParse)
objBlank.Update
MsgBox "數據保存成功!", vbInformation, "程序填空題管理"
isAdding = False
'顯示當前記錄編號和記錄總數
txtNews = "記錄:" & objBlank.AbsolutePosition & "/" & objBlank.RecordCount
End With
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
objCn.Close '關閉數據聯接
Set objCn = Nothing '釋放數據庫聯接
Set objBlank = Nothing '釋放記錄集對象
End Sub
'限制分數輸入
Private Sub txtPoint_KeyPress(KeyAscii As Integer)
If Not (Chr(KeyAscii) Like "[1-9]" Or KeyAscii = vbKeyBack) Then
KeyAscii = 0 '輸入不是數字或退格鍵,取消輸入
End If
End Sub
Private Sub Show_Data()
Dim i%
With objBlank
If .RecordCount < 1 Then
txtNews = "記錄:無" '顯示無記錄提示
'清除顯示數據
txtQuestion = "": txtPoint = "": txtParse = ""
txtA = "": txtB = "": txtC = "": txtD = ""
Else
'顯示當前記錄數據
txtQuestion = .Fields("題干"): txtPoint = .Fields("分數")
txtParse = .Fields("解析"): txtA = .Fields("空a")
txtB = .Fields("空b"): txtC = .Fields("空c"): txtD = .Fields("空d")
'顯示當前記錄編號和記錄總數
txtNews = "記錄:" & .AbsolutePosition & "/" & .RecordCount
End If
End With
End Sub
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -