This document is archived and information here might be outdated.  Recommended version.


Walkthrough: Migrating VB6 to VB.NET for ArcGIS 10 (ArcObjects .NET 10.4 SDK)

Migrating VB6 to VB.NET for ArcGIS 10


Summary
To successfully convert Visual Basic 6 (VB6) code to Visual Basic .NET (VB.NET) requires modifications. There is no completely automated, error-free way to upgrade from VB6 to VB.NET. This topic provides an example of how the conversion process might work. The original VB6 project has the functionality of copying a selected set of records in an ArcMap table to the Clipboard, which can then be pasted into a basic text editor, such as Notepad.
This topic focuses on migrating a basic ArcMap command from VB6 to VB.NET. Emphasis is on the mechanics of the conversion process, creating a functionally equivalent VB.NET project from the original VB6 version, and improving the VB.NET project to take advantage of .NET coding best practices.
To bring the customization into the latest Esri programming practices, two options using the Esri Visual Studio Integration tools are demonstrated to advance the code. The first option uses the Esri base class features and the second option uses the Esri add-in feature introduced with ArcGIS 10.

Click here to get the sample associated with this walkthrough.

In this topic


About migrating VB6 to VB.NET for ArcGIS 10

This topic is specifically for VB6 customizations built in ArcGIS 9.0 to 9.3.1 that need to be migrated to VB.NET in ArcGIS 10. There are some important differences in ArcGIS 10 from prior versions of ArcGIS that are outlined in this topic.
For a similar topic for VB6 customizations migrated to VB.NET for ArcGIS 9.0 to 9.3.1, see How to migrate from VB6 to VB.NET (copying table selection).

Obtaining supporting data

This topic shows how to convert a customized ArcMap command created in ArcGIS 9.0 to 9.3.1 using VB6, to ArcGIS 10 using VB.NET. To follow the steps in this topic, you need the required files, which are in the following location:
  • <Your ArcGIS install location>\DeveloperKit10.0\samples\ArcObjectsNET\CopyTableSelection
The following is the ArcObjects .NET software development kit (SDK) default install location:
  • C:\Program Files\ArcGIS\DeveloperKit10.0\samples\ArcObjectsNET\CopyTableSelection
The following are the six associated project folders:
  • <Your ArcGIS developer kit install location>\samples\ArcObjectsNET\CopyTableSelection\VBNet\VB6
  • <Your ArcGIS developer kit install location>\samples\ArcObjectsNET\CopyTableSelection\VBNet\VBNet_AddIn_2008
  • <Your ArcGIS developer kit install location>\samples\ArcObjectsNET\CopyTableSelection\VBNet\VBNet_BaseClass_2008
  • <Your ArcGIS developer kit install location>\samples\ArcObjectsNET\CopyTableSelection\VBNet\VBNet_Equivalency_2008
  • <Your ArcGIS developer kit install location>\samples\ArcObjectsNET\CopyTableSelection\VBNet\VBNet_UpgradeRaw_2008
  • <Your ArcGIS developer kit install location>\samples\ArcObjectsNET\CopyTableSelection\VBNet\VBNet_Standards_2008
Create a test location to complete the steps in this topic for easier navigation and to preserve the original code. In this topic, you will create the high-level folder, C:\CaseStudy1\CopyTableSelection\VBNet. In the remainder of this topic, C:\CaseStudy1\CopyTableSelection\VBNet will be referred to as <your test location>.
Copy the <Your ArcGIS developer kit install location>\samples\ArcObjectsNET\CopyTableSelection\VBNet\VB6 folder structure to <your test location>.
Do not copy and compile the remaining folders in <Your ArcGIS developer kit install location>\samples\ArcObjectsNET\CopyTableSelection that begin with VBNet_ to <your test location>. These other project folders are for reference and will be created when working through this topic.
By not compiling the projects that begin with <Your ArcGIS developer kit install location>\samples\ArcObjectsNET\CopyTableSelection\VBNet\VBNet_ projects, duplicate Component Object Model (COM) registration entries will be avoided to prevent problems during debugging.

Understanding the VB6 project

Understanding how your VB6 project works is critical to a successful migration to VB.NET in ArcGIS 10. Only test VB6 projects on a computer with ArcGIS 9.3.1 and earlier. VB6 customizations are not supported on a computer with ArcGIS 10. For more information, see Migrating from VB6 to VB.NET.
In the VB6 development project, you need to know the references that are used. This information is necessary after the VB6 project has been auto-translated as part of Visual Studio.
In the sample VB6 project provided in this topic (<your test location>\VB6\copy_table_sel.vbp), the references on the following screen shot were required:

The VB6 custom component for this sample demonstrates a limited set of ArcObjects functionality. The functionality of the VB6 sample is to enable a user who has a selected set of attribute records to copy to the Clipboard, so they can be copied into another basic text editor, such as Notepad.
For developers who have ArcMap 9.3.1 and want to test the functionality of the VB6 application, do the following steps:
  1. Start ArcMap to test the VB6 .dll.
  2. Click the Tools menu and choose Customize. The Customize dialog box appears.
  3. Click the Add from file button and browse to the <your test location>\VB6\CopyTableSelectedVB6.dll file.
  4. Select the (CopyTableSelectedVB6.dll) file and click Open. Click the Commands tab, then scroll down and click Developer Samples under the Categories section. See the following screen shot:
  1. Drag the Copy Table Selection VB6 command onto the ArcMap graphical user interface (GUI).
  2. Open the attribute table of a feature layer and select some records to use the Copy Table Selection VB6 command.
  3. Click the Copy Table Selection VB6 command to copy the selected records to the Clipboard.
  4. Start a basic text editor, such as Notepad, and paste the contents to the Clipboard.

Performing the raw conversion from VB6 to VB.NET

Do the following steps for the raw conversion from VB6 to VB.NET on a computer with ArcGIS 10:
  1. Start Visual Studio 2008.
  2. Click File, Open, then Project/Solution. The Open Project dialog box appears. Browse to <your test location>\VB6\copy_table_sel.vbp, which starts the Visual Basic Upgrade Wizard series of dialog boxes. See the following screen shot:
  3. Click Next on Page 1 of 5.
  4. Click Next on Page 2 of 5.
  5. Click Browse on Page 3 of 5 and specify the folder <your test location>\CopyTableSelection\VBNet\VBNet_UpgradeRaw_2008, then click Next.
  6. Click Next on Page 4 of 5, then wait while the upgrade completes.
  7. When the conversion is complete, rename the Visual Basic project file on disk to distinguish it clearly from the VB6 project. To do this, rename the Project File property on the properties window to VBNet_CopyTableSel_2008.vbproj. See the following screen shot:
  8. The final step in the raw conversion is to save the Visual Studio project, which creates a solution file (.sln). Name the file VBNet_CopyTableSel_2008. See the following screen shot:

Creating a VB.NET functional equivalent project

Create the functional equivalent project on a computer with ArcGIS 10. The following are four areas that need to be completed to create a VB.NET functional equivalent of the VB6 customization:
  • Make a copy of the original raw converted project to perform the changes and view resulting errors and warnings.
  • Modify the necessary code files to fix the errors and warnings.
  • Make project level adjustments.
  • Perform the equivalency testing.

Copying the project to review errors and warnings

Do the following steps to copy the original raw converted project to perform the changes, then view resulting errors and warning:
  1. Create a copy of the <your test location>\VBNet_UpgradeRaw_2008 folder, then create another folder to perform the edits. In this example, create <your test location>\VBNet_Equivalency_2008.
  2. Open the <your test location>\VBNet_Equivalency_2008\VBNet_CopyTableSel_2008.sln project.
  3. Click the Build menu and choose Build Solution. The Visual Basic project that generates will not compile. The project has errors that must be corrected to have equivalent functionality. See the following screen shot:

Modifying code to fix errors and warnings

Review the following for changes that need to be made to correct the errors and warnings as a result of the compile, then make the appropriate code changes:
  1. There are several places in the VB.NET code file, clscopy_table_sel.vb, that need correcting. Only the bare minimum will be changed at this point to fix the errors and warning messages to create a functionally equivalent VB.NET version of the VB6 customization. The specific code changes include the following:
    1. Renaming the ProgID so there is no conflict between the VB6 and VB.NET versions of the customization.
    2. Changing the return type of the property ICommand_Bitmap from ESRI.ArcGIS.esriSystem.OLE_HANDLE to System.Int32.
    3. Modifying the Property ICommand_Caption, Property ICommand_Message, Property ICommand_Name, and Property ICommand_Tooltip to distinguish between the VB6 and VB.NET versions of the customization.
    4. Adding an empty return string to the Property ICommand_HelpFile.
    5. Commenting out the use of the pFld variable in the Sub Copy.
    6. Setting the pCur variable to equal Nothing during its instantiation in the Sub Copy.
    7. Initializing the strR variable to an empty string during its instantiation in the Sub Copy.
    8. Correcting an ArcMap framework level change that occurred between ArcGIS 9.3 and 10. The attribute table window is no longer a data window but rather a  dockable window. As a result, a different set of ArcObjects calls to the new ArcGIS 10 interface—ITableWindow3—using the .FindOpenTableWindows method is needed to get the ITableWindow object.

    The following code example shows the un-modified raw converted code for clscopy_table_sel.vb:
[VB.NET]
Option Strict Off
Option Explicit On
<System.Runtime.InteropServices.ProgId("cldcopy_table_sel_NET.cldcopy_table_sel")> Public Class cldcopy_table_sel
    Implements ESRI.ArcGIS.SystemUI.ICommand
    
    Private m_pApp As ESRI.ArcGIS.Framework.IApplication
    Private m_pMXDoc As ESRI.ArcGIS.ArcMapUI.IMxDocument
    Private m_pWorkSpace As ESRI.ArcGIS.Geodatabase.IWorkspace
    Private m_pTableView As ESRI.ArcGIS.GeoDatabaseUI.ITableView2
    
    Private ReadOnly Property ICommand_Bitmap() As ESRI.ArcGIS.esriSystem.OLE_HANDLE Implements ESRI.ArcGIS.SystemUI.ICommand.Bitmap
    Get
    End Get
End Property

Private ReadOnly Property ICommand_Caption() As String Implements ESRI.ArcGIS.SystemUI.ICommand.Caption
Get
ICommand_Caption="Copy Table Selection VB6"
End Get
End Property

Private ReadOnly Property ICommand_Category() As String Implements ESRI.ArcGIS.SystemUI.ICommand.Category
Get
ICommand_Category="Developer Samples"
End Get
End Property

Private ReadOnly Property ICommand_Checked() As Boolean Implements ESRI.ArcGIS.SystemUI.ICommand.Checked
Get
End Get
End Property

Private ReadOnly Property ICommand_Enabled() As Boolean Implements ESRI.ArcGIS.SystemUI.ICommand.Enabled
Get

' Make it enabled if it is in a table context menu.
ICommand_Enabled=False

Dim pAppWindows As ESRI.ArcGIS.ArcMapUI.IApplicationWindows
Dim pWindowSet As ESRI.ArcGIS.esriSystem.ISet
Dim pDataWindow As ESRI.ArcGIS.ArcMapUI.IDataWindow
Dim pTableWindow As ESRI.ArcGIS.ArcMapUI.ITableWindow
Dim pTableControl As ESRI.ArcGIS.GeoDatabaseUI.ITableControl
Dim pSelSet As ESRI.ArcGIS.Geodatabase.ISelectionSet

pAppWindows=m_pApp
pWindowSet=pAppWindows.DataWindows
pWindowSet.Reset()
pDataWindow=pWindowSet.Next
Do Until pDataWindow Is Nothing
    'UPGRADE_WARNING: TypeOf has a new behavior. Click for more: 'MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'.
    If TypeOf pDataWindow Is ESRI.ArcGIS.ArcMapUI.TableWindow Then
        pTableWindow=pDataWindow
        pTableControl=pTableWindow.TableControl
        m_pTableView=pTableControl
        pSelSet=m_pTableView.SelectionSet
        If pSelSet.Count > 0 Then
            ICommand_Enabled=True
        End If
    End If
    pDataWindow=pWindowSet.Next
Loop

End Get
End Property

Private ReadOnly Property ICommand_HelpContextID() As Integer Implements ESRI.ArcGIS.SystemUI.ICommand.HelpContextID
Get
End Get
End Property

Private ReadOnly Property ICommand_HelpFile() As String Implements ESRI.ArcGIS.SystemUI.ICommand.HelpFile
Get
End Get
End Property

Private ReadOnly Property ICommand_Message() As String Implements ESRI.ArcGIS.SystemUI.ICommand.Message
Get
ICommand_Message="Copies the selected records in the table window VB6"
End Get
End Property

Private ReadOnly Property ICommand_Name() As String Implements ESRI.ArcGIS.SystemUI.ICommand.Name
Get
ICommand_Name="Developer Samples_Copy Table Selection VB6"
End Get
End Property

Private ReadOnly Property ICommand_Tooltip() As String Implements ESRI.ArcGIS.SystemUI.ICommand.Tooltip
Get
ICommand_Tooltip="Validate Table Selection VB6"
End Get
End Property

Private Sub ICommand_OnClick() Implements ESRI.ArcGIS.SystemUI.ICommand.OnClick
    Copy()
End Sub

