Select to view content in your preferred language

Automaticly enter address for selected parcel features

413
1
09-27-2010 03:12 PM
CharlesMcLeod
New Contributor
I want to use a input box to start entering addresses to parcels.  I want to first select the parcels then click on a command button that will populate the ST_Number field
I got the change part to work so I put it in a seperated function that is called.  I need to pass the value in the OBJECTID field of the selected feature to the change function. I'm fairly new to VBA and am stuck any help is appreciated.

Private Sub UIButtonControl1_Click()
   
    Dim mAddress As Integer
    Dim pLayer As IFeatureLayer
    Dim pClass As IFeatureClass
    Dim pMap As IMap
    Dim pDoc As IMxDocument
    Dim pFields As IFields
    Dim pField As IField
    Dim pFeat As IFeature
    Dim pRowIdObj As IRowIdentifyObject
    Dim pIdObj As IIdentifyObj
    Dim i As Integer
   
   
    Set pDoc = Application.Document
    Set pMap = pDoc.FocusMap
    Set pLayer = pMap.Layer(2)
    Set pClass = pLayer.FeatureClass
    Set pFields = pClass.Fields
    Set pRowIdObj = pIdObj
    Set pFeat = pRowIdObj.Row
    Set pFields = pFeat.Fields
 
    mAddress = InputBox("Enter First Address")

      '**********
    Dim i As Integer
    For i = 0 To pFields.FieldCount - 1
        Set pField = pFields.Field(i)
        mChange (pField)
        mAddress = mAddress + 2
    Next i

       
End Sub
Public Sub mChange(mRec As Integer)

    Dim pDoc As IMxDocument
    Dim pMap As IMap
    Dim pFLayer As IFeatureLayer
    Dim pFeature As IFeature
    Dim mAddress As Integer
   
    Set pDoc = Application.Document
    Set pMap = pDoc.FocusMap
    Set pFLayer = pMap.Layer(2)
    Set pFeature = pFLayer.FeatureClass.GetFeature(mRec)
   
     mAddress = InputBox("Enter Address", "Ghana Address")
       
    If mAddress < 1 Then
        Exit Sub
    End If
       
    pFeature.Value(pFeature.Fields.FindField("St_Number")) = mAddress
       
    pFeature.Store

End Sub
0 Kudos
1 Reply
CharlesMcLeod
New Contributor
Public mAddress As Integer
Private Sub UIButtonControl1_Click()
    'Dim mAddress As Integer
    Dim pFeat As IFeature
    Dim pEnumFeature As IEnumFeature
    Dim pLayer As IFeatureLayer
   
    Dim pClass As IFeatureClass
    Dim pMap As IMap
    Dim pDoc As IMxDocument

    Dim pEnumFeatureSetup As IEnumFeatureSetup
   
      
    Set pDoc = Application.Document
    Set pMap = pDoc.FocusMap
    Set pLayer = pMap.Layer(gLayer)
    Set pClass = pLayer.FeatureClass
    Set pFields = pClass.Fields
    Set pEnumFeature = pMap.FeatureSelection
    Set pFeat = pEnumFeature.Next
   
    mAddress = InputBox("Enter First Address")
   
    Do While (Not pFeat Is Nothing)
        mChange (pFeat.Value(0))
        Set pFeat = pEnumFeature.Next
        mAddress = mAddress + 2
    Loop

 
End Sub
Property Get gLayer() As Integer
    Dim pMap As IMap
    Dim pDoc As IMxDocument
    Dim pLayer As IFeatureLayer
    Dim i As Integer
   
    Set pDoc = Application.Document
    Set pMap = pDoc.FocusMap
    Set pLayer = pMap.Layer(i)
   
    For i = 0 To pMap.LayerCount - 1
        If pMap.Layer(i).Name = "Parcels" Then
            pPlayer = i
        End If
    Next i
   
End Property
Public Function mChange(ByVal mRec As Integer)

    Dim pDoc As IMxDocument
    Dim pMap As IMap
    Dim pFLayer As IFeatureLayer
    Dim pFeature As IFeature
   
    Set pDoc = Application.Document
    Set pMap = pDoc.FocusMap
    Set pFLayer = pMap.Layer(mLayIndex)
    Set pFeature = pFLayer.FeatureClass.GetFeature(mRec)
   
       
    pFeature.Value(pFeature.Fields.FindField("St_Number")) = mAddress
    pFeature.Store
   
End Function
0 Kudos