Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question
    
Do you want a QueryFilter? –  patrick May 19 '11 at 15:22
    
thank you all guys!!! Problem solve!!! :) Alex –  Alex May 20 '11 at 13:56
    
please place a check mark next to the accepted answer. –  Kirk Kuykendall May 20 '11 at 13:59
add comment

3 Answers

up vote 1 down vote accepted

Try this:

Dim pMxDoc As IMxDocument
Dim pFeatureClass As IFeatureClass
Dim pFeatLayer As IFeatureLayer
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 pFeatCursor As IFeatureCursor
Dim pFeature As IFeature

' Prepare a query filter.
Set pQFilter = New QueryFilter
pQFilter.SubFields = "PARCEL_NAME, SCALE" 'Retrieve only these fields
pQFilter.WhereClause = "PARCEL_NAME='" & txtParcelName.Text & "'" ''' Text box on form

' Create a feature cursor for updating.
Set pFeatCursor = pFeatureClass.Search(pQFilter, true)

' Part 3: Get the Scale value
Do

pFeature = pFeatureCursor.NextFeature

If pFeature IsNot Nothing Then

MsgBox("Scale: " & pFeature.Value(pFeatureCursor.FindField("SCALE")))

End If

While !(pFeature = Nothing)
share|improve this answer
    
thank you....i´ve used parts of your code and it work. –  Alex May 20 '11 at 13:55
add comment

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))
share|improve this answer
    
I dont see any need of an update cursor...isnt simple Search cursor enough for the job? –  ujjwalesri May 19 '11 at 17:21
add comment

Create a select cursor. I'm not sure about VBA but for python: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v00000039000000.htm

#iName is input testing Name

parcels = arcpy.SearchCursor(fParcels)

for parcel in parcels:
    if parcel.Name == iName:
        scale = parcel.scale
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.