Private Sub ICommand_OnCreate(ByVal hook As Object) Implements ESRI.ArcGIS.SystemUI.ICommand.OnCreate
    m_pApp=hook
    m_pMXDoc=m_pApp.Document
End Sub

'################### Private Routines

Private Sub Copy()
    
    ' Get the selection from the table.
    Dim pInSelSet As ESRI.ArcGIS.Geodatabase.ISelectionSet
    Dim pTable As ESRI.ArcGIS.Geodatabase.ITable
    pInSelSet=m_pTableView.SelectionSet
    pTable=m_pTableView.Table
    
    Dim pCur As ESRI.ArcGIS.Geodatabase.ICursor
    Dim pRow As ESRI.ArcGIS.Geodatabase.IRowBuffer
    Dim pFlds As ESRI.ArcGIS.Geodatabase.IFields
    Dim pFld As ESRI.ArcGIS.Geodatabase.IField
    Dim iCnt As Short
    Dim iind As Short
    pInSelSet.Search(Nothing, False, pCur)
    pRow=pCur.NextRow
    Dim strR As String
    pFlds=pRow.Fields
    iCnt=pFlds.FieldCount
    Do Until pRow Is Nothing
        For iind=0 To iCnt - 1
            If Not TypeOf pRow.Value(iind) Is ESRI.ArcGIS.Geometry.IGeometry Then
                'UPGRADE_WARNING: Couldn't resolve default property of object pRow.Value(). Click for more: 'MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'.
                strR=strR & pRow.Value(iind) & ","
            End If
        Next iind
        strR=Left(strR, Len(strR) - 1) ' Remove the trailing comma.
        strR=strR & vbNewLine
        pRow=pCur.NextRow
    Loop
    
    My.Computer.Clipboard.Clear()
    My.Computer.Clipboard.SetText(strR)
    
End Sub

End Class
  1. Change the code in the clscopy_table_sel.vb file to the following code example to fix all errors and warning messages:
[VB.NET]
Option Strict Off
Option Explicit On
<System.Runtime.InteropServices.ProgId("clscopy_table_sel_NET.clscopy_table_sel_NET")> Public Class clscopy_table_sel
    Implements ESRI.ArcGIS.SystemUI.ICommand
    
    Private m_pApp As ESRI.ArcGIS.Framework.IApplication
    Private m_pMXDoc As ESRI.ArcGIS.ArcMapUI.IMxDocument
    Private m_pWorkSpace As ESRI.ArcGIS.Geodatabase.IWorkspace
    Private m_pTableView As ESRI.ArcGIS.GeoDatabaseUI.ITableView2
    
    Private ReadOnly Property ICommand_Bitmap() As System.Int32 Implements ESRI.ArcGIS.SystemUI.ICommand.Bitmap
    Get
    End Get
End Property

Private ReadOnly Property ICommand_Caption() As String Implements ESRI.ArcGIS.SystemUI.ICommand.Caption
Get
ICommand_Caption="Copy Table Selection VB2008"
End Get
End Property

Private ReadOnly Property ICommand_Category() As String Implements ESRI.ArcGIS.SystemUI.ICommand.Category
Get
ICommand_Category="Developer Samples"
End Get
End Property

Private ReadOnly Property ICommand_Checked() As Boolean Implements ESRI.ArcGIS.SystemUI.ICommand.Checked
Get
End Get
End Property


Private ReadOnly Property ICommand_Enabled() As Boolean Implements ESRI.ArcGIS.SystemUI.ICommand.Enabled

Get
' Make it enabled if it is in a table context menu.
ICommand_Enabled=False

Dim pAppWindows As ESRI.ArcGIS.ArcMapUI.IApplicationWindows
Dim pWindowSet As ESRI.ArcGIS.esriSystem.ISet=Nothing
Dim pTableWindow As ESRI.ArcGIS.ArcMapUI.ITableWindow
Dim pTableControl As ESRI.ArcGIS.GeoDatabaseUI.ITableControl
Dim pSelSet As ESRI.ArcGIS.Geodatabase.ISelectionSet
Dim pTableWindow3 As ESRI.ArcGIS.ArcMapUI.ITableWindow3

pTableWindow3=New ESRI.ArcGIS.ArcMapUI.TableWindow()
pTableWindow3.FindOpenTableWindows(pWindowSet)
pAppWindows=m_pApp
pWindowSet.Reset()
pTableWindow=pWindowSet.Next

Do Until pTableWindow Is Nothing
    pTableControl=pTableWindow.TableControl
    m_pTableView=pTableControl
    pSelSet=m_pTableView.SelectionSet
    If pSelSet.Count > 0 Then
        ICommand_Enabled=True
    End If
    pTableWindow=pWindowSet.Next
Loop
End Get
End Property

Private ReadOnly Property ICommand_HelpContextID() As Integer Implements ESRI.ArcGIS.SystemUI.ICommand.HelpContextID
Get
End Get
End Property

Private ReadOnly Property ICommand_HelpFile() As String Implements ESRI.ArcGIS.SystemUI.ICommand.HelpFile
Get
Return ""
End Get
End Property

Private ReadOnly Property ICommand_Message() As String Implements ESRI.ArcGIS.SystemUI.ICommand.Message
Get
ICommand_Message="Copies the selected records in the table window VB2008"
End Get
End Property

Private ReadOnly Property ICommand_Name() As String Implements ESRI.ArcGIS.SystemUI.ICommand.Name
Get
ICommand_Name="Developer Samples_Copy Table Selection VB2008"
End Get
End Property

Private ReadOnly Property ICommand_Tooltip() As String Implements ESRI.ArcGIS.SystemUI.ICommand.Tooltip
Get
ICommand_Tooltip="Validate Table Selection VB2008"
End Get
End Property

Private Sub ICommand_OnClick() Implements ESRI.ArcGIS.SystemUI.ICommand.OnClick
    Copy()
End Sub

Private Sub ICommand_OnCreate(ByVal hook As Object) Implements ESRI.ArcGIS.SystemUI.ICommand.OnCreate
    m_pApp=hook
    m_pMXDoc=m_pApp.Document
End Sub

'################### Private Routines

