[GIS] ArcObjects – Select record from table

arcobjectsvba

I´ve a project in VBA but I hit a wall that I can't pass.
What I want to do:

I´ve a table (of parcels) with the fields: ID, Name, Area, Scale. For each Parcel there is a different scale!

I input, in a text box, the name of a parcel. I want to "get" the corresponding scale.

Does anybody know how I can do that?

Best Answer

Here is a code example of a QueryFilter. You could assign a variable to hold your text box value for this line "APP_TYP = 'PA'" and update this line indexClass = pUpdateFeatures.FindField("Dir") to point to your scale field. The result will give you a message box of the scale value.

' Par 1: Define the feature class.
    Dim pMxDoc As IMxDocument
    Dim pFeatureClass As IFeatureClass
    Dim pFeatLayer As IFeatureLayer
    'Dim pFeatureClass As IFeatureClass
    Dim pFields As IFields
    Dim ii As Integer
    Set pMxDoc = ThisDocument
    Set pFeatLayer = pMxDoc.FocusMap.Layer(0)
    Set pFeatureClass = pFeatLayer.FeatureClass

    ' Part 2: Prepare a feature cursor.
    Dim pQFilter As IQueryFilter
    Dim pUpdateFeatures As IFeatureCursor
    ' Prepare a query filter.
    Set pQFilter = New QueryFilter
    pQFilter.WhereClause = "APP_TYP = 'PA'"
    ' Create a feature cursor for updating.
    Set pUpdateFeatures = pFeatureClass.Update(pQFilter, False)

    ' Part 3: Calcuate the Class value.
    Dim indexClass As String
    Dim pFeature As IFeature
    indexClass = pUpdateFeatures.FindField("Dir")
    Set pFeature = pUpdateFeatures.NextFeature

        MsgBox ("Scale value = " & pFeature.value(indexClass))