📄 select4.frm
字号:
VERSION 5.00
Begin VB.Form Form1
BackColor = &H00C0C0C0&
Caption = "Chapter 3.4 Example"
ClientHeight = 3045
ClientLeft = 1740
ClientTop = 2490
ClientWidth = 6795
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
LinkTopic = "Form1"
PaletteMode = 1 'UseZOrder
ScaleHeight = 3045
ScaleWidth = 6795
Begin VB.TextBox txtStartYear
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 285
Left = 1620
TabIndex = 8
Top = 1770
Width = 855
End
Begin VB.CommandButton cmdLookup
Caption = "&Look Up"
Default = -1 'True
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 555
Left = 3750
TabIndex = 7
Top = 2400
Width = 1335
End
Begin VB.TextBox txtEndYear
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 285
Left = 3030
TabIndex = 3
Top = 1770
Width = 855
End
Begin VB.TextBox txtPartialTitle
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 315
Left = 1620
TabIndex = 2
Top = 1380
Width = 4635
End
Begin VB.CommandButton cmdClose
Caption = "&Close"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 555
Left = 5340
TabIndex = 1
Top = 2400
Width = 1335
End
Begin VB.ListBox lstTitles
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 1230
Left = 120
TabIndex = 0
Top = 90
Width = 6555
End
Begin VB.Label lblEndYear
AutoSize = -1 'True
BackColor = &H00C0C0C0&
Caption = "and"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 195
Left = 2610
TabIndex = 6
Top = 1830
Width = 270
End
Begin VB.Label lblStartYear
AutoSize = -1 'True
BackColor = &H00C0C0C0&
Caption = "Published between:"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 195
Left = 120
TabIndex = 5
Top = 1800
Width = 1395
End
Begin VB.Label lblPartialTitle
AutoSize = -1 'True
BackColor = &H00C0C0C0&
Caption = "Title includes text:"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 195
Left = 120
TabIndex = 4
Top = 1410
Width = 1275
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Const BIBLIO_PATH = "D:\Program Files\Microsoft Visual Studio\VB6\Biblio.MDB"
Private Sub cmdLookup_Click()
Dim dbfBiblio As Database, recSelect As Recordset
Dim strName As String, strSQL As String
Dim strTitleText As String, strStartYear As String, strEndYear As String
On Error GoTo LookupError
'Clear the list box
lstTitles.Clear
'Construct the search strings, using wildcards where appropriate.
'For example, if the txtPartialTitle field is blank, the
'* wildcard is substituted.
strTitleText = IIf(txtPartialTitle <> "", txtPartialTitle, "*")
strStartYear = IIf(IsNumeric(txtStartYear), txtStartYear, "1")
strEndYear = IIf(IsNumeric(txtEndYear), txtEndYear, "9999")
'Open the database
Set dbfBiblio = DBEngine.Workspaces(0).OpenDatabase(BIBLIO_PATH)
'Build the SQL statement, substituting our search strings, built above,
'in the appropriate locations.
strSQL = "SELECT [Title] FROM [Titles] " & _
"WHERE [Title] LIKE '*" & strTitleText & "*' " & _
"AND [Year Published] BETWEEN " & strStartYear & " AND " & strEndYear & _
" ORDER BY [Title]"
'Construct the SQL statement.
Set recSelect = dbfBiblio.OpenRecordset(strSQL, dbOpenSnapshot)
'If we get results, load the Title field of each record into the
'list box.
If recSelect.RecordCount > 0 Then
recSelect.MoveFirst
Do Until recSelect.EOF
lstTitles.AddItem recSelect![Title]
recSelect.MoveNext
Loop
End If
On Error GoTo 0
Exit Sub
LookupError:
MsgBox Err.Description, vbExclamation
Exit Sub
End Sub
Private Sub cmdClose_Click()
End
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -