helenak

convert standalone table code to featureclass (shp file) one

Discussion created by helenak on Jun 3, 2010
Dear,

I have the code below for standalone table.
However, I wanna implement for the attribute table of a shp file (attached).

Please kindly help how to convert it .
Thanks


The code

Public Sub ConcatenateField()
' ---- Modify these values as appropriate ----
Const LOCATIONID_FIELD As String = "GID2"
Const BUSINESS_FIELD As String = "C0440"
' --------------------------------------------
Dim pMxDoc As IMxDocument
Dim pSATblColl As IStandaloneTableCollection
Dim pTbl As IStandaloneTable
Dim pTb2 As ITable
Dim pCsr As ICursor
Dim pRow As IRow
Dim pNxtRow As IRow
Dim sLocID As String
Dim sNxtLocID As String
Dim sBus As String
Dim sNxtBus As String
Dim lLocIdx As Long
Dim lBusIdx As Long
Dim sConcat As String
Dim pTblSort As ITableSort
Dim pEditor As IEditor
Dim pID As New UID

    ' Make sure we're in an edit session
    pID.Value = "esriEditor.Editor"
    Set pEditor = Application.FindExtensionByCLSID(pID)
    If pEditor.EditState = esriStateNotEditing Then
        MsgBox "Please Start An Edit Session On The Table"
        Exit Sub
    End If
   
    ' Get a ref to the first table in the map
    Set pMxDoc = ThisDocument
    Set pSATblColl = pMxDoc.FocusMap
    Set pTbl = pSATblColl.StandaloneTable(0)
    Set pTb2 = pTb1.Table
   
    ' Get the field indexes
    lLocIdx = pTb2.FindField(LOCATIONID_FIELD)
    lBusIdx = pTb2.FindField(BUSINESS_FIELD)
   
    ' Get a sorted cursor on the table
    Set pTblSort = New TableSort
    With pTblSort
        Set .Table = pTb2
        .Fields = LOCATIONID_FIELD + "," + BUSINESS_FIELD
        .Ascending(LOCATIONID_FIELD) = True
        .Ascending(BUSINESS_FIELD) = True
        .Sort Nothing
    End With
   
    ' Start an edit operation (so that it can be undone)
    pEditor.StartOperation
   
    ' Loop thru all the sorted records
    Set pCsr = pTblSort.Rows
    Set pRow = pCsr.NextRow
    sLocID = CStr(pRow.Value(lLocIdx))
    sBus = "," + pRow.Value(lBusIdx) + ","
    Set pNxtRow = pCsr.NextRow
   
    While Not pNxtRow Is Nothing
        sNxtLocID = CStr(pNxtRow.Value(lLocIdx))
        If sNxtLocID = sLocID Then
            ' Concatenate the Business field for duplicate records
            ' and delete the duplicates.
            ' Only concatenate unique Business field entries
            sNxtBus = pNxtRow.Value(lBusIdx)
            If InStr(sBus, "," + sNxtBus + ",") = 0 Then
                sBus = sBus + sNxtBus + ","
            End If
            pNxtRow.Delete
        Else
            'Store the record with the concatenated Business field
            sBus = Mid(sBus, 2, Len(sBus) - 2)
            sBus = Replace(sBus, ",", ", ")
            pRow.Value(lBusIdx) = sBus
            pRow.Store
            Set pRow = pNxtRow
            sLocID = CStr(pRow.Value(lLocIdx))
            sBus = "," + pRow.Value(lBusIdx) + ","
        End If
        ' Get the next record
        Set pNxtRow = pCsr.NextRow
    Wend

    ' Store the last record
    sBus = Mid(sBus, 2, Len(sBus) - 2)
    sBus = Replace(sBus, ",", ", ")
    pRow.Value(lBusIdx) = sBus
    pRow.Store

    ' Stop the edit operation
    pEditor.StopOperation "Concatenate Field"


    ' Inform the user we've finished
    MsgBox "Concatenation completed", vbInformation, ""

End Sub

Attachments

Outcomes