Private Sub Copy()
    ' Get the selection from the table.
    Dim pInSelSet As ESRI.ArcGIS.Geodatabase.ISelectionSet
    Dim pTable As ESRI.ArcGIS.Geodatabase.ITable
    pInSelSet=m_pTableView.SelectionSet
    pTable=m_pTableView.Table
    
    Dim pCur As ESRI.ArcGIS.Geodatabase.ICursor=Nothing
    Dim pRow As ESRI.ArcGIS.Geodatabase.IRowBuffer
    Dim pFlds As ESRI.ArcGIS.Geodatabase.IFields
    'Dim pFld As ESRI.ArcGIS.Geodatabase.IField.
    Dim iCnt As Short
    Dim iind As Short
    pInSelSet.Search(Nothing, False, pCur)
    pRow=pCur.NextRow
    Dim strR As String=""
    pFlds=pRow.Fields
    iCnt=pFlds.FieldCount
    Do Until pRow Is Nothing
        For iind=0 To iCnt - 1
            If Not TypeOf pRow.Value(iind) Is ESRI.ArcGIS.Geometry.IGeometry Then
                'UPGRADE_WARNING: Couldn't resolve default property of object pRow.Value(). Click for more: 'MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'.
                strR=strR & pRow.Value(iind) & ","
            End If
        Next iind
        strR=Left(strR, Len(strR) - 1) ' Remove the trailing comma.
        strR=strR & vbNewLine
        pRow=pCur.NextRow
    Loop
    
    My.Computer.Clipboard.Clear()
    My.Computer.Clipboard.SetText(strR)
End Sub

End Class

Adjusting project level changes

Now that all of the code changes have been made, continue with the following project level changes to complete a successful compile of the customization:
  1. When the upgrade wizard was used, extraneous references were added to the project. The upgrade wizard reviews all references used in the VB6 project and automatically adds any dependency references; thereby, adding the extraneous ones. Additionally, the Esri references that are added, point to references in the Windows Global Assembly Cache (GAC) as part of the upgrade wizard. Only use the references provided as part of the ArcObjects .NET SDK that are installed in the developer kit folder.
    1. On the Solution Explorer, remove the Esri references that were automatically added, then add the ones needed from the Esri ArcObjects .NET SDK install folder (the default install location for the developer kit version of the Esri assemblies is C:\Program Files\ArcGIS\DeveloperKit10.0\DotNet). Only the following references are necessary for a successful compile without errors or warnings: 
      • ESRI.ArcGIS.ArcMap
      • ESRI.ArcGIS.ArcMapUI
      • ESRI.ArcGIS.Framework
      • ESRI.ArcGIS.Geodatbase
      • ESRI.ArcGIS.GeodatabaseUI
      • ESRI.ArcGIS.Geometry
      • ESRI.ArcGIS.System
      • ESRI.ArcGIS.SystemUI
      • System 
      • System.Data 
      • System.Drawing
      • System.Windows.Forms
      • System.XML
    2. Ensure that any Esri assemblies have the Specific Version property set to False. Do this by selecting all Esri assemblies on the Solution Explorer and by setting the Specific Version property to False on the Properties window. See the following screen shot:
  1. Click the Project menu, then select VBNet_CopyTableSel_2008 properties.
  2. Click the Application tab. 
  3. Type VBNet_CopyTableSel_2008 in the Assembly name text field, then type VBNet_CopyTableSel_2008 in the Root namespace text field. When the project compiles, it creates VBNet_CopyTableSel_2008.dll and VBNet_CopyTableSel_2008.tlb. See the following screen shot:
  4. Click the Debug tab. Specify the start external program to be the appropriate location for the ArcMap executable (.exe). For ArcGIS 10, the default location is C:\Program Files\ArcGIS\Desktop10.0\bin\ArcMap.exe. See the following screen shot:
  5. Click the Compile tab and select the Register for COM interop check box. See the following screen shot:
  6. Click the References tab. Under the Imported namespaces section, clear the Microsoft.VisualBasic.Compatibility check box. See the following screen shot:
  7. On the Solution Explorer, delete the following files that reported information about the upgrade process (these files were automatically added during the conversion upgrade):
    • _UpgradedReport_Files
    • _UpgradeReport.htm
    • copy_table_sel.log 
If all of the files do not show on the following screen shot, click the Show All Files button on the Solution Explorer.
See the following screen shot:

  1. Click the Build menu, then Rebuild Solution to rebuild the project and verify there are no errors or warning messages.

Performing equivalency testing

Do the following steps to test that the VB.NET project is functionally equivalent to the VB6 version:
  1. Click the Start Debugging button. The ArcMap application starts.
  2. In ArcMap, click Customize, then Customize mode. The Customize dialog box appears.
  3. Click the Add from file button and browse to the
    <your test location>\VBNet_Equivalency_2008\bin folder.
  4. Select the VBNet_CopyTableSel_2008.tlb file.
  5. Click Open.
  6. Click the Commands tab, scroll down, then click Developer Samples under the Categories section.
  7. Click, then drag the Copy Table Selection VB2008 command onto the ArcMap GUI.
  8. Open the attribute table of a feature layer and select some records to use the Copy Table Selection VB2008 command.
  9. Click the Copy Table Selection VB2008 command to copy the selected records to the Clipboard.
  10. Start a basic text editor, such as Notepad, and paste the contents to the Clipboard.

Improving the VB2008 project to conform to .NET standards

Do the revised project that conforms to VB.NET standards on a computer with ArcGIS 10.
At this point, only necessary modifications were made to generate an equivalent VB.NET version of the original VB6 customization. As you move to a different development language, write code using the standards for that language.
This section provides an example of how to modify the relevant code base to bring it into conformity with VB.NET coding practices. Do the following to create a VB.NET standards version of the VB6 customization:
  • Make a copy of the functional equivalent VB.NET project to perform the changes for .NET standards.
  • Modify the necessary code files.
  • Perform the testing.

Copying the project to code for VB.NET standards

Do the following steps to make a copy of the equivalency project and create a version for coding the VB.NET standards:
  1. Create a copy of the <your test location>\VBNet_Equivalency_2008 folder, then create another folder to do the edits. In this example, create <your test location>\VBNet_Standards_2008.
  2. Open the <your test location>\VBNet_Standards_2008\VBNet_CopyTableSel_2008.sln project.

Modifying the code

Review the following for changes that need to be made to update the project and use the best practices for VB.NET, then make the appropriate code changes. Use the following .NET standards in the <your test location>\VBNet_Standards_2008\VBNet_CopyTableSel_2008.sln project:
  • Set Option Strict to equal On to catch potential casting errors.
  • Remove the letter "p" at the beginning of every variable name. Pointers are not used by .NET managed code.
  • Declare and instantiate objects on the same line of code where possible to make the code more readable and eliminate variables that are unused.
  • Do not declare and use an object until it is needed in the code, that is, do not declare all the variables at the top of each method (this is a good way to eliminate variables that are never used).
  • Use Imports statements to shorten the length of coding statements.
  • Use Return statements instead of the function and property name for returning variables.
  • Comment the code.
  • Eliminate unused variables.
  • Use Member (also known as, Global) variables judiciously.
  • Restructure the business logic of the code to provide a more understandable flow.

    As a result, modify clscopy_table_sel.vb file to look like the following code example:
[VB.NET]
Option Strict On
Option Explicit On

Imports ESRI.ArcGIS.Framework
Imports ESRI.ArcGIS.ArcMapUI
Imports ESRI.ArcGIS.Geodatabase
Imports ESRI.ArcGIS.GeoDatabaseUI
Imports ESRI.ArcGIS.esriSystem
Imports ESRI.ArcGIS.Geometry
<System.Runtime.InteropServices.ProgId("clscopy_table_sel_NET_Standards.clscopy_table_sel_Standards")> Public Class clscopy_table_sel
    Implements ESRI.ArcGIS.SystemUI.ICommand
    
    Private m_application As IApplication
    Private m_tableView2 As ITableView2
    
    Private ReadOnly Property ICommand_Bitmap() As System.Int32 Implements ESRI.ArcGIS.SystemUI.ICommand.Bitmap
    Get
    Return Nothing
    End Get
End Property

Private ReadOnly Property ICommand_Caption() As String Implements ESRI.ArcGIS.SystemUI.ICommand.Caption
Get
Return "Copy Table Selection VB2008 Standards"
End Get
End Property

Private ReadOnly Property ICommand_Category() As String Implements ESRI.ArcGIS.SystemUI.ICommand.Category
Get
Return "Developer Samples"
End Get
End Property

Private ReadOnly Property ICommand_Checked() As Boolean Implements ESRI.ArcGIS.SystemUI.ICommand.Checked
Get
Return Nothing
End Get
End Property

Private ReadOnly Property ICommand_Enabled() As Boolean Implements ESRI.ArcGIS.SystemUI.ICommand.Enabled
Get

'Create an instance of TableWindowClass using the ITableWindow3 interface.
Dim tableWindow3 As ITableWindow3=New TableWindowClass

'Create an empty ISet to hold the open table windows.
Dim windowSet As ISet=Nothing

'The .FindOpenTableWindows populates the windowSet object byRef.
tableWindow3.FindOpenTableWindows(windowSet)

'Go to the first item in the ISet.
windowSet.Reset()

'Cast the first ISet object to an ITableWindow.
Dim tableWindow As ITableWindow=CType(windowSet.Next, ITableWindow)

'Loop through the tableWindows.
Do Until tableWindow Is Nothing
    
    'Get the TableControl from the TableWindow.
    Dim tableControl As ITableControl=tableWindow.TableControl
    
    'Set the member (also known as, Global) variable ITableView2 interface.
    m_tableView2=CType(tableControl, ITableView2)
    
    'If you have selected records, enable the command.
    Dim selectionSet As ISelectionSet=m_tableView2.SelectionSet
    
    If selectionSet.Count > 0 Then
        Return True
    End If
    
    'Iterate over the next ArcMap Window.
    tableWindow=CType(windowSet.Next, ITableWindow)
Loop

'If TableWindow is not found, disable the command.
Return False

End Get
End Property

Private ReadOnly Property ICommand_HelpContextID() As Integer Implements ESRI.ArcGIS.SystemUI.ICommand.HelpContextID
Get
Return Nothing
End Get
End Property

Private ReadOnly Property ICommand_HelpFile() As String Implements ESRI.ArcGIS.SystemUI.ICommand.HelpFile
Get
Return Nothing
End Get
End Property

Private ReadOnly Property ICommand_Message() As String Implements ESRI.ArcGIS.SystemUI.ICommand.Message
Get
Return "Copies the selected records in the table window VB2008 Standards"
End Get
End Property

Private ReadOnly Property ICommand_Name() As String Implements ESRI.ArcGIS.SystemUI.ICommand.Name
Get
Return "Developer Samples_Copy Table Selection VB2008 Standards"
End Get
End Property

Private ReadOnly Property ICommand_Tooltip() As String Implements ESRI.ArcGIS.SystemUI.ICommand.Tooltip
Get
Return "Validate Table Selection VB2008 Standards"
End Get
End Property

Private Sub ICommand_OnClick() Implements ESRI.ArcGIS.SystemUI.ICommand.OnClick
    Copy()
End Sub

Private Sub ICommand_OnCreate(ByVal hook As Object) Implements ESRI.ArcGIS.SystemUI.ICommand.OnCreate
    m_application=CType(hook, IApplication)
End Sub

Private Sub Copy()
    
    ' Get the selection from the table.
    Dim selectionSet As ISelectionSet=m_tableView2.SelectionSet
    Dim table As ITable=m_tableView2.Table
    Dim cursor As ICursor=Nothing
    
    'Load the selection results into the cursor object.
    selectionSet.Search(Nothing, False, cursor)
    
    'Get the first row of the cursor.
    Dim rowBuffer As IRowBuffer=cursor.NextRow
    
    'Initialize the returnString to be empty.
    Dim returnString As String=""
    
    'Obtain all of the fields in the table.
    Dim fields As IFields=rowBuffer.Fields
    
    'Loop through all of the rows.
    Dim Count As Integer=fields.FieldCount
    Do Until rowBuffer Is Nothing
        
        'Loop through all of the fields.
        Dim index As Integer
        For index=0 To Count - 1
            If Not TypeOf rowBuffer.Value(index) Is IGeometry Then
                'Extract the strings from each field in the table row.
                returnString=returnString + rowBuffer.Value(index).ToString + ","
            End If
        Next index
        
        'Remove the trailing comma.
        returnString=Left(returnString, Len(returnString) - 1)
        
        'Add the line feed.
        returnString=returnString + vbNewLine
        
        'Go to the next row.
        rowBuffer=cursor.NextRow
    Loop
    
    'Copy the contents of the clipboardString to the Clipboard.
    My.Computer.Clipboard.Clear()
    My.Computer.Clipboard.SetText(returnString)
    
End Sub

End Class

Testing the project

Do the following steps to test the VB.NET standards version to ensure it is still functionally equivalent to the VB6 version:
  1. Click the Start Debugging button. The ArcMap application starts.
  2. In ArcMap, click Customize, then Customize mode. The Customize dialog box appears.
  3. Click the Add from file button and browse to the <your test location>\VBNet_Standards_2008\bin folder.
  4. Select the VBNet_CopyTableSel_2008.tlb file.
  5. Click Open.
  6. When the Customize dialog box refreshes, click the Commands tab, scroll down, then click Developer Samples under the Categories section.
  7. Click, then drag the Copy Table Selection VB2008 Standards command onto the ArcMap GUI.
  8. Open the attribute table of a feature layer and select some records to use the Copy Table Selection VB2008 Standards command.
  9. Click the Copy Table Selection VB2008 Standards command to copy the selected records to the Clipboard.
  10. Start a basic text editor, such as Notepad, and paste the contents to the Clipboard.

Using Esri base classes (Option 1)

