VBA to VB. NET Migration

The migration of VBA project could be tedious and depending on the size of the project could take some time to finish it. There are limitations and the translation is not always one to one with .NET. This article will help you to migrate your VBA project to VB. NET. ARES Commander doesn’t support VBA modules, so customers that have such plugins need to port them to vb .NET.

Requirements:

  • AutoCAD

  • VBA module for AutoCAD: Download the Microsoft VBA Module for AutoCAD

  • The VBA to VB6 Converter: An Autodesk “magic” helper tool . This converter is a macro that exports VBA projects to VB6 format and make them ready for VB Upgrade Wizard without using VB6 IDE. One of the benefits of this tool is the conversion of User Form into VB6 forms

  • A tool to convert VB 6 projects into VB .NET. You can find several applications in the web like VBUC or https://www.vbmigration.com/white-papers/migrating-a-vb6-application-in-10-easy-steps/ . In my case, I have downloaded VS 2008: http://download.microsoft.com/download/8/1/d/81d3f35e-fa03-485b-953b-ff952e402520/VS2008ProEdition90dayTrialENUX1435622.iso and use Visual Basic Upgrade Wizard

  • ARES Commander and ARES .NET SDK

  • Visual Studio with a Toolset compatible with the ARES Commander version that you have installed.

 Steps

  1. Convert VBA to VB6 project. Please read the Whitepaper.pdf that it is inside the SupportingFiles.zip file, which explains how to execute this step (read from chapter: The VBA to VB6 Converter: A “magic” helper tool)

Limitations: As you will read, the tool has some limitations: The converter does not work for the MSForms controls TabStrip, Multipage, SpinButton, or any other external control. Also I have found problems with Listbox with multiple columns. You may need to manually migrate them.

  1. Performing the upgrade to VB .NET. Use of VS 2008's Upgrade Wizard. Once the VB6 project it is generated, you are ready to migrate your project to VB .NET. Start VS2008 and open the VB6 project, it will ask you to upgrade to VB .NET. The following link will help to complete this step: https://www.codeproject.com/Articles/31960/Upgrading-VB6-to-VB-NET

  2. Error Correction. Next step will be fix the compiling issues and warnings that you got. You will have lots of errors! To see a list of errors, open the "Error List" (View menu | Error List).

Considerations

Considerations

Link against .NET SDK references: FxCoreMgd, PCAD_AC_X, PCAD_DB_X, TD_Mgd

Add Imports to PCAD_AC_X and to all vb files

Review that all UI forms were created, if one of them it is not generated, you will need to create it manually

You need to adapt VBA ThisDrawing. Read whitepaper.pdf in SupportFiles (Working with Events)

Removed PtrSafe statement from functions

Replace GoSub with regular functions or GoTo

TextStream replaced with StreamReader or StreamWriter

TreeView1 is not declared as a member

Events are not handled properly. In some cases, you will need to handle them with corresponding event

UserForm events handles by MyBase: Load, Closed, Activated

Replaced Node with TreeNode

We cannot use AcadSelectionSet(), replace with AcadSelectionSet.Item()

VBA End statement commented. Replaced with Exit Sub

Color assignation, Vb .NET use: Color.FromArgb

Load Event for the user forms. Read whitepaper.pdf in SupportFiles (Migration of UserForms)

VBA multicolumn ListBox replace with ListView

Replace ListBox.List with ListView.Items(__row).SubItems(__column).Text

Replace SpinBox with NumericUpDown control

error BC30454: Expression is not a method.->replaced with the corresponding VB. NET API function: zoomWindow, etc..

Replaced ThisDrawing.Layouts.("Model"). with ThisDrawing.Layouts.Item(0).

ProgressBar was not converted

CommonDialog1 splitted in OpenFileDialog and SaveFileDialog

Add Singleton for each form to be accessible only once

Created a function (FindDrawingLayer) to replace: App.ThisDrawing.Layers(“layer“)

Created a function (FindDrawingBlock) to replace: App.ThisDrawing.Blocks(“block”)

Replaced listbox.Column and listbox.List with .ListBox1.Items(x).SubItems(y)

Documents.Add replaced with ThisDrawing.Application.Documents.Add()

Unknown Instance types where converted to Object, please remove them if there is already a corresponding type from ARES SDK

Mismatch of ACAD types when converting from VB6 to VB.Net . Example:

VB6 code:

Dim Mtext As AcadMText, Kreis As AcadCircle, Bogen As AcadArc

…was translated in VB.Net as:

Dim Spline, Linie, Kreis_Renamed, punkt As AcadSpline

must be converted manually into

Dim Spline As AcadSpline Dim Linie As AcadLine Dim Kreis_Renamed As AcadCircle Dim punkt As AcadPoint

Show() dialog method must be reviewed. For modal dialogs must be replaced with ShowDialog() method.

Application.RunMacro must be called with actual connected application object.

acadApp.RunMacro(“MacroName) to compile.

  1. Update Code and DoEvents(). Read following documentation to improve your project code: https://www.codeproject.com/Articles/31960/Upgrading-VB6-to-VB-NET

Other interesting links: