+ Reply to Thread
Results 1 to 5 of 5

Thread: Do Until IsEmpty Error - VBA to VB.net

  1. #1
    Stephanie Macuga
    Join Date
    Apr 2010
    Posts
    30
    Points
    3
    Answers Provided
    1


    0

    Default Do Until IsEmpty Error - VBA to VB.net

    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

  2. #2
    Ken Buja

    Join Date
    Jan 2010
    Posts
    1,210
    Points
    874
    Answers Provided
    151


    0

    Default Re: Do Until IsEmpty Error - VBA to VB.net

    Here's an example of stepping through all the unique values using DataStatistics in VB.NET

    Code:
    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
    Ken Buja
    Silver Spring, MD

  3. #3
    John Nelson
    Join Date
    Jan 2012
    Posts
    20
    Points
    16
    Answers Provided
    3


    1

    Default Re: Do Until IsEmpty Error - VBA to VB.net


  4. #4
    Stephanie Macuga
    Join Date
    Apr 2010
    Posts
    30
    Points
    3
    Answers Provided
    1


    0

    Default Re: Do Until IsEmpty Error - VBA to VB.net

    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

  5. #5
    John Nelson
    Join Date
    Jan 2012
    Posts
    20
    Points
    16
    Answers Provided
    3


    0

    Default Re: Do Until IsEmpty Error - VBA to VB.net

    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

+ Reply to Thread

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts