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

📄 frmlinea.frm

📁 Visual Basic 6 大学教程的代码
💻 FRM
字号:
VERSION 5.00
Begin VB.Form frmLinear 
   Caption         =   "Fig. 7.8: Linear Search"
   ClientHeight    =   4500
   ClientLeft      =   2460
   ClientTop       =   345
   ClientWidth     =   4710
   BeginProperty Font 
      Name            =   "MS Sans Serif"
      Size            =   8.25
      Charset         =   0
      Weight          =   700
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   ForeColor       =   &H80000008&
   LinkTopic       =   "Form1"
   PaletteMode     =   1  'UseZOrder
   ScaleHeight     =   4500
   ScaleWidth      =   4710
   Begin VB.ListBox lstData 
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   1260
      Left            =   240
      TabIndex        =   4
      Top             =   1440
      Width           =   4215
   End
   Begin VB.CommandButton cmdExit 
      BackColor       =   &H80000005&
      Caption         =   "Exit"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   735
      Left            =   3210
      TabIndex        =   3
      Top             =   3585
      Width           =   1215
   End
   Begin VB.CommandButton cmdSearch 
      BackColor       =   &H80000005&
      Caption         =   "Search"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   735
      Left            =   240
      TabIndex        =   2
      Top             =   3600
      Width           =   1335
   End
   Begin VB.TextBox txtKey 
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   420
      Left            =   3480
      TabIndex        =   1
      Top             =   120
      Width           =   975
   End
   Begin VB.Label lblInstruction 
      Caption         =   "Click on list box to generate new data:"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   615
      Left            =   240
      TabIndex        =   6
      Top             =   705
      Width           =   4215
   End
   Begin VB.Label lblResult 
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   240
      TabIndex        =   5
      Top             =   2925
      Width           =   4215
   End
   Begin VB.Label lblKey 
      Caption         =   "Enter integer search key:"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   195
      TabIndex        =   0
      Top             =   120
      Width           =   3135
   End
End
Attribute VB_Name = "frmLinear"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' Fig. 7.8
' Demonstrating a linear search
Option Explicit
Option Base 1
Dim mArray(10) As Integer

Private Sub cmdSearch_Click()
   Dim searchKey As Integer   ' Value to search for
   Dim element As Integer     ' Index of Value

   lblResult.Caption = ""
   searchKey = txtKey.Text

   ' Call LinearSearch and pass array and key
   element = LinearSearch(mArray(), searchKey)

   If element <> -1 Then
      lblResult.Caption = "Value was found."
   Else
      lblResult.Caption = "Value was not found."
   End If

End Sub

Private Sub Form_Load()
   Call lstData_Click
End Sub

Private Sub lstData_Click()
   Dim x As Integer

   Call Randomize
   Call lstData.Clear
   lblResult.Caption = ""

   ' Generate some random data
   For x = LBound(mArray) To UBound(mArray)
      mArray(x) = 1 + Int(10000 * Rnd())
      Call lstData.AddItem(mArray(x))
   Next x

End Sub

Private Sub cmdExit_Click()
   End
End Sub

⌨️ 快捷键说明

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