While creating a functionally equivalent VB.NET project to the VB6 customization and modernizing the code base to use .NET best practices might be sufficient in some circumstances, there are limitations. One of the main differences is that VB6 uses the Implements keyword for all COM types stubs used by the ICommand interface (referred to as polymorphism). In contrast, the generated base command that used Esri templates use the Inheritance behavior.
In VB6, the polymorphic behavior requires to code stubs for each property and function on the ICommand interface. VB.NET continues to support polymorphic programming practices but also enables the ability to create and use base classes. If developers need more control over a specific ICommand type, they use the Overrides keyword for that ICommand type, then code behavior similar to the polymorphic behavior.
Using the Esri base classes that are available in the Esri Visual Studio Integrated Development Environment (IDE) tools, the OnCreate and OnClick events are stubbed out with the base classes. Developers can then write code in these events. For more information, see the following topics on the Microsoft Developer Network (MSDN) Web site:
Another major difference in the Esri base classes is that COM and component category registration is done automatically, which makes ArcGIS Desktop customization easier. Additionally, in the project's properties under the Compile tab, the Register for COM interop check box is selected and under the Debug tab, the correct path to ArcMap.exe is set to start external program.
Do the following to create a VB.NET customization based on the Esri base classes:
  • Create a VB.NET project and specify the appropriate settings.
  • Write the necessary code.
  • Perform the testing

Creating a VB.NET project using base classes

Rather than making a copy of an existing project (previously demonstrated in this topic), create a VB.NET project by doing the following steps:
  1. Start Visual Studio 2008.
  2. Click the File menu and choose New Project. The New Project dialog box appears.
  3. Click to expand the Visual Basic, ArcGIS, then Extending ArcObjects nodes.
  4. Select the Class Library (ArcMap) template. Name the template VBNet_BaseClass_2008, then click OK. See the following screen shot:
  5. After you click OK on the New Project dialog box, the ArcGIS Project Wizard appears. Right-click the default Class1.vb file on the Solution Explorer, then select Delete.
  6. Click the Project menu and choose Add New Item. The Add New Item dialog box appears.
  7. Click to expand the Common Items, ArcGIS, and Extending ArcObjects nodes.
  8. Select the Base Command template. In the Name text field, type clsCopyTableSelection.vb, then click Add. See the following screen shot:
  9. After you click Add on the Add New Item dialog box, the ArcGIS New Item Wizard Options dialog box appears. Select Desktop ArcMap Command, then click OK. See the following screen shot:
  10. After you click OK on the ArcGIS New Item Wizard Options dialog box, the Code Editor window appears. Click File, then Save All. The <your test location>\VBNet_BaseClass_2008\VBNet_BaseClass_2008.sln file is created.
  11. On the Solution Explorer, right-click the project name, then choose Add ArcGIS Reference. Add the following references to the project:
    • ESRI.ArcGIS.Geodatabase
    • ESRI.ArcGIS.GeoDatabaseUI
    • ESRI.ArcGIS.Geometry

Writing the necessary code

One of the biggest differences developers will discover when using the VB.NET Esri base classes is that there are less code stubs to deal with then in VB6. Typically, developers write code in the OnCreate and OnClick events, and they match closely to VB6. For the potentially numerous Implements code stubs required for properties in VB6, their corollary in the base classes is a simpler property mechanism.
If more control is needed over a property in the base classes, use the Overrides keyword. Using the VB.NET project previously created in this topic that demonstrated VB.NET best coding practices as a reference, write the following code example in the clsCopyTableSelection.vb file:
[VB.NET]
Imports System.Runtime.InteropServices
Imports System.Drawing
Imports ESRI.ArcGIS.ADF.BaseClasses
Imports ESRI.ArcGIS.ADF.CATIDs
Imports ESRI.ArcGIS.Framework
Imports ESRI.ArcGIS.ArcMapUI
Imports ESRI.ArcGIS.Geodatabase
Imports ESRI.ArcGIS.GeoDatabaseUI
Imports ESRI.ArcGIS.Geometry
Imports ESRI.ArcGIS.esriSystem

<ComClass(clsCopyTableSelection.ClassId, clsCopyTableSelection.InterfaceId, clsCopyTableSelection.EventsId), _
          ProgId("VB2008_BaseClass.clsCopyTableSelection")> _
          Public NotInheritable Class clsCopyTableSelection
    Inherits BaseCommand
    
    #Region "COM GUIDs"
    ' These  GUIDs provide the COM identity for this class
    ' and its COM interfaces. If you change them, existing
    ' clients will no longer be able to access the class.
    Public Const ClassId As String="719e02c3-71b7-460e-8719-1c9ffe9d581e"
    Public Const InterfaceId As String="0ae522ba-7791-4183-a385-b052817501c8"
    Public Const EventsId As String="a8806b0c-a2cb-4d09-8eca-d1f27195b531"
    #End Region
    
    #Region "COM Registration Function(s)"
    <ComRegisterFunction(), ComVisibleAttribute(False)> _
                         Public Shared Sub RegisterFunction(ByVal registerType As Type)
        ' Required for ArcGIS Component Category Registrar support.
        ArcGISCategoryRegistration(registerType)
        'Add any COM registration code after the ArcGISCategoryRegistration() call.
    End Sub

    <ComUnregisterFunction(), ComVisibleAttribute(False)> _
                           Public Shared Sub UnregisterFunction(ByVal registerType As Type)
        ' Required for ArcGIS Component Category Registrar support.
        ArcGISCategoryUnregistration(registerType)
        'Add any COM unregistration code after the ArcGISCategoryUnregistration() call.
    End Sub

    #Region "ArcGIS Component Category Registrar generated code"
    Private Shared Sub ArcGISCategoryRegistration(ByVal registerType As Type)
    Dim regKey As String=String.Format("HKEY_CLASSES_ROOT\CLSID\{{{0}}}", registerType.GUID)
    MxCommands.Register(regKey)
End Sub

Private Shared Sub ArcGISCategoryUnregistration(ByVal registerType As Type)
Dim regKey As String=String.Format("HKEY_CLASSES_ROOT\CLSID\{{{0}}}", registerType.GUID)
MxCommands.Unregister(regKey)
End Sub

#End Region
#End Region

Private m_application As IApplication
Private m_TableView2 As ITableView2

' A creatable COM class must have a Public Sub New()
' with no parameters; otherwise, the class will not be
' registered in the COM registry and cannot be created
' via CreateObject.

