Transitioning from VBA to VB.NET - Template Assistance

Transitioning from VBA to VB.NET - Template Assistance

grahamP6L9M
Contributor Contributor
1,307 Views
7 Replies
Message 1 of 8

Transitioning from VBA to VB.NET - Template Assistance

grahamP6L9M
Contributor
Contributor

Good morning All

 

I've been programming in VBA for many years, but feel that as my programs get more complex and sophistacted, I should probably make the switch to a more powerful and supported language.

 

Years ago I had a dabble into VB.NET but never really had the time to pursue it properly, but I did have some templates that would start off a new AutoCAD script in Visual Studio, that was preset with all the file references etc needed to manipulate a session of AutoCAD. It was even set to allow for the old VBA 'ThisDrawing' variable, referring to the current AutoCAD drawing. 

 

I'm presently using AutoCAD 2019 & 2020 and have Visual Studio 2019 installed, but I'm really struggling to get a VB.NET session started and successfully referenced to AutoCAD.  With VBA, it's all taken care of, of course.

 

So, if any of you have a template set up that you'd be willing to share, I'd be very grateful.  Or if there's a good noobie reference guide somewhere, that could also prove invaluable.

 

Thanks very much

 

Graham

0 Likes
1,308 Views
7 Replies
Replies (7)
Message 2 of 8

_gile
Consultant
Consultant

Hi,

 

Here's @Ed__Jobe 's translation of a tutorial I tried to write to show how to create a Visual Studio project template for an AutoCAD plugin.

http://gilecad.azurewebsites.net/Resources/Template_Csharp_Ed_Jobe.pdf

It's C# but, IMO, you should learn C# instead of VB because you'll find much more valuable help and example in C# than in VB (and in addition, it will help you better understand a new programming environment by moving away from the habits acquired in VBA).



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 8

grahamP6L9M
Contributor
Contributor

Hi Gilles

 

Thanks very much for the PDF! I've had a scan over it and it looks to be the right kinda thing. I'll have a proper look over it later after work and see if I can get it sorted.

One question though if I may. There's a table in there regarding which version of the .NET Framework to use per version of AutoCAD.  We currently have users running either 2018 or 2019.  Would I have to set the framework to 4.6 or would our 2019 versions not like it, as they're supposed to be running 4.7?

 

Thanks for the assistance so far!

 

Kind regards 

 

Graham

0 Likes
Message 4 of 8

_gile
Consultant
Consultant

Hi,

you can build your plugin for the earliest version (targetting .NET Framework 4.6 and referencing AutoCAD 2018 libraries) and try it as is with later versions (AutoCAD 2019). Most of the times it will work.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 5 of 8

CADbloke
Advocate
Advocate

If you're looking to convert VBA to VB.NET (or C#) then here is how to partially automate it.

 

Spoiler Alert, you will need Visual Studio 2008 and (maybe) AutoCAD older than 2012, v2011 was the last one to run on .NET 3.5. I may be wrong about the AutoCAD requirement but you will definitely need VS 2008 because it has the VB6 - VB.NET converter.

 

The conversion process is VBA to VB6, VB6 to VB.NET, optionally VB to C#.

 

Step 1. go to https://www.keanw.com/2010/02/updated-devtv-autocad-vba-to-vbnet-migration-basics.html and download http://download.autodesk.com/media/adn/DevTV_VBA_Migration/english/DevTV_VBA_To_VBdotNet_Migration_E... (the link is on Kean's page). Watch the video. The code is in the SupportingFiles.zip. You're looking for the VBA to VB6 converter which you will run in AutoCAD with your VBA code. It won't do everything but it will get you a fair way there. It is eespecially handy with forms and their controls.

 

Step 2. In Visual Studio 2008 convert the VB6 project to VBA. There's plenty of direction on teh webs for this. ok, lazybones: https://stackoverflow.com/questions/11528797/convert-project-from-vb6-to-vb-net-visual-studio-2008 and to download it: https://stackoverflow.com/questions/15318560/visual-c-2008-express-download-link-dead - I used the Pro version so I can't vouch for Express, it apparently has the converter too.

 

optional Step 3. In Visual Studio 2017/9 use https://marketplace.visualstudio.com/items?itemName=SharpDevelopTeam.CodeConverter to convert the VB.NET to C#

 

Is is completely hands-off?  Naaaaah but it will leapfrog a lot of tedious crap, especially with the forms.

 

FYI I set all that up in a Virtualbox VM to keep the clutter off my dev machine.

- - - - - - -
working on all sorts of things including www.tvCAD.tv & www.CADreplace.com
0 Likes
Message 6 of 8

CADbloke
Advocate
Advocate
Well, if you have used "ThisDrawing" extensively then you are in for a world of pain ... or at least a lot of extension methods. see https://forums.autodesk.com/t5/net/vb-net-reference-to-quot-thisdrawing-quot/m-p/1791868#M5047
- - - - - - -
working on all sorts of things including www.tvCAD.tv & www.CADreplace.com
0 Likes
Message 7 of 8

grahamP6L9M
Contributor
Contributor

Thanks for the imput. I'll read up on that and see what's involved and if it's worth it or not.

0 Likes
Message 8 of 8

CADbloke
Advocate
Advocate
From what I have found so far it is far from automated or easy. This is my first one and it feels like it is going to be a very manual process. VB to me is kinda like revisiting high-school french only the teacher is not as pretty.
also see: https://forums.augi.com/showthread.php?162937-CP327-6L-Hands-On-Migrating-VBA-Projects-to-VB-NET&p=1... - you may glean something from it.
- - - - - - -
working on all sorts of things including www.tvCAD.tv & www.CADreplace.com