⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.frm

📁 Visual Basic 6 大学教程的代码
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Demonstrating the Dictionary Object"
   ClientHeight    =   2970
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4935
   LinkTopic       =   "Form1"
   ScaleHeight     =   2970
   ScaleWidth      =   4935
   StartUpPosition =   3  'Windows Default
   Begin VB.ListBox lstItems 
      Height          =   1425
      ItemData        =   "Form1.frx":0000
      Left            =   2520
      List            =   "Form1.frx":0002
      TabIndex        =   9
      Top             =   1560
      Width           =   2415
   End
   Begin VB.CommandButton cmdRemoveAll 
      Caption         =   "Remove all key/value pairs"
      Height          =   285
      Left            =   2520
      TabIndex        =   8
      Top             =   840
      Width           =   2415
   End
   Begin VB.CommandButton cmdRemove 
      Caption         =   "Remove key/value pair"
      Height          =   285
      Left            =   2520
      TabIndex        =   7
      Top             =   480
      Width           =   2415
   End
   Begin VB.CommandButton cmdExists 
      Caption         =   "Is key in Dictionary already?"
      Height          =   285
      Left            =   0
      TabIndex        =   6
      Top             =   840
      Width           =   2415
   End
   Begin VB.CommandButton cmdAdd 
      Caption         =   "Add key/value pair"
      Height          =   285
      Left            =   0
      TabIndex        =   5
      Top             =   480
      Width           =   2415
   End
   Begin VB.TextBox txtValue 
      Height          =   285
      Left            =   3240
      TabIndex        =   4
      Top             =   120
      Width           =   1215
   End
   Begin VB.TextBox txtKey 
      Height          =   285
      Left            =   840
      TabIndex        =   1
      Top             =   120
      Width           =   1215
   End
   Begin VB.ListBox lstKeys 
      Height          =   1425
      ItemData        =   "Form1.frx":0004
      Left            =   0
      List            =   "Form1.frx":0006
      TabIndex        =   0
      Top             =   1560
      Width           =   2415
   End
   Begin VB.Label lblItems 
      Caption         =   "Items"
      Height          =   255
      Left            =   2520
      TabIndex        =   11
      Top             =   1320
      Width           =   1215
   End
   Begin VB.Label lblKeys 
      Caption         =   "Keys"
      Height          =   255
      Left            =   0
      TabIndex        =   10
      Top             =   1320
      Width           =   1215
   End
   Begin VB.Label lblValue 
      Alignment       =   1  'Right Justify
      Caption         =   "Value"
      Height          =   255
      Left            =   2520
      TabIndex        =   3
      Top             =   135
      Width           =   615
   End
   Begin VB.Label lblKey 
      Alignment       =   1  'Right Justify
      Caption         =   "Key"
      Height          =   255
      Left            =   120
      TabIndex        =   2
      Top             =   135
      Width           =   615
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' Fig. 21.18
' Demonstrating the Dictionary object
Option Explicit
Dim mMyDictionary As New Dictionary

Private Sub cmdAdd_Click()
   If mMyDictionary.Exists(txtKey.Text) Then
      mMyDictionary.Item(txtKey.Text) = txtValue.Text
   Else
      Call mMyDictionary.Add(txtKey.Text, txtValue.Text)
   End If
   
   Call ListKeys
   Call ListItems
End Sub

Private Sub cmdExists_Click()
   If mMyDictionary.Exists(txtKey.Text) Then
      Call MsgBox("Key '" + txtKey.Text + "' exists. Value is '" _
         + mMyDictionary.Item(txtKey.Text) + "'")
   Else
      Call MsgBox("Key '" + txtKey.Text + "' does not exist.")
   End If
End Sub

Private Sub cmdRemove_Click()
   On Error Resume Next
   Call mMyDictionary.Remove(txtKey.Text)
   Call ListKeys
   Call ListItems
End Sub

Private Sub cmdRemoveAll_Click()
   Call mMyDictionary.RemoveAll
   Call ListKeys
   Call ListItems
End Sub

Private Sub ListItems()
   Dim elements() As Variant, i As Integer
   
   Call lstItems.Clear
   elements = mMyDictionary.Items()
   
   For i = 0 To mMyDictionary.Count - 1
      Call lstItems.AddItem(elements(i))
   Next
End Sub

Private Sub ListKeys()
   Dim elements() As Variant, i As Integer
   
   Call lstKeys.Clear
   elements = mMyDictionary.Keys()
   
   For i = 0 To mMyDictionary.Count - 1
      Call lstKeys.AddItem(elements(i))
   Next
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -