home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Begin VB.Form Lists
- Caption = "Key List"
- ClientHeight = 3750
- ClientLeft = 2400
- ClientTop = 1650
- ClientWidth = 6330
- LinkTopic = "Form1"
- ScaleHeight = 3750
- ScaleWidth = 6330
- Begin VB.CommandButton DeleteButton
- Caption = "Delete"
- BeginProperty Font
- Name = "MS Sans Serif"
- Size = 9.75
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 495
- Left = 3000
- TabIndex = 2
- Top = 3000
- Width = 1215
- End
- Begin VB.CommandButton AddButton
- Caption = "Add New"
- BeginProperty Font
- Name = "MS Sans Serif"
- Size = 9.75
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 495
- Left = 4920
- TabIndex = 1
- Top = 3000
- Width = 1215
- End
- Begin VB.ListBox List1
- BeginProperty Font
- Name = "MS Sans Serif"
- Size = 9.75
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 3210
- Left = 120
- Sorted = -1 'True
- TabIndex = 0
- Top = 210
- Width = 2655
- End
- Begin VB.CommandButton CancelButton
- Caption = "Cancel"
- BeginProperty Font
- Name = "MS Sans Serif"
- Size = 9.75
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 495
- Left = 3000
- TabIndex = 4
- Top = 3000
- Width = 1215
- End
- Begin VB.CommandButton OKButton
- Caption = "OK"
- BeginProperty Font
- Name = "MS Sans Serif"
- Size = 9.75
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 495
- Left = 4920
- TabIndex = 3
- Top = 3000
- Width = 1215
- End
- Begin VB.TextBox Text1
- BeginProperty Font
- Name = "MS Sans Serif"
- Size = 9.75
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 360
- Left = 2880
- TabIndex = 5
- Top = 390
- Width = 1455
- End
- Begin VB.TextBox Text2
- BeginProperty Font
- Name = "MS Sans Serif"
- Size = 9.75
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 315
- Left = 4530
- Locked = -1 'True
- TabIndex = 8
- Top = 390
- Width = 1455
- End
- Begin VB.TextBox Text3
- BeginProperty Font
- Name = "MS Sans Serif"
- Size = 9.75
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 360
- Left = 2880
- Locked = -1 'True
- TabIndex = 7
- Top = 1050
- Width = 3135
- End
- Begin VB.TextBox Text4
- BeginProperty Font
- Name = "MS Sans Serif"
- Size = 9.75
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 675
- Left = 2880
- Locked = -1 'True
- MultiLine = -1 'True
- TabIndex = 6
- Top = 1815
- Width = 3135
- End
- Begin VB.Label Label4
- Caption = "Author"
- BeginProperty Font
- Name = "MS Sans Serif"
- Size = 9.75
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 225
- Left = 2880
- TabIndex = 12
- Top = 795
- Width = 1425
- End
- Begin VB.Label Label3
- Caption = "Published by"
- BeginProperty Font
- Name = "MS Sans Serif"
- Size = 9.75
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 270
- Left = 4515
- TabIndex = 11
- Top = 120
- Width = 1380
- End
- Begin VB.Label Label2
- Caption = "Title"
- BeginProperty Font
- Name = "MS Sans Serif"
- Size = 9.75
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 210
- Left = 2880
- TabIndex = 10
- Top = 1545
- Width = 1455
- End
- Begin VB.Label Label1
- Caption = "ISBN"
- BeginProperty Font
- Name = "MS Sans Serif"
- Size = 9.75
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 225
- Left = 2880
- TabIndex = 9
- Top = 120
- Width = 1440
- End
- Attribute VB_Name = "Lists"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- Dim DataArray(999, 3) As String
- Dim ArrayIndex As Integer
- Function BSearch(KeyField) As Integer
- Dim Lower, Upper, Middle
- Lower = 0
- Upper = List1.ListCount - 1
- While 1
- Middle = Fix((Lower + Upper) / 2)
- If Upper < Lower Then
- BSearch = -1
- Exit Function
- End If
- If StrComp(KeyField, List1.List(Middle)) > 0 Then
- Lower = Middle + 1
- Else
- If StrComp(KeyField, List1.List(Middle)) < 0 Then
- Upper = Middle - 1
- Else
- BSearch = Middle
- Exit Function
- End If
- End If
- End Function
- Sub ClearFields()
- Text1.Text = ""
- Text2.Text = ""
- Text2.Locked = False
- Text3.Text = ""
- Text3.Locked = False
- Text4.Text = ""
- Text4.Locked = False
- DeleteButton.Visible = False
- AddButton.Visible = False
- OKButton.Visible = True
- CancelButton.Visible = True
- End Sub
- Sub ShowButtons()
- OKButton.Visible = False
- CancelButton.Visible = False
- AddButton.Visible = True
- DeleteButton.Visible = True
- Text2.Locked = True
- Text3.Locked = True
- Text4.Locked = True
- End Sub
- Private Sub AddButton_Click()
- ClearFields
- End Sub
- Private Sub CancelButton_Click()
- ShowButtons
- List1_Click
- End Sub
- Private Sub DeleteButton_Click()
- If List1.ListIndex < 0 Then
- MsgBox "No item selected in the list"
- List1.RemoveItem List1.ListIndex
- End If
- End Sub
- Private Sub Form_Load()
- List1.Clear
- End Sub
- Private Sub List1_Click()
- If List1.ListIndex < 0 Then
- Text1.Text = ""
- Text2.Text = ""
- Text3.Text = ""
- Text4.Text = ""
- Exit Sub
- End If
- ItemIndex = List1.ItemData(List1.ListIndex)
- Text1.Text = List1.List(List1.ListIndex)
- Text2.Text = DataArray(ItemIndex, 1)
- Text3.Text = DataArray(ItemIndex, 2)
- Text4.Text = DataArray(ItemIndex, 3)
- End Sub
- Private Sub OKButton_Click()
- Key = Trim(Text1.Text)
- If Key = "" Then
- MsgBox "Key field must be non-mepty"
- Exit Sub
- End If
- position = BSearch(Trim(Text1.Text))
- If position >= 0 Then
- reply = MsgBox("Key exists. Replace existing record?", vbYesNo)
- If reply = vbYes Then
- List1.RemoveItem position
- Else
- Text1.SetFocus
- Exit Sub
- End If
- End If
- ArrayIndex = ArrayIndex + 1
- List1.AddItem Key
- List1.ItemData(List1.NewIndex) = ArrayIndex
- DataArray(ArrayIndex, 1) = Text2.Text
- DataArray(ArrayIndex, 2) = Text3.Text
- DataArray(ArrayIndex, 3) = Text4.Text
- List1.ListIndex = List1.NewIndex
- ShowButtons
- End Sub
- Private Sub Text1_Change()
- position = BSearch(Trim$(Text1.Text))
- If position >= 0 Then
- List1.ListIndex = position
- List1_Click
- Text2.Text = ""
- Text3.Text = ""
- Text4.Text = ""
- End If
- End Sub
-