helenak

convert a ArcGIS Desktop VBA to ArcCatalog VBA

Discussion created by helenak on Apr 24, 2012
Latest reply on Apr 27, 2012 by helenak
Hello

I have a VBA code for ArcGIS Desktop.
I would like to ask if it is possible to convert it for ArcCatalog.
Thank you.

Code
Public Sub CreateField()
On Error GoTo eh:
       
Dim pMxDoc As IMxDocument
Set pMxDoc = ThisDocument
Dim pMap As IMap
Set pMap = pMxDoc.FocusMap
Dim pLayer As ILayer
Set pLayer = pMap.Layer(0)
Dim pFeatureLayer As IFeatureLayer
Dim pFeatureClass As IFeatureClass
If TypeOf pLayer Is IFeatureLayer Then
Set pFeatureLayer = pLayer
Else
Exit Sub
End If
Set pFeatureClass = pFeatureLayer.FeatureClass
Dim pField As IField
Dim pFieldedit As IFieldEdit
Set pField = New Field
Set pFieldedit = pField
With pFieldedit
.Name = "Season"
.AliasName = "Season"
.Type = esriFieldTypeString
.Length = 6
End With
pFeatureClass.AddField pField
Call UpdateFeatures
eh:
End Sub

Public Sub UpdateFeatures()
    Dim pFeatureClass As IFeatureClass
    Dim pFeatureLayer As IFeatureLayer
    Dim pDoc As IMxDocument
    Dim pMap As IMap
   
    Set pDoc = ThisDocument
    Set pMap = pDoc.Maps.Item(0)
    Set pFeatureLayer = pMap.Layer(0)
    Set pFeatureClass = pFeatureLayer.FeatureClass
   
    Dim pFeatureCursor As IFeatureCursor
    Dim pFeature As IFeature
   
    Set pFeatureCursor = pFeatureClass.Update(Nothing, False)
   
    '++++++ Loop through each feature and update
    Set pFeature = pFeatureCursor.NextFeature
    Do While Not pFeature Is Nothing
    pFeature.Value(pFeature.Fields.FindField("Season")) = pFeature.Value(pFeature.Fields.FindField("C9469"))
    pFeature.Store
    Set pFeature = pFeatureCursor.NextFeature
    Loop
End Sub

Outcomes