?? frmoldtests.frm
字號:
VERSION 5.00
Begin VB.Form OldTests
BorderStyle = 1 'Fixed Single
Caption = "歷屆試題管理"
ClientHeight = 1905
ClientLeft = 45
ClientTop = 330
ClientWidth = 4455
LinkTopic = "Form1"
MaxButton = 0 'False
MDIChild = -1 'True
MinButton = 0 'False
ScaleHeight = 1905
ScaleWidth = 4455
Begin VB.TextBox txtNum
Height = 270
Left = 1635
Locked = -1 'True
MaxLength = 8
TabIndex = 9
Top = 195
Width = 1995
End
Begin VB.TextBox txtName
Height = 270
Left = 1620
Locked = -1 'True
MaxLength = 20
TabIndex = 8
Top = 607
Width = 1995
End
Begin VB.PictureBox picNavigation
AutoSize = -1 'True
BorderStyle = 0 'None
Height = 360
Left = 885
ScaleHeight = 360
ScaleWidth = 2685
TabIndex = 6
Top = 1312
Width = 2685
Begin VB.TextBox txtNews
Height = 300
Left = 690
Locked = -1 'True
TabIndex = 7
TabStop = 0 'False
Top = 15
Width = 1275
End
Begin VB.CommandButton cmdMove
Height = 300
Index = 2
Left = 1950
Picture = "frmOldTests.frx":0000
Style = 1 'Graphical
TabIndex = 4
Top = 15
Width = 345
End
Begin VB.CommandButton cmdMove
Height = 300
Index = 3
Left = 2280
Picture = "frmOldTests.frx":0044
Style = 1 'Graphical
TabIndex = 5
Top = 15
Width = 345
End
Begin VB.CommandButton cmdMove
Height = 300
Index = 0
Left = 30
Picture = "frmOldTests.frx":0093
Style = 1 'Graphical
TabIndex = 2
Top = 15
Width = 345
End
Begin VB.CommandButton cmdMove
Height = 300
Index = 1
Left = 360
Picture = "frmOldTests.frx":00E0
Style = 1 'Graphical
TabIndex = 3
Top = 15
Width = 345
End
End
Begin VB.CommandButton cmdDelete
Caption = "刪除"
Height = 300
Left = 1440
TabIndex = 0
Top = 997
Width = 735
End
Begin VB.CommandButton cmdExit
Cancel = -1 'True
Caption = "退出"
Height = 315
Left = 2280
TabIndex = 1
Top = 990
Width = 735
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "試題編號"
Height = 180
Left = 825
TabIndex = 11
Top = 240
Width = 720
End
Begin VB.Label Label2
AutoSize = -1 'True
Caption = "試題名稱"
Height = 180
Left = 825
TabIndex = 10
Top = 652
Width = 720
End
End
Attribute VB_Name = "OldTests"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim objOldTests 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 objOldTests = New Recordset '實例化objOldTests對象
With objOldTests
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 objOldTests
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
If .RecordCount < 1 Then
txtNews = "記錄:無" '顯示無記錄提示
txtNum = ""
txtName = ""
Else
'顯示當前記錄數據
txtNum = .Fields("編號")
txtName = .Fields("表名")
'顯示當前記錄編號和記錄總數
txtNews = "記錄:" & .AbsolutePosition & "/" & .RecordCount
End If
End With
End Sub
Private Sub cmdDelete_Click()
Dim strSQL$
'請求確認執行刪除操作
If objOldTests.RecordCount > 0 Then
If MsgBox("是否刪除當前記錄?", vbYesNo + vbQuestion, "歷屆試題管理") = vbYes Then
'執行刪除當前記錄操作
strSQL = "DROP TABLE " & objOldTests.Fields("表名")
objOldTests.Delete
objCn.Execute strSQL
'顯示下一記錄數據
cmdMove(2).Value = True
End If
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
objCn.Close '關閉數據聯接
Set objCn = Nothing '釋放數據庫聯接
Set objOldTests = Nothing '釋放記錄集對象
End Sub
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -