Select to view content in your preferred language

Grab Attribute Value from Query

492
1
04-20-2011 12:00 PM
JayKappy
Occasional Contributor
I can do this and grab the Attribute value from the spatial query (only grabs one value)

       If featureSet IsNot Nothing AndAlso featureSet.Features.Count > 0 Then
            For Each feature As Graphic In featureSet.Features
                feature.Symbol = TryCast(LayoutRoot.Resources("PrecinctsFill"), FillSymbol)
                graphicsLayer.Graphics.Insert(0, feature)

                Dim Test = feature.Attributes("PRECINCTS_")
                MessageBox.Show(Test)

            Next feature
        End If


But I want the value outside the For EAch Loop to put that in another query...
I tried this but errors

        Dim Test As String
         Dim Test2 As String

        If featureSet IsNot Nothing AndAlso featureSet.Features.Count > 0 Then
            For Each feature As Graphic In featureSet.Features
                feature.Symbol = TryCast(LayoutRoot.Resources("PrecinctsFill"), FillSymbol)
                graphicsLayer.Graphics.Insert(0, feature)

                Test2 = feature.Attributes("PRECINCTS_")


            Next feature
        End If

       Test = Test2
0 Kudos
1 Reply
nakulmanocha
Esri Regular Contributor
This isn't really a SLT/ArcGIS SLT API issue. It is actually a general programming issue. Test2 variable goes outside the scope when accessed outside the loop. You must declare the Test2 variable outside the loop. Also, remember that Test2 will always take the last feature value of the attribute (within the featureset). Unless you know for sure that your featureSet going to return only one feature. You may wanna use some condition to break out of the loop (after getting the desired attribute value).


Dim Test As String

 Dim Test2 As String 

        If featureSet IsNot Nothing AndAlso featureSet.Features.Count > 0 Then
            For Each feature As Graphic In featureSet.Features
                feature.Symbol = TryCast(LayoutRoot.Resources("PrecinctsFill"), FillSymbol)
                graphicsLayer.Graphics.Insert(0, feature)

                Test2 = feature.Attributes("PRECINCTS_")


            Next feature
        End If

       Test = Test2
0 Kudos