Select to view content in your preferred language

Adding a New Field to Attribute Table

1087
4
11-18-2010 08:08 AM
RonWilson
New Contributor
All,

I am reentering the frey from a nearly 6 year hiatus form programming and need to do a few simple things to get reantiquated.  Unlike MapObjects that had a straightforward API, and as many of you know, ArcObjects does not.  I am looking to calculate an index across two layers.  I need to get data from the two layers, calculate the index, and store the result in the one layer.  The first thing that I need to do is create a new field in the data table.  I have identified how to get the fields and get information about them, but I cannot seem to figure out how to add the new field and then likely update it.  I don't yet have the Getting to Know ArcObjects book yet but need to get started on this before it arrives.

Thank you,

Ron Wilson
Social Science Analyst
Office of Policy Developlment and Research
Department of Housing and Urban Development
0 Kudos
4 Replies
JeffreyHamblin
Occasional Contributor
What programming language do you intent to use? C#, VB.net, Java, Python...
0 Kudos
RonWilson
New Contributor
After I posted the message I realized I forgot to put the technical details in.  I am basically using VBA within the VB Macro Editor in ArcMap.
0 Kudos
AlexanderGray
Honored Contributor
0 Kudos
JeffreyHamblin
Occasional Contributor
I am basically using VBA within the VB Macro Editor in ArcMap.


Before you use VBA, are you aware that it is in its death throws? In version 10.0 it is a separate installation and code can no longer be placed in a normal.mxt so that any tools are available in all maps. You have to cut and paste the code into each map document. In version 10.1 VBA will be gone altogether.

If you have 10, or will be moving to it soon, then it would make a lot of sense to look at using Visual Studio 2008 Express and the new Add-ins. If you know VB/VBA then VB.net should work for you. Another option, if you don't need user interface interaction, is to use Python.

That said, if you're going to be on 9.3 for a while, might as well stick with VBA for now. There are some good examples in the online 9.3 VBA SDK documentation:
http://resources.esri.com/help/9.3/arcgisdesktop/com/vba_start.htm

The interfaces of interest are:
IFields
IFieldsEdit
IField
IFieldEdit

* pay attention to the plurals *

Set Fields to your existing fields.
Cast it to FieldsEdit.
Add a new Field.
Cast it to FieldEdit.
Set the properties of FieldEdit.
And add the field with FieldsEdit.AddField(Field);

Hope that gets you started.

-Jeff
0 Kudos