Select to view content in your preferred language

ArcGIS Engine 10 : VB.NET Implicit Conversion Problem

996
2
Jump to solution
07-05-2012 07:47 PM
Nik_Mohd_FadhilNik_Mohd_Kamil
Emerging Contributor
Hey folk of greater ArcObjects Wisdom than I,  how can I handle the errors regarding the implicit conversion? Below is example of code that I working at right now. Please help me 😞

Private Sub zoomFeature(ByVal objectID As String)         Dim pQueryFilter As IQueryFilter         Dim pFeatureLayer As IFeatureLayer         Dim pFeatureSelection As IFeatureSelection         Dim pLayer As ILayer         Dim intCount As Integer         For intCount = 0 To AxMapControl1.LayerCount - 1             pLayer = AxMapControl1.Map.Layer(intCount)             If TypeOf pLayer Is IFeatureLayer Then                 pFeatureLayer = pLayer '<---Implicit conversion from 'ESRI.ArcGIS.Carto.ILayer' to 'ESRI.ArcGIS.Carto.IFeatureLayer'                 pFeatureSelection = pFeatureLayer '<---Implicit conversion from 'ESRI.ArcGIS.Carto.IFeatureLayer' to 'ESRI.ArcGIS.Carto.IFeatureSelection'                 If pFeatureLayer.Name = "DistrictBoundary" Then                     'Create the query filter                     pQueryFilter = New QueryFilter '<---Implicit conversion from 'ESRI.ArcGIS.Geodatabase.QueryFilterClass' to 'MapControlApplication1.QueryFilter'                     pQueryFilter.WhereClause = "OBJECTID = " & objectID '<--- 'WhereClause' is not a member of 'MapControlApplication1.QueryFilter'                     AxMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, Nothing, Nothing)                     pFeatureSelection.SelectFeatures(pQueryFilter, esriSelectionResultEnum.esriSelectionResultNew, False) '<---Implicit conversion from 'MapControlApplication1.QueryFilter' to 'ESRI.ArcGIS.Geodatabase.IQueryFilter'                 End If             End If End Sub
0 Kudos
1 Solution

Accepted Solutions
2 Replies
RichardWatson
Deactivated User
0 Kudos
Nik_Mohd_FadhilNik_Mohd_Kamil
Emerging Contributor
Cast?

http://www.codeproject.com/Articles/5044/Cheat-Sheet-Casting-in-VB-NET-and-C


Thanks Richard, it's help! Below are the change that I made and it work pretty well.

Add 'Option Strict Off' on top of code as shown below.
Option Strict Off
Imports System.Data.OleDb
Imports System.Drawing
.....


The correct casting

Private Sub SelectFeatureZoom(ByVal NAM As String)
        Dim pQueryFilter As ESRI.ArcGIS.Geodatabase.IQueryFilter = New ESRI.ArcGIS.Geodatabase.QueryFilterClass
        Dim pFeatureLayer As IFeatureLayer
        Dim pFeatureSelection As IFeatureSelection
        Dim pLayer As ILayer
        Dim intCount As Integer
        For intCount = 0 To AxMapControl1.LayerCount - 1
            pLayer = AxMapControl1.Map.Layer(intCount)
            If TypeOf pLayer Is IFeatureLayer Then
                pFeatureLayer = pLayer
                pFeatureSelection = pFeatureLayer
                If pFeatureLayer.Name = "DistrictBoundary" Then
                    'Create the query filter & select feature 
                    pQueryFilter.WhereClause = " NAM = " & "'" & ComboBox1.Text & "'"
                    AxMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, Nothing, Nothing)
                    pFeatureSelection.SelectFeatures(pQueryFilter, esriSelectionResultEnum.esriSelectionResultNew, False) 
                End If
            End If
        Next
        'Then Zoom
        Dim pFeature As IFeature
        Dim pEnvelope As IEnvelope
        Dim pArea As IArea
        Dim pEnumFeat As IEnumFeature
        pEnumFeat = AxMapControl1.ActiveView.FocusMap.FeatureSelection
        pFeature = pEnumFeat.Next
        pEnvelope = pFeature.Shape.Envelope.Envelope
        If pFeature.Shape.GeometryType = esriGeometryType.esriGeometryPoint Or (pEnvelope.Width = 0 And pEnvelope.Height = 0) Then
            If AxMapControl1.ActiveView.FocusMap.ReferenceScale <> 0.0 Then
                AxMapControl1.ActiveView.FocusMap.MapScale = AxMapControl1.ActiveView.FocusMap.ReferenceScale / 3
                pEnvelope = AxMapControl1.ActiveView.Extent
                pArea = pFeature.Shape.Envelope
                pEnvelope.CenterAt(pArea.Centroid)
            Else
                pEnvelope = AxMapControl1.ActiveView.Extent
                pArea = pFeature.Shape.Envelope
                pEnvelope.CenterAt(pArea.Centroid)
                pEnvelope.Expand(2, 2, True)
            End If
            AxMapControl1.ActiveView.Extent = pEnvelope
            AxMapControl1.ActiveView.Refresh()
        Else
            AxMapControl1.ActiveView.Extent = pFeature.Extent
            AxMapControl1.ActiveView.Refresh()
        End If
    End Sub


Thanks again and have a great weekend everyone!
0 Kudos