📄 frmfind.frm
字号:
VERSION 5.00
Begin VB.Form frmFind
BorderStyle = 3 'Fixed Dialog
Caption = "Find"
ClientHeight = 3015
ClientLeft = 2265
ClientTop = 4425
ClientWidth = 5850
Icon = "frmFind.frx":0000
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 3015
ScaleWidth = 5850
ShowInTaskbar = 0 'False
Begin VB.CommandButton CancelButton
Cancel = -1 'True
Caption = "Cancel"
Height = 375
Left = 4560
TabIndex = 1
Top = 600
Width = 1215
End
Begin VB.CommandButton OKButton
Caption = "Find"
Default = -1 'True
Height = 375
Left = 4560
TabIndex = 0
Top = 120
Width = 1215
End
Begin VB.TextBox FindText
Height = 285
Left = 2160
TabIndex = 2
Top = 840
Width = 2055
End
Begin VB.ComboBox FieldCombo
Height = 315
Left = 2160
Style = 2 'Dropdown List
TabIndex = 4
Top = 480
Width = 2055
End
Begin VB.ComboBox LayerCombo
Height = 315
Left = 1320
Style = 2 'Dropdown List
TabIndex = 5
Top = 120
Width = 2895
End
Begin VB.Frame Frame1
Caption = "Optional"
Height = 1695
Left = 120
TabIndex = 8
Top = 1200
Width = 4215
Begin VB.TextBox ZoomText
Height = 285
Left = 2040
TabIndex = 16
Text = "250"
Top = 1320
Width = 1455
End
Begin VB.CheckBox ZoomCheck
Caption = "Set Zoom to:"
Height = 255
Left = 760
TabIndex = 15
Top = 1340
Value = 1 'Checked
Width = 1335
End
Begin VB.TextBox RefineText
Height = 285
Left = 2040
TabIndex = 14
Top = 960
Width = 2055
End
Begin VB.ComboBox RefineFieldCombo
Height = 315
Left = 2040
Style = 2 'Dropdown List
TabIndex = 13
Top = 600
Width = 2055
End
Begin VB.ComboBox RefineLayerCombo
Height = 315
Left = 2040
Style = 2 'Dropdown List
TabIndex = 10
Top = 240
Width = 2055
End
Begin VB.Label Label7
Caption = "Miles"
Height = 255
Left = 3600
TabIndex = 17
Top = 1380
Width = 495
End
Begin VB.Label Label6
Caption = "with a Value of:"
Height = 255
Left = 860
TabIndex = 12
Top = 1005
Width = 1215
End
Begin VB.Label Label5
Caption = "and Field:"
Height = 255
Left = 1260
TabIndex = 11
Top = 660
Width = 735
End
Begin VB.Label Label4
Caption = "Refine Search with Layer:"
Height = 255
Left = 120
TabIndex = 9
Top = 270
Width = 1935
End
End
Begin VB.Label Label2
Caption = "for an Object whose Field:"
Height = 255
Left = 240
TabIndex = 7
Top = 525
Width = 2055
End
Begin VB.Label Label1
Caption = "has a Value of:"
Height = 255
Left = 1020
TabIndex = 6
Top = 870
Width = 1095
End
Begin VB.Label Label3
Caption = "Search Layer:"
Height = 255
Left = 240
TabIndex = 3
Top = 165
Width = 1095
End
End
Attribute VB_Name = "frmFind"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
' This sample application and corresponding sample code is provided
' for example purposes only. It has not undergone rigorous testing
' and as such should not be shipped as part of a final application
' without extensive testing on the part of the organization releasing
' the end-user product.
Private Sub CancelButton_Click()
Unload Me
End Sub
Private Sub ZoomCheck_Click()
If ZoomCheck.Value = vbChecked Then
ZoomText.Enabled = True
Else
ZoomText.Enabled = False
End If
End Sub
Private Sub Form_Load()
Dim lyr As Layer
' Add every layer to the search layer combobox
For Each lyr In fMainForm.Map1.Layers
LayerCombo.AddItem lyr.Name
Next
' In order to Find, we need to have a dataset to search. In
' this case, we want to search the data in the MapInfo table
' that makes up a map layer. So, we add each layer as a dataset.
' As a convention, we name each dataset with the name of the layer
' and then " dataset"
' Note: We don't need to add and remove all these datasets every time
' the find dialog is shown; it would be faster to only add them once
' and reuse them throughout the runtime of the program.
' We only use this approach because it is simplest.
For Each lyr In fMainForm.Map1.Layers
fMainForm.Map1.Datasets.Add miDataSetLayer, lyr, lyr.Name & " dataset"
Next
' Select the first layer in the search box. This will also call LayerCombo_Click,
' which will take care of filling all the other combo boxes
LayerCombo.ListIndex = 0
End Sub
Private Sub Form_Unload(Cancel As Integer)
' Before the form is closed, a little housekeeping: we need to remove
' all of the datasets that we added in Form_Load
Dim lyr As Layer
For Each lyr In fMainForm.Map1.Layers
fMainForm.Map1.Datasets.Remove lyr.Name & " dataset"
Next
End Sub
Private Sub OKButton_Click()
' Perform the search. This is performed by getting the Layer.Find object
' from the layer to be searched. This Find object has properties that
' identify the dataset and field to be searched, and the dataset, field,
' and layer to be used if a refining value is used. Then, the Find.Search
' method performs the search and returns a FindFeature object.
' The FindFeature object has all the properties of a normal feature object,
' plus a FindRC property. This FindRC result code contains information including
' if MapX found anything.
Dim FindObj As MapXLib.Find
Dim FoundFeature As FindFeature
If LayerCombo.ListIndex = -1 Or FieldCombo.ListIndex = -1 Then
Exit Sub
End If
' Get the Find Object from the layer to be searched, and set the dataset
' and field to be searched.
Set FindObj = fMainForm.Map1.Layers(LayerCombo.Text).Find
Set FindObj.FindDataset = fMainForm.Map1.Datasets(LayerCombo.Text & " dataset")
Set FindObj.FindField = FindObj.FindDataset.Fields(FieldCombo.Text)
If RefineLayerCombo.Text <> "(None)" And RefineLayerCombo.Text <> "" And RefineFieldCombo.ListIndex <> -1 Then
' The user wants to search with a refining value
Set FindObj.RefineLayer = fMainForm.Map1.Layers(RefineLayerCombo.Text)
Set FindObj.RefineDataset = fMainForm.Map1.Datasets(RefineLayerCombo.Text & " dataset")
Set FindObj.RefineField = FindObj.RefineDataset.Fields(RefineFieldCombo.Text)
' Perform the search
Set FoundFeature = FindObj.Search(FindText.Text, RefineText.Text)
Else
Set FindObj.RefineLayer = Nothing
Set FindObj.RefineDataset = Nothing
Set FindObj.RefineField = Nothing
' Perform the search without a refining value
Set FoundFeature = FindObj.Search(FindText.Text)
End If
If FoundFeature.FindRC Mod 10 = 1 Or FoundFeature.FindRC Mod 10 = 2 Then
' This means that either an exact match was found or a match
' was found with a substitution from the abbreviations file.
' Either way, just center the map over the object that we found
' AutoRedraw should be turned off, since the change to CenterX then
' change to CenterY can cause two individual redraws.
fMainForm.Map1.AutoRedraw = False
fMainForm.Map1.CenterX = FoundFeature.CenterX
fMainForm.Map1.CenterY = FoundFeature.CenterY
If ZoomCheck.Value = vbChecked Then
' Set the zoom to zoom in on whatever we found
Dim ZoomValue As Double
On Error GoTo NoZoom ' If the user enters non-numeric data in the text box,
' an error will be raised
ZoomValue = ZoomText.Text
fMainForm.Map1.Zoom = ZoomValue
End If
NoZoom:
fMainForm.Map1.AutoRedraw = True
Else
' Couldn't find anything; just display a diagnostic.
MsgBox "Exact Match Not Found; FindRC: " & FoundFeature.FindRC
End If
End Sub
Private Sub LayerCombo_Click()
' This subroutine may look complicated, but what it's doing is filling the
' Field combobox with every field in the current layer's dataset. Then, it
' fills the Refine Layer combobox with every layer except the one selected
' in the primary Layer combobox.
Dim oldField As String
Dim oldRefineLayer As String
' If the user selected a field, then changed the layer, we can try to
' keep the correct field selected
oldField = FieldCombo.Text
' Also, try to keep the correct refine layer selected
oldRefineLayer = RefineLayerCombo.Text
' First, we need to remove all of the current items in the Field combo
Dim i As Integer
For i = 0 To FieldCombo.ListCount - 1
FieldCombo.RemoveItem 0
Next
' And remove all of the Refine Layer entries
For i = 0 To RefineLayerCombo.ListCount - 1
RefineLayerCombo.RemoveItem 0
Next
' Then, add all the fields that are in the current layer's dataset
If LayerCombo.ListIndex <> -1 Then
' The layer combo contains the name of the layer that the user selected
' The dataset that corresponds to this layer is the layer name plus " dataset"
Dim layerds As Dataset
Set layerds = fMainForm.Map1.Datasets(LayerCombo.Text & " dataset")
Dim fld As MapXLib.Field
For Each fld In layerds.Fields
FieldCombo.AddItem fld.Name
If oldField = fld.Name Then
' If the user selected a field, try to keep it selected in the
' new field list
FieldCombo.ListIndex = FieldCombo.ListCount - 1
End If
Next
' If we couldn't restore the user's old selection, just select the first field
If FieldCombo.ListIndex = -1 Then
FieldCombo.ListIndex = 0
End If
Dim lyr As Layer
For Each lyr In fMainForm.Map1.Layers
If lyr.Name <> LayerCombo.Text Then
' Add all the layers to the refine layer combo except the one selected
' in the primary layer combobox
RefineLayerCombo.AddItem lyr.Name
' Try to keep the users old selection selected
If oldRefineLayer = lyr.Name Then
RefineLayerCombo.ListIndex = RefineLayerCombo.ListCount - 1
End If
End If
Next
' Also, add an item named "(None)"
RefineLayerCombo.AddItem "(None)"
If RefineLayerCombo.ListIndex = -1 Then ' we couldn't keep the user's selection
RefineLayerCombo.ListIndex = RefineLayerCombo.ListCount - 1
End If
End If
End Sub
Private Sub RefineLayerCombo_Click()
' What this subroutine does is, when the Refine Search with Layer combobox is
' changed, it fills the Refine Field combobox with all of the fields in the
' new refine Layer.
' Also, if "(None)" is selected in the Refine Layer combobox, it just adds
' "(None)" to the Refine Field combobox
Dim oldRefineField As String
' If the user selected a field, then changed the refine layer, we can try to
' keep the correct field selected
oldRefineField = FieldCombo.Text
' First, we need to remove all of the current items in the Refine Field combo
Dim i As Integer
For i = 0 To RefineFieldCombo.ListCount - 1
RefineFieldCombo.RemoveItem 0
Next
If RefineLayerCombo.ListIndex <> -1 Then
' First, deal with it if the user selected "(None)" for the layer
If RefineLayerCombo.Text = "(None)" Then
' If so, just have the field combo contain 1 entry: "(None)"
RefineFieldCombo.AddItem "(None)"
RefineFieldCombo.ListIndex = 0
Exit Sub
End If
' If we get here, the user picked a real layer
' Then, add all the fields that are in the current layer's dataset
' The refine layer combo contains the name of the layer that the user selected
' The dataset that corresponds to this layer is the layer name plus " dataset"
Dim layerds As Dataset
Set layerds = fMainForm.Map1.Datasets(RefineLayerCombo.Text & " dataset")
Dim fld As MapXLib.Field
For Each fld In layerds.Fields
RefineFieldCombo.AddItem fld.Name
If oldRefineField = fld.Name Then
' If the user selected a field, try to keep it selected in the
' new field list
RefineFieldCombo.ListIndex = RefineFieldCombo.ListCount - 1
End If
Next
' If we couldn't restore the user's old selection, just select the first field
If RefineFieldCombo.ListIndex = -1 Then
RefineFieldCombo.ListIndex = 0
End If
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -