2

I've got a shp-file, here is it's attribute table:

Attribute table

It's easy to fill the attribute table of some pFeature programmatically if I get the feature from cursor:

For example, "RECNO" Field(3) has a numeric format

Set pFeature = pFeatureCursor.NextFeature
Set pFeature.Value(3) =2
pFeature.store

Usually, it works fine, I shouldn't even start the Edit session for this.

But when I add a new feature and try to fill the attribute table in this code below, the error "Object required" appears.

Dim pMxDoc As IMxDocument
Dim pFeatureLayer As IFeatureLayer
Dim pFeature As IFeature
Dim pFeatureClass1 As IFeatureClass
Set pMxDoc = ThisDocument
Set pFeatureLayer = pMxDoc.FocusMap.Layer(0)
Set pFeatureClass1 = pFeatureLayer.FeatureClass
Set pFeature = pFeatureClass1.CreateFeature
' HERE IS THE PROBLEM
Set pFeature.Value(3) = 2

Error message

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Dec 18, 2015 at 7:05

1 Answer 1

4

I believe the code you have:

Set pFeature.Value(3) = 2

needs to be

pFeature.Value(3) = 2

The reason is that the value it is storing is a number and not an object.

If you are planning to run this in a loop, consider using an IFeatureBuffer with an insert cursor, I believe these are faster. Below is some example code from an old project of mine.

 For i = 0 To aDict.Count - 1
 Let aKey = thekeys(i) ' aKey is dist from route mouth
 Set pPoint = aDict.Item(aKey) ' point
 Set pFeatureBuffer = pFeatureClass_Output.CreateFeatureBuffer
 Set pFeatureBuffer.Shape = pPoint
 With pFeatureBuffer
 .Value(.Fields.FindField("ID")) = spID
 .Value(.Fields.FindField("Dist2Mouth")) = aKey
 .Value(.Fields.FindField("PolylineID")) = pFeature_WB.OID
 .Value(.Fields.FindField("WBID")) = WBID
 End With
 Let spID = spID + 1
 pFeatureCursor_SP.InsertFeature pFeatureBuffer
 Next i
answered Dec 18, 2015 at 10:54
1
  • you are right, it works! Hornbydd, thanks a lot! Commented Dec 18, 2015 at 11:46

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.