To populate a field using the field calculator and a stored
VBA script:
1) Highlight the attribute table field by clicking on the field name.
2) Right-click on the field name and select “Calculate Values…” to
bring up the Field Calculator. If you are not in editing mode, a
warning reminds you that changes to the table outside of an
editing session cannot be undone. Either answer “No” to “Do you
wish to continue?”, start an editing session (Editing Toolbar
dropdown>Start Editing) and repeat the steps to continue, or click
“Yes” and proceed.
3) With the Field Calculator open, check the “Advanced” check
box to see the Prelogic and variable areas that will hold the VBA
script.
4) Click the “Load…” button, navigate to the script of interest
and click OK to load it.
5) If you’re so inclined, examine the script and marvel at the
arcane code and syntax. (More seriously, a great resource for
coding in VBA is available in the digital books folder. It should
be relatively easy to understand a script by spending just a
little time with the tutorial.)
6) Click OK and the field will be populated with new values
generated by the script. Most scripts require that the field
properties (long integer, short integer, scale, precision, etc) of
the attribute field that you are populating match that required by
the script. If the script does not run or returns values
that are nonsense this is the probable cause. A principle consideration should be the
units of the new values. Depending on the script, these will be
either in the units of coordinate system of the layer or the units
of the Data Frame. Examining the script should establish this. In
the example below that calculates area the script uses the
properties of the Data Frame to establish units (“pGeometry.Project
pMap.SpatialReference”) . Other scripts may rely on the coordinate
system of the layer.
|