VBA Code to VB.NET

713
1
05-21-2010 02:12 PM
KavinLai
New Contributor
Hi, I currently have the codes below for ArcGIS VBA. When the button is clicked, a label would be added to the selected feature. Specifically a country name would be added to the world map. However, I have limited knowledge working with Visual Studio 2008, and I was asked to convert these codes into working codes for Visual Studio 2008. I know that it will not work if I just copy and paste it.

Any help would be great. Thanks


Private Sub UIButtonControl3_Click()
'Get the focus map
Dim pDoc As IMxDocument
Set pDoc = ThisDocument
Dim pMap As IMap
Set pMap = pDoc.FocusMap

' Get the selected layer
Dim pLayer As IGeoFeatureLayer
Set pLayer = pDoc.SelectedLayer
' Make sure a layer was selected
  If pLayer Is Nothing Then
    MsgBox "You must select a Layer to Label"
    Exit Sub
  End If

' Get the feature class to get the correct
' oid field name for the data type (oid,fid,objectid)
Dim pFc As IFeatureClass
Dim strOIDName As String
Set pFc = pLayer.FeatureClass
strOIDName = pFc.OIDFieldName

' Get the selected features from the layer
Dim pFSel As IFeatureSelection
Set pFSel = pLayer
Dim pSelSet As ISelectionSet
Set pSelSet = pFSel.SelectionSet
Dim pFCur As IFeatureCursor
pSelSet.Search Nothing, False, pFCur
' Loop through the selected features and create a label
' expression for the selected features
Dim pFeat As IFeature
Dim strSql As String
Set pFeat = pFCur.NextFeature
  Do While Not pFeat Is Nothing
    If strSql = "" Then
      strSql = strOIDName & " = " & pFeat.OID
    Else
      strSql = strSql & " or " & strOIDName & " = " & pFeat.OID
    End If
    Set pFeat = pFCur.NextFeature
  Loop
Debug.Print strSql

' Get AnnotateLayerPropertiesCollection from layer
Dim pAnnoLayerPropsColl As IAnnotateLayerPropertiesCollection
Set pAnnoLayerPropsColl = pLayer.AnnotationProperties
Dim pAnnoLayerProps As IAnnotateLayerProperties
pAnnoLayerPropsColl.QueryItem 0, pAnnoLayerProps, Nothing, Nothing
pAnnoLayerProps.Class = "LabelSel"
pAnnoLayerProps.WhereClause = strSql
' Display the lables
pLayer.DisplayAnnotation = True
' Refresh the Data Frame
pDoc.ActiveView.Refresh

End Sub
0 Kudos
1 Reply
JamesCrandall
MVP Frequent Contributor
http://resources.esri.com/arcgisdesktop/dotnet/index.cfm

Has walk-thru's and just about everything you'll need to get going.

Good Luck!
0 Kudos