2

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?

whuber
70.4k17 gold badges189 silver badges285 bronze badges
asked May 19, 2011 at 15:16
1
  • Do you want a QueryFilter? Commented May 19, 2011 at 15:22

3 Answers 3

2

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))
answered May 19, 2011 at 16:14
1
  • I dont see any need of an update cursor...isnt simple Search cursor enough for the job? Commented May 19, 2011 at 17:21
1

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)
answered May 19, 2011 at 17:39
0
0

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
answered May 19, 2011 at 16:16

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.