📄 vba10-2.txt
字号:
Option Explicit
Public Sub PopulateStateCombo()
' This procedure uses the State layer to populate
' cboState with state names. The State layer is available
' through a global variable that was set in module Main.
'
' (1) Access the State layer
Dim pLayer As IFeatureLayer
Dim pFeatureClass As IFeatureClass
Set pLayer = Main.g_pStateLayer
Set pFeatureClass = pLayer.FeatureClass
'
' (2) Sort State layer's table
Dim pTableSort As ITableSort
Set pTableSort = New TableSort
pTableSort.Fields = "STATE_NAME"
pTableSort.Ascending("STATE_NAME") = True
Set pTableSort.Table = pFeatureClass
pTableSort.Sort Nothing
'
' (3) Populate the State's combo box
Dim pCursor As ICursor
Dim pRow As IRow
Dim lngFieldIndex As Long
Set pCursor = pTableSort.Rows
lngFieldIndex = pFeatureClass.FindField("STATE_NAME")
Set pRow = pCursor.NextRow
Do While Not pRow Is Nothing
cboState.AddItem pRow.Value(lngFieldIndex)
Set pRow = pCursor.NextRow
Loop
cboState.ListIndex = 0
End Sub
Public Sub PopulateClassificationCombo()
' The Classification field combo always has a list
' of numeric fields in the census tract layer. This
' procedure populates it.
'
' (1) Access the Tract layer
Dim pLayer As IFeatureLayer
Dim pFeatureClass As IFeatureClass
Set pLayer = Main.g_pTractLayer
Set pFeatureClass = pLayer.FeatureClass
'
' (2) Populate combo box with numeric field names
Dim pFields As IFields
Dim pField As IField
Dim lngIndex As Long
Set pFields = pFeatureClass.Fields
For lngIndex = 0 To pFields.FieldCount - 1
Set pField = pFields.Field(lngIndex)
If pField.Type = esriFieldTypeDouble Or _
pField.Type = esriFieldTypeInteger Or _
pField.Type = esriFieldTypeSingle Then
cboField.AddItem pField.AliasName
End If
Next lngIndex
cboField.ListIndex = 0
End Sub
Public Sub PopulateClassCountCombo()
' The application provides from 2 to 9 classes.
' This procedure populates the class count choices
' in the class count combo box.
Dim lngIndex As Long
For lngIndex = 2 To 9
cboClassCount.AddItem lngIndex
Next lngIndex
cboClassCount.ListIndex = 0
End Sub
Private Sub cboState_Change()
' This procedure is executed each time a diffrent
' state is selected. It populates the county combo
' box based on the selected state.
'
' (1) Access the County layer
Dim pLayer As IFeatureLayer
Dim pFeatureClass As IFeatureClass
Set pLayer = Main.g_pCountyLayer
Set pFeatureClass = pLayer.FeatureClass
'
' (2) Query and sort County layer's table
Dim pTableSort As ITableSort
Dim pQueryFilter As IQueryFilter
Set pQueryFilter = New QueryFilter
'pQueryFilter.SubFields = "STATE_NAME,NAME"
pQueryFilter.WhereClause = "STATE_NAME = '" & _
cboState.Text & "'"
Set pTableSort = New TableSort
pTableSort.Fields = "STATE_NAME,NAME"
pTableSort.Ascending("STATE_NAME") = True
pTableSort.Ascending("NAME") = True
Set pTableSort.QueryFilter = pQueryFilter
Set pTableSort.Table = pFeatureClass
pTableSort.Sort Nothing
'
' (3) Populate the County's combo box
Dim pCursor As ICursor
Dim pRow As IRow
Dim lngFieldIndex As Long
' Clear any existing county names
cboCounty.Clear
Set pCursor = pTableSort.Rows
lngFieldIndex = pFeatureClass.FindField("NAME")
Set pRow = pCursor.NextRow
Do While Not pRow Is Nothing
cboCounty.AddItem pRow.Value(lngFieldIndex)
Set pRow = pCursor.NextRow
Loop
cboCounty.ListIndex = 0
End Sub
Private Sub cmdCancel_Click()
End
End Sub
Private Sub cmdOK_Click()
frmClassify.Hide
frmLayout.Show
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -