how to get the value of IField ????

3163
13
07-09-2010 06:39 AM
AbdulrahmanAlqasim
New Contributor
i want to get the field value of a feature class using this code:

pFeature = pFeatureCursor.NextFeature();
pField = pFeature.Fields.get_Field(0);

how i can get the value of pField.
thank you
0 Kudos
13 Replies
JamesCrandall
MVP Frequent Contributor
You could just get the value right from pFeature:

Dim value as String
pFeature = pFeatureCursor.NextFeature
Do Until pFeature Is Nothing
  value = pFeature.Value(pFeature.Fields.FindField("TheFieldName"))
  pFeature = pFeatureCursor.NextFeature
Loop
0 Kudos
AbdulrahmanAlqasim
New Contributor
thanks man
that was very helpful
0 Kudos
JamesCrandall
MVP Frequent Contributor
No problem -- glad I could help.
0 Kudos
pavankalvala
New Contributor
I am able to get the value of a field name "FID" in a message box. I am trying to put this value into a word doc Bookmark.

How can I do this. Any  help.

Code I used to get the field value of "FID":

M = pFeat.Value(pFeat.Fields.FindField("FID"))
            pFeat = pEnumFeat.Next
            MsgBox(M)  /// I need this value shown in message box pulled into a word doc bookmark.
0 Kudos
pavankalvala
New Contributor
Is there a code to loop through the field names from a selected feature?
0 Kudos
AlexanderGray
Occasional Contributor III
If you just want to loop through all the values you could do something like this

feature = get feature with the method of your choice
i = 0
for i to feature.fields.count -1
  theValue = feature.value(i)
  theFieldName = feature.fields.field(i)

Of course you have to be careful the way you handle the field values, you will be getting objectids, shapes, integers, strings and probably dbnulls.

Cheers
0 Kudos
pavankalvala
New Contributor
I am able to get the field name through the loop as below:

pEnumFeat = pMxdoc.FocusMap.FeatureSelection
        pFeat = pEnumFeat.Next

        ' loop through each field and add the field name to a list
        For ii = 0 To fields.FieldCount - 1
            Field = fields.Field(ii)
            fieldname = Field.Name
            fieldvalue = Field.VarType
            ' fieldvalue = pFeat.Value(pFeat.Fields.Field)       '' trying to get the field value
            'value = Field.DefaultValue                               '' trying to get the field value

            namelist = namelist & fieldname & fieldvalue & Chr(13)
        Next
MsgBox(namelist, , "field names")

This displays all the fields from the selected feature. How do I get the field value from the above loop.
0 Kudos
AlexanderGray
Occasional Contributor III
pEnumFeat = pMxdoc.FocusMap.FeatureSelection
pFeat = pEnumFeat.Next

' loop through each field and add the field name to a list
For ii = 0 To fields.FieldCount - 1
Field = fields.Field(ii)
fieldname = Field.Name
fieldvalue = pFeat.Value(ii)
0 Kudos
pavankalvala
New Contributor
I tried that, but I get an error ' conversion from type '_ComObject' to type 'Long' is not valid'

I set the value as :

Dim value as long.  ( I tried using 'string', 'double', 'long' and I get the same error as above)

Any hint?
0 Kudos