Public Sub New()
    MyBase.New()
    
    ' TODO: Define values for the public properties.
    MyBase.m_category="Developer Samples"
    MyBase.m_caption="Copy Table Selection VB2008 via Base Class"
    MyBase.m_message="Copies the selected records in the table window VB2008 via Base Class"
    MyBase.m_toolTip="Validate Table Selection VB2008 via Base Class"
    MyBase.m_name="Developer Samples_Copy Table Selection VB2008 via Base Class"
    
    Try
    'TODO: Change the bitmap name if necessary.
    Dim bitmapResourceName As String=Me.GetType().Name + ".bmp"
    MyBase.m_bitmap=New Bitmap(Me.GetType(), bitmapResourceName)
    Catch ex As Exception
    System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Bitmap")
    End Try
    
End Sub

Public Overrides Sub OnCreate(ByVal hook As Object)
If Not hook Is Nothing Then
    m_application=CType(hook, IApplication)
    
    'Disable if it is not ArcMap.
    If TypeOf hook Is IMxApplication Then
        MyBase.m_enabled=True
    Else
        MyBase.m_enabled=False
    End If
End If

' TODO:  Add other initialization code.
End Sub

Public Overrides Sub OnClick()
Copy()
End Sub

Private Sub Copy()
    
    ' Get the selection from the table.
    Dim selectionSet As ISelectionSet=m_tableView2.SelectionSet
    Dim table As ITable=m_tableView2.Table
    Dim cursor As ICursor=Nothing
    
    'Load the selection results into the cursor object.
    selectionSet.Search(Nothing, False, cursor)
    
    'Get the first row of the cursor.
    Dim rowBuffer As IRowBuffer=cursor.NextRow
    
    'Initialize the returnString to be empty.
    Dim returnString As String=""
    
    'Obtain all of the fields in table.
    Dim fields As IFields=rowBuffer.Fields
    
    'Loop through all of the rows.
    Dim Count As Integer=fields.FieldCount
    Do Until rowBuffer Is Nothing
        
        'Loop through all of the fields.
        Dim index As Integer
        For index=0 To Count - 1
            If Not TypeOf rowBuffer.Value(index) Is IGeometry Then
                
                'Extract the strings from each field in the table row.
                returnString=returnString + rowBuffer.Value(index).ToString + ","
                
            End If
            
        Next index
        
        'Remove the trailing comma.
        returnString=Left(returnString, Len(returnString) - 1)
        
        'Add the line feed.
        returnString=returnString + vbNewLine
        
        'Go to the next row.
        rowBuffer=cursor.NextRow
        
    Loop
    
    'Copy the contents of the clipboardString to the Clipboard.
    My.Computer.Clipboard.Clear()
    My.Computer.Clipboard.SetText(returnString)
    
End Sub

Public Overrides ReadOnly Property Enabled() As Boolean
Get

'Create an instance of TableWindowClass using the ITableWindow3 interface.
Dim tableWindow3 As ITableWindow3=New TableWindowClass

'Create an empty ISet to hold the open table windows.
Dim windowSet As ISet=Nothing

'The .FindOpenTableWindows populates the windowSet object byRef.
tableWindow3.FindOpenTableWindows(windowSet)

'Go to the first item in the ISet.
windowSet.Reset()

'Cast the first ISet object to an ITableWindow.
Dim tableWindow As ITableWindow=CType(windowSet.Next, ITableWindow)

'Loop through the tableWindows.
Do Until tableWindow Is Nothing
    
    'Get the TableControl from the TableWindow.
    Dim tableControl As ITableControl=tableWindow.TableControl
    
    'Set the member (also known as, Global) variable ITableView2 interface.
    m_TableView2=CType(tableControl, ITableView2)
    
    'If you have selected records, enable the command.
    Dim selectionSet As ISelectionSet=m_TableView2.SelectionSet
    If selectionSet.Count > 0 Then
        Return True
    End If
    
    'Iterate over the next ArcMap window.
    tableWindow=CType(windowSet.Next, ITableWindow)
    
Loop

'If TableWindow is not found, disable the command.
Return False
End Get
End Property

End Class
Writing code to Override a default property can be complicated for new developers. Developers sometimes inquire how this is done because they did not notice that property as an Override option in Visual Studio's drop-down combo boxes on the base class. For example, in the code for this base class, the Enabled property was created using an Overrides statement. Generating the default stub code for the overridden enabled property was accomplished by doing the following:
  1. Typing P inside the class file at the bottom of the file. IntelliSense provides a set of context menu choices.
  2. Selecting Public and pressing the Tab key to insert the Public keyword in the code editor.
  3. Pressing the space bar. Another set of context menu choices appear.
  4. Selecting Overrides and pressing the Tab key. The code editor changes to read Public Overrides.
  5. Pressing the space bar and a final context menu appears.
  6. Selecting Enabled() As Boolean and pressing the Tab key. The code editor changes and the complete stub code generates.

Testing base classes

Do the following steps to test the VB.NET base class customization and ensure it is functionally equivalent to the VB6 version:
  1. Click the Start Debugging button. The ArcMap application starts.
  2. In ArcMap, click Customize, then Customize mode. The Customize dialog box appears.
  3. Click the Commands tab, scroll down, then click Developer Samples under the Categories section.
  4. Click, then drag the Copy Table Selection VB2008 via Base Classes command onto the ArcMap GUI.
  5. Open the attribute table of a feature layer and select some records to use the Copy Table Selection VB2008 via Base Class command.
  6. Click the Copy Table Selection VB2008 via Base Class command (shows as a white bunny as the icon) to copy the selected records to the Clipboard.
  7. Start a basic text editor, such as Notepad, then paste the contents to the Clipboard.
Because the COM references and component categories have been set via the code as part of the Esri Base Command project template, it is not necessary to click the Add from file button on the Customize dialog box in ArcMap. The command—Copy Table Selection VB2008 via Base Class—is automatically added to the Developer Samples category on the Customize dialog box.
This is one of the advantages of writing ArcObjects customizations using the base command (inheritance) over the VB6 Implements (polymorphism) programming paradigm.

Using Esri add-ins (Option 2)

The second option for ease of developing ArcObjects customizations is the Esri add-in, which is new with ArcGIS 10. The programming paradigm is similar to that of the Esri base classes in Option 1 but there is the added benefit of deployments being easier. For more information about add-ins, see Building add-ins for ArcGIS for Desktop
Do the following to create a VB.NET customization based on the add-ins:
  • Create a VB.NET project and specify the appropriate settings.
  • Write the necessary code.
  • Perform the testing

Creating a VB.NET project using add-ins

