210 likes | 392 Views
AutoCAD® VBA to .NET Migration: The Easy Way Using COM Interop. Augusto Gonçalves Developer Consultant at Autodesk. Meet the presenter. Augusto Gonçalves Developer Technical Services São Paulo, Brazil Autodesk
E N D
AutoCAD® VBA to .NET Migration: The Easy Way Using COM Interop Augusto Gonçalves Developer Consultant at Autodesk
Meet the presenter Augusto GonçalvesDeveloperTechnicalServicesSão Paulo, BrazilAutodesk Augusto is member of DevTech team since 2008 based at São Paulo office. He is specialist in AutoCAD, Civil3D and Revit APIs. Before join Autodesk, Augusto worked on CAD-related developments for civil engineering and web commerce. He is graduated in Civil Engineering and holds a Master in Computer Engineer.
Autodesk Developer Network • Access to almost all Autodesk software and SDK’s • Including early access to Beta software • Members-only website with 1000s of technical articles • Unlimited technical support • Product direction through conferences • Marketing benefits • Exposure on autodesk.com • Promotional opportunities • 1 to 3 free API training classes • Based on user level www.autodesk.com/joinadn
Why migrate to VB.NET? • Discontinuation of the VBA Licensing Program • We do not expect to be included with AutoCAD for many releases • Limitations • VBA 32 bits running on 64 bits • No 64 bits of many features, such as DAO • New .NET technologies • True Object Orientation • WinForms, ADO.NET, AutoCAD.NET
The ActiveX API • ActiveX is the API used by VBA • The discontinuation announced by Microsoft do not apply to the API, only to the IDE • You can use this API from .NET • .NET Interop can access the same object model available on VBA
The new IDE: Visual Studio • Succeeds VBAIDE • There are many versions, including a free version - Express
Demonstration • Creating a simple Hello World with VB.NET using COM Interop • Goals • Understand type of project, references and required code
Migration step-by-step • Prepare your code for migration • May reduce the required effort and improve the final result • Export your VBA project to VB6 • Save each VBA file, such as modules, classes and userforms • Import into a VB6 project • Append all files exported from VBA • Upgrade using Visual Basic Express • This is the migration itself • Make some corrections • Such as references and ThisDrawing variable
Prepare you code for migration • Use Early-Binding instead Late-Binding • Consider replace all Object and Variant • Use CXxxx where relevant • Cint, CStr, CDbl, etc
Demonstration • Perform the step-by-step migration for a simple project • Will not include UserForms
Using the converter Macro • Create a VB6 project from a VBA .dvb file • Do not require VB6 installed • Convert UserForms into Forms • Which allow migration to .NET WinForms • Automate steps 3 and 4 (export from VBA to VB6) • Save us a lot of manual work
Demonstration • Using the converter macro
Working with events • Use a ThisDrawing variable instead a property • WithEvents keyword cannot be applied to properties • Manage swap between documents • This is automatically on VBA, but VB.NET requires a special code • Start handling events on startup
Demonstration • Special requirements to handle ThisDrawing events
Demonstration • Particularities when handling Form events • Goal • Understand how manually check and correct migrated events
Quick throubleshooting • Some common issues when migrating from VBA to VB.NET • You may check it when you start your work • Unable to cast COM object exception • Requires a later version of the .NET Framework • Project cannot be started directly
Additional Resources Through the Interface blog • http://through-the-interface.typepad.com AutoCAD.NET Developer’s Guide • http://www.autodesk.com/autocad-net-developers-guide ADN DevTV: AutoCAD VBA to .NET Migration Basics • http://download.autodesk.com/media/adn/VBA_Migration/DevTV_Recording.zip Discussion Groups • http://discussion.autodesk.com/forums/category.jspa?categoryID=8 Autodesk Developer Network • http://www.autodesk.com/joinadn
DevLab • San Francisco, USA Feb 1-5, 2010 • Farnborough, UK Feb 8-12, 2010 • Munich, Germany June 7-11, 2010 • Other countries TBD • www.autodesk.com/apitraining > Schedule • stephen.preston@autodesk.com