Select to view content in your preferred language

How to insert row-values into an array?

938
1
05-27-2010 10:13 AM
CK
by
Emerging Contributor
Hello,

I would like to insert the values of a row of an attribute table into an array. I know how to do this manually:

Dim myArray()
myArray= Array("21621", "21612", "21624", .....)

But I was wondering if you can use a loop to get the values automatically (using VBA).
Can anybody help? Thanks!
0 Kudos
1 Reply
JamesCrandall
MVP Alum
Hello,

I would like to insert the values of a row of an attribute table into an array. I know how to do this manually:

Dim myArray()
myArray= Array("21621", "21612", "21624", .....)

But I was wondering if you can use a loop to get the values automatically (using VBA).
Can anybody help? Thanks!


Do you mean get the values of the features from a Layer that is loaded in the TOC of ArcMap?  I don't work much with arrays, but try something like this (untested):


Dim pLayer as IFeatureLayer = pMap.Layer(0) 'gets the first layer in the TOC
Dim pFSel as IFeatureSelection = pLayer
Dim pFCursor as IFeatureCursor
pFSel.SelectionSet.Search(Nothing, False, pFCursor)

Dim myArray() As Array = New Array
Dim i As Integer
i = 0
                
Dim pFeat as IFeature
pFeat = pFCursor.NextFeature

Dim valForArray As String
Do Until pFeat Is Nothing
     valForArray = pFeat.Value(pFeat.Fields.FindField("TheFieldName"))
     myArray.Insert(i + 1, valForArray)
   pFeat = pFCursor.NextFeature
Loop
0 Kudos