Rather than making a copy of an existing project (previously demonstrated in this topic), create a VB.NET project by doing the following steps:
  1. Start Visual Studio 2008.
  2. Click the File menu and choose New Project. The New Project dialog box appears.
  3. Click to expand the Visual Basic, ArcGIS, then Desktop Add-Ins nodes.
  4. Select the ArcMap Add-in template. Type VBNet_AddIn_2008 in the Name text field, then click OK. See the following screen shot:
  5. After you click OK, the ArcGIS Add-Ins Wizard dialog box appears. Specify the following on the dialog box:
    • Add-in Name—VBNet_AddIn_2008.
    • Company/Publisher—Your company's or publisher's name.
    • Author—The author's name.
    • Description—The add-in's description.

      See the following screen shot:
  6. Click Next. The Available Add-in Components dialog box appears.
  7. Select the Button check box under the Add-in Types area, then specify the following:
    • Class Name—ButtonAddIn.
    • Caption—Copy Table Selection VB2008 via add-in.
    • Category—Developer Samples.
    • Tooltip—Validate Table Selection VB2008 via add-in.
    • Description—Copies selected records in the table window VB2008 via add-in.
    • Heading—Custom add-in.
    • Content—Add-in to copy selected records in the attribute table to the Clipboard.

      See the following screen shot:
  8. Click Finish. The Code Editor window appears.
  9. Click File, then Save All. The <your test location>\VBNet_AddIn_2008\VBNet_AddIn_2008.sln file is created.
  10. On the Solution Explorer, right-click the project name and choose Add ArcGIS Reference. Add the following references to the project:
    • ESRI.ArcGIS.Geodatabase
    • ESRI.ArcGIS.GeoDatabaseUI
    • ESRI.ArcGIS.Geometry

Writing the necessary code

Similar to Esri base classes, there are less code stubs to manage then in VB6. For a button, developers typically write code in the OnClick and OnUpdate events. Using the VB.NET project created earlier in this topic that demonstrated VB.NET best coding practices as a reference, write the following code example in the ButtonAddIn.vb file:
[VB.NET]
Imports ESRI.ArcGIS.Geodatabase
Imports ESRI.ArcGIS.GeoDatabaseUI
Imports ESRI.ArcGIS.Geometry
Imports ESRI.ArcGIS.esriSystem
Imports ESRI.ArcGIS.ArcMapUI

Public Class ButtonAddIn
    Inherits ESRI.ArcGIS.Desktop.AddIns.Button
    
    Private m_TableView2 As ITableView2
    
    Public Sub New()
    End Sub
    
    Protected Overrides Sub OnClick()
    Copy()
End Sub

Protected Overrides Sub OnUpdate()

'If TableWindow is not found, disable the command.
Enabled=False

'Create an iinstance of the TableWindowClass using the ITableWindow3 interface.
Dim tableWindow3 As ITableWindow3=New TableWindowClass

'Create an empty ISet to hold the open table windows.
Dim windowSet As ISet=Nothing

'The .FindOpenTableWindows populates the windowSet object byRef.
tableWindow3.FindOpenTableWindows(windowSet)

'If the windowSet is not populated, stop execution of OnUpdate.
If windowSet Is Nothing Then
    Return
End If

'Go to the first item in the ISet.
windowSet.Reset()

'Cast the first ISet object to an ITableWindow.
Dim tableWindow As ITableWindow=CType(windowSet.Next, ITableWindow)

'Loop through the tableWindows.
Do Until tableWindow Is Nothing
    
    'Get the TableControl from tthe TableWindow.
    Dim tableControl As ITableControl=tableWindow.TableControl
    
    'Set the member (also known as, Global) variable ITableView2 interface.
    m_TableView2=CType(tableControl, ITableView2)
    
    'If you have selected records, enable the command.
    Dim selectionSet As ISelectionSet=m_TableView2.SelectionSet
    If selectionSet.Count > 0 Then
        Enabled=True
    End If
    
    'Iterate over the next ArcMap window.
    tableWindow=CType(windowSet.Next, ITableWindow)
    
Loop

End Sub

Private Sub Copy()
    
    ' Get the selection from the table.
    Dim selectionSet As ISelectionSet=m_TableView2.SelectionSet
    Dim table As ITable=m_TableView2.Table
    Dim cursor As ICursor=Nothing
    
    'Load the selection results into the cursor object.
    selectionSet.Search(Nothing, False, cursor)
    
    'Get the first row of the cursor.
    Dim rowBuffer As IRowBuffer=cursor.NextRow
    
    'Obtain all of the fields in table.
    Dim fields As IFields=rowBuffer.Fields
    
    'Initialize the clipboardString to be empty.
    Dim clipboardString As String=""
    
    'Loop through all of the rows.
    Dim Count As Integer=fields.FieldCount
    Do Until rowBuffer Is Nothing
        
        'Loop through all of the fields.
        Dim index As Integer
        For index=0 To Count - 1
            If Not TypeOf rowBuffer.Value(index) Is IGeometry Then
                
                'Extract the strings from each field in the table row.
                clipboardString=clipboardString + rowBuffer.Value(index).ToString + ","
            End If
        Next index
        
        'Remove the trailing comma.
        clipboardString=Left(clipboardString, Len(clipboardString) - 1)
        
        'Add the line feed.
        clipboardString=clipboardString + vbNewLine
        
        'Go to the next row.
        rowBuffer=cursor.NextRow
        
    Loop
    
    'Copy the contents of the clipboardString to the Clipboard.
    My.Computer.Clipboard.Clear()
    My.Computer.Clipboard.SetText(clipboardString)
    
End Sub

End Class

Testing add-ins

Do the following steps to test the VB.NET add-in class customization to ensure it is functionally equivalent to the VB6 version:
  1. Click the Start Debugging button. The ArcMap application starts.
  2. In ArcMap, click Customize, then Customize mode. The Customize dialog box appears.
  3. Click the Commands tab, scroll down, then click Developer Samples under the Categories section.
  4. Click, then drag the Copy Table Selection VB2008 via Add-In command onto the ArcMap GUI.
  5. Open the attribute table of a feature layer and select some records to use the Copy Table Selection VB2008 via Add-In command.
  6. Click the Copy Table Selection VB2008 via Add-In command to copy the selected records to the Clipboard.
  7. Start a basic text editor, such as Notepad, then paste the contents to the Clipboard.

Other migration issues

ArcGIS 10 has other new and important architecture changes that may need to be addressed for ArcObjects developers upgrading from ArcGIS 9.x. For additional reference the following two documents may be of interest: Migrating ArcGIS 9.3.x and 10 Desktop and Engine custom components to ArcGIS 10.1 and How to migrate ArcGIS 9.3.x and 10 Desktop and Engine stand-alone applications to ArcGIS 10.1.


See Also:

Migrating from VB6 to VB.NET
General steps for migrating from VB6 to VB.NET




Development licensing Deployment licensing
ArcGIS for Desktop Basic ArcGIS for Desktop Basic
ArcGIS for Desktop Standard ArcGIS for Desktop Standard
ArcGIS for Desktop Advanced ArcGIS for Desktop Advanced
Engine Developer Kit Engine