Do Until IsEmpty Error - VBA to VB.net

1502
4
04-09-2012 10:16 AM
StephanieMacuga
New Contributor III
Despite the fact that I am a novice, I'm looking to upgrade some coding from VBA to VB.net.  I literally have gone from 102 errors, down to 1 - and am stuck! 

This small section essentially searches through a table which has multiple inspection locations and each location can have several inspection dates. I need to query that table in ArcMap to find all the unique inspection locations and the most recent inspection date for that location.  The original coding (that I had incredible help with developing thanks to the forums!!) worked beautifully for 2 years, but I'm running into an issue now with the 'Do Until IsEmpty (value)' line.  I'm getting an error message that "Name 'IsEmpty' is not declared".  Any ideas??

The original coding is as follows:

Sub SelectRecordsForMaxFieldValue_Inspections() 'selects all unique inspections from "Inspections.shp" and most recent date
        Dim pMxDoc As IMxDocument
        Dim pFLayer As IFeatureLayer
        Dim pData As IDataStatistics
        Dim pCursor As ICursor
        pMxDoc = My.ArcMap.Document
        pFLayer = pMxDoc.FocusMap.Layer(1) 'change the index according to the layer of interest
        pCursor = pFLayer.Search(Nothing, False)

        'Create the new table that the selected records will populate.
        pData = New DataStatistics
        pData.Field = "typeAndNum" 'change to match FC attribute with multiple records
        pData.Cursor = pCursor 'this is the same cursor created above

        Dim pEnumVar As IEnumVariantSimple

        Dim value As Object

        pEnumVar = pData.UniqueValues

        value = pEnumVar.Next

        Dim pFeatureSelection As IFeatureSelection
        pFeatureSelection = pFLayer 'QI

        Dim pActiveView As IActiveView
        pActiveView = pMxDoc.ActiveView

        Do Until IsEmpty(value)
            Dim pQF As IQueryFilter
            pQF = New QueryFilter
            pQF.WhereClause = "typeAndNum = '" & value & "'" 'change to match FC attribute with multiple records
            Dim pFc As ICursor
            Dim pTable As ITable
            pTable = pFLayer
            pFc = pTable.Search(pQF, False)
            Dim pDataStats1 As IDataStatistics
            pDataStats1 = New DataStatistics
            pDataStats1.Field = "dt_stamp" 'FC attribute you want the most recent value of
            pDataStats1.Cursor = pFc
            Dim pDataStatResults1 As IStatisticsResults
            pDataStatResults1 = pDataStats1.Statistics

            'Create the query filter
            Dim pQueryFilter As IQueryFilter
            pQueryFilter = New QueryFilter
            pQueryFilter.WhereClause = "typeAndNum = '" & value & "' AND dt_stamp = date '" & Format(pDataStatResults1.Maximum, "MM/DD/YYYY") & "'"

            pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, Nothing, Nothing) 'Flag original selection
            pFeatureSelection.SelectFeatures(pQueryFilter, esriSelectionResultEnum.esriSelectionResultAdd, False) 'Perform the selection
            pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, Nothing, Nothing) 'Flag the new selection

            value = pEnumVar.Next
        Loop

Thanks in advance for any help/ideas!
Stephanie
0 Kudos
4 Replies
KenBuja
MVP Esteemed Contributor
Here's an example of stepping through all the unique values using DataStatistics in VB.NET


Dim pEnumerator As System.Collections.IEnumerator

pEnumerator = pData.UniqueValues
pEnumerator.Reset()

Do While pEnumerator.MoveNext
  value = pEnumerator.Current
  pQF = New QueryFilter
  pQF.WhereClause = "typeAndNum = '" & value & "'" 'change to match FC attribute with multiple records

  'etc

Loop
0 Kudos
JohnNelson3
New Contributor III
0 Kudos
StephanieMacuga
New Contributor III
Thanks for the replies!  The "IsNothing" removed the error and I was able to successfully create the build!  Huge step for me!  However, after adding the add-in to ArcMap, the software crashed which leads me to believe I have some other error floating around in there.

Thanks for the help here though - and for that website - great resource 🙂
0 Kudos
JohnNelson3
New Contributor III
Dim pMxDoc As IMxDocument
        Dim pFLayer As IFeatureLayer
        Dim pData As IDataStatistics
        Dim pCursor As ICursor
        Try
            pMxDoc = My.ArcMap.Document
            pFLayer = pMxDoc.FocusMap.Layer(0) 'change the index according to the layer of interest
            pCursor = pFLayer.Search(Nothing, False)

            'Create the new table that the selected records will populate.
            pData = New DataStatistics
            pData.Field = "typeAndNum" 'change to match FC attribute with multiple records
            pData.Cursor = pCursor 'this is the same cursor created above

            Dim pEnumVar As IEnumerator


            pEnumVar = CType(pData.UniqueValues, IEnumerator)
            pEnumVar.Reset()
            pEnumVar.MoveNext()

            Dim pFeatureSelection As IFeatureSelection
            pFeatureSelection = pFLayer 'QI

            Dim pActiveView As IActiveView
            pActiveView = pMxDoc.ActiveView
            Dim d As DateTime

            Do Until IsNothing(pEnumVar.Current)
                Dim pQF As IQueryFilter
                pQF = New QueryFilter
                pQF.WhereClause = "typeAndNum = '" & pEnumVar.Current & "'" 'change to match FC attribute with multiple records
                Dim pFc As ICursor
                Dim pTable As ITable
                pTable = pFLayer
                pFc = pTable.Search(pQF, False)
                Dim pDataStats1 As IDataStatistics
                pDataStats1 = New DataStatistics
                pDataStats1.Field = "dt_stamp" 'FC attribute you want the most recent value of
                pDataStats1.Cursor = pFc
                Dim pDataStatResults1 As IStatisticsResults
                pDataStatResults1 = pDataStats1.Statistics

                'Create the query filter
                Dim pQueryFilter As IQueryFilter
                pQueryFilter = New QueryFilter
                pQueryFilter.WhereClause = "typeAndNum = '" & pEnumVar.Current & "' AND dt_stamp = date '" & Date.FromOADate(pDataStatResults1.Maximum).Date & "'"
                pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, Nothing, Nothing) 'Flag original selection
                pFeatureSelection.SelectFeatures(pQueryFilter, esriSelectionResultEnum.esriSelectionResultAdd, False) 'Perform the selection
                pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, Nothing, Nothing) 'Flag the new selection
                pEnumVar.MoveNext()

            Loop
        Catch

        End Try
0 Kudos