payapangalon

Help: Selecting records and displaying it on listbox

Discussion created by payapangalon on Dec 15, 2010
Latest reply on Dec 17, 2010 by Grieck
Hello:
I was able to do this for one layer. Now that im doing it to 4 other layer through combo box selection, it won't run properly.

Will someone look at my code and figure out what's wrong? Pretty please...

Private Sub SelectRecords(layername As String)
    ' Part 1: Define the table.
    Dim pWSName As IWorkspaceName
    Dim pDatasetName As IDatasetName
    Dim pName As IName
    Dim pTable As ITable
    ' Get the dbf file.
    Set pWSName = New WorkspaceName
    pWSName.WorkspaceFactoryProgID = "esriCore.ShapefileWorkspaceFactory"
    pWSName.PathName = "X:\arcobjects\FinalProject\Final Project"
    Set pDatasetName = New TableName
    pDatasetName.name = layername
    Set pDatasetName.WorkspaceName = pWSName
    Set pName = pDatasetName
    'Open the dbf table.
    Set pTable = pName.Open

 
    ' Part 2: Perform selection.
    Dim pQFilter As IQueryFilter
    Dim pScratchWS As IWorkspace
    Dim pScratchWSFactory As IScratchWorkspaceFactory
    Dim pSelectionSet As ISelectionSet
    ' Prepare a query filter.
    Set pQFilter = New QueryFilter
   
   
    Select Case layername
        Case "PurshiaGPSpoints"
            pQFilter.SubFields = "Id, Number, Observer, Occurence"
            pQFilter.WhereClause = "Number > 3"
        Case "TES385"
            pQFilter.SubFields = "objectid, map_unit_s, landform, material, soil_name"
            pQFilter.WhereClause = "Map_Unit_S like '03%'"
        Case "TES350"
            pQFilter.SubFields = "objectid, map_unit_s, landform, material, soil_name"
            pQFilter.WhereClause = "Map_Unit_S like '03%'"
        Case "slope"
            pQFilter.SubFields = "value, slope_percent"
            pQFilter.WhereClause = "Value > 1"
        Case "aspect"
            pQFilter.SubFields = "value, aspect"
            pQFilter.WhereClause = "Value > 1"
    End Select
    ListBox.Clear
   
    Dim pMxDoc As IMxDocument
    Dim pMap As IMap
    Dim pActiviVIew As IActiveView
    Dim pFeatureLayer As IFeatureLayer
    Dim pFeatureSelection As IFeatureSelection
    Dim pfeaturecursor As IFeatureCursor
    'pSelectionSet.Search Nothing, False, pfeaturecursor
   
    Dim pFeature As IFeature
    'Set pFeature = pfeaturecursor.NextFeature
   
    If layername = "PurshiaGPSpoints" Then
        Dim Idfieldvalue As Integer
        Idfieldvalue = pFeatureLayer.FeatureClass.FindField("Id")

        Dim Numberfieldvalue As Integer
        Numberfieldvalue = pFeatureLayer.FeatureClass.FindField("Number")

        Dim Observerfieldvalue As Long
        Observerfieldvalue = pFeatureLayer.FeatureClass.FindField("Observer")

        Dim commentsfieldvalue As String
        commentsfieldvalue = pFeatureLayer.FeatureClass.FindField("comments")
   
        Do Until pFeature Is Nothing

            Me.ListBox.AddItem pFeature.Value(Idfieldvalue)
            Me.ListBox.AddItem pFeature.Value(Numberfieldvalue)
            Me.ListBox.AddItem pFeature.Value(Observerfieldvalue)
            Me.ListBox.AddItem pFeature.Value(commentsfieldvalue)
            Set pFeature = pfeaturecursor.NextFeature

        Loop
   
    ElseIf layername = "TES385" Then
       
        Dim Objectidfieldvalue As Integer
        Objectidfieldvalue = pFeatureLayer.FeatureClass.FindField("Objectid")

        Dim Map_Unit_Sfieldvalue As Integer
        Map_Unit_Sfieldvalue = pFeatureLayer.FeatureClass.FindField("map_unit_s")

        Dim Landformfieldvalue As Long
        Landformfieldvalue = pFeatureLayer.FeatureClass.FindField("landform")

        Dim soil_namefieldvalue As String
        soil_namefieldvalue = pFeatureLayer.FeatureClass.FindField("soil_name")
       
        Dim materialfieldvalue As String
        materialfieldvalue = pFeatureLayer.FeatureClass.FindField("material")
       
       
        Do Until pFeature Is Nothing
   
                Me.ListBox.AddItem pFeature.Value(Objectidfieldvalue)
                Me.ListBox.AddItem pFeature.Value(Map_Unit_Sfieldvalue)
                Me.ListBox.AddItem pFeature.Value(Landformfieldvalue)
                Me.ListBox.AddItem pFeature.Value(soil_namefieldvalue)
                Me.ListBox.AddItem pFeature.Value(materialfieldvalue)
                Set pFeature = pfeaturecursor.NextFeature
        Loop
   
    ElseIf layername = "TES350" Then
           
        Dim Objectidfieldvalue2 As Integer
        Objectidfieldvalue2 = pFeatureLayer.FeatureClass.FindField("Objectid")

        Dim Map_Unit_Sfieldvalue2 As Integer
        Map_Unit_Sfieldvalue2 = pFeatureLayer.FeatureClass.FindField("map_unit_s")

        Dim Landformfieldvalue2 As Long
        Landformfieldvalue2 = pFeatureLayer.FeatureClass.FindField("landform")

        Dim soil_namefieldvalue2 As String
        soil_namefieldvalue2 = pFeatureLayer.FeatureClass.FindField("soil_name")
       
        Dim materialfieldvalue2 As String
        materialfieldvalue2 = pFeatureLayer.FeatureClass.FindField("material")
       
        Do Until pFeature Is Nothing
   
                Me.ListBox.AddItem pFeature.Value(Objectidfieldvalue)
                Me.ListBox.AddItem pFeature.Value(Map_Unit_Sfieldvalue)
                Me.ListBox.AddItem pFeature.Value(Landformfieldvalue)
                Me.ListBox.AddItem pFeature.Value(soil_namefieldvalue)
                Me.ListBox.AddItem pFeature.Value(materialfieldvalue)
                Set pFeature = pfeaturecursor.NextFeature
        Loop
       
    ElseIf layername = "slope" Then
           
        Dim valuefieldvalue As Integer
        valuefieldvalue = pFeatureLayer.FeatureClass.FindField("value")

        Dim slope_percentfieldvalue As Integer
        slope_percentfieldvalue = pFeatureLayer.FeatureClass.FindField("slope_percent")
       
        Do Until pFeature Is Nothing
   
                Me.ListBox.AddItem pFeature.Value(valuefieldvalue)
                Me.ListBox.AddItem pFeature.Value(slope_percentfieldvalue)
                Set pFeature = pfeaturecursor.NextFeature
        Loop
   
    ElseIf layername = "aspect" Then
           
        Dim valuefieldvalue2 As Integer
        valuefieldvalue2 = pFeatureLayer.FeatureClass.FindField("value")

        Dim aspectfieldvalue2 As String
        aspectfieldvalue2 = pFeatureLayer.FeatureClass.FindField("aspect")

        Do Until pFeature Is Nothing
            Me.ListBox.AddItem pFeature.Value(valuefieldvalue)
            'Me.ListBox.AddItem pFeature.Value(aspectfieldvalue)
            Set pFeature = pfeaturecursor.NextFeature
        Loop
    End If
  
End Sub

Outcomes