convert double to string (shape file attribute table)

278
1
06-03-2010 05:41 PM
ElaineKuo
Occasional Contributor
Dear ,

In an attribute table of shp file,

I want to convert a field (Double) (GID1) to a field (string) (GID4) using VBA.

Cstr  was tried but failed.
Pls kindly help and thanks




code

Public Sub AddCalcField()
   
    Dim pMxDoc As IMxDocument
    'Dim pFLayer As IGeoFeatureLayer
    Dim pFLayer As IFeatureLayer
    Dim pFClass As IFeatureClass
    Dim pField As IFieldEdit
    Dim dt As String
    Dim db As Double

    Set pMxDoc = ThisDocument
    Set pFLayer = pMxDoc.FocusMap.Layer(0)
    Set pFClass = pFLayer.FeatureClass
    Set pField = New Field
   
    ' Adding new Real Estate Tax field and converts to integer
            pField.Name = "GID4"
            pField.Type = esriFieldTypeString
            pField.Length = 10

   
    pFClass.AddField pField
    intRTax1 = pFClass.FindField("GID")
    intRTax2 = pFClass.FindField("GID4")
    intRTax2 = CStr(intRTax1)
   
    Dim pFeature As IFeature
    Dim pFCursor As IFeatureCursor
    Set pFCursor = pFClass.Update(Nothing, False)
    Set pFeature = pFCursor.NextFeature
    'Loops through the attribute table and updates null values for new R_TAX field
    Do Until pFeature Is Nothing
        pFeature.Value(intRTax2) = Val(pFeature.Value(intRTax1))
        pFCursor.UpdateFeature pFeature
       
    Set pFeature = pFCursor.NextFeature
    Loop
End Sub
0 Kudos
1 Reply
JeffMatson
Occasional Contributor III
I see you already found the code for using feature classes...please disregard my post in your other thread...



try commenting out this line
'intRTax2 = CStr(intRTax1)  'this is just to get the index position of the field

and apply the CStr in this line:
'pFeature.Value(intRTax2) = Val(pFeature.Value(intRTax1))
pFeature.Value(intRTax2) = CStr(pFeature.Value(intRTax1))
0 Kudos