PDA

View Full Version : Convert VBA code to VB code



Robert Platt
2007-02-15, 06:42 AM
I've been looking at visual basic and like the extra stuff it offers. Does anyone know if there a painless way of converting VBA code to VB code, using some third party software perhaps? Alternatively does anyone know of any place I might find comparison information/charts so that I can work through my code to convert it myself?

Thanks in advance

MikeJarosz
2007-02-15, 02:46 PM
I found a book: The .NET Languages: a quick translation guide. The subtitle tells it all: Learn to convert programs among VB 6.0, VB.NET and C#

The author is Brian Bischof. I found it remaindered for about $3.99 at Edward Hamilton Books.

I've opened a discussion on this topic, as I sense a lot of the VBA world is waking up to the changes coming. See my post on the future of VBA.

Ed Jobe
2007-02-15, 04:07 PM
Are you wanting to convert to VB6 or .Net? There really isn't much to "convert". Just export your modules from the dvb. If you have forms in your dvb, that will take some conversion, but some have written code to handle that.

Robert Platt
2007-02-18, 09:24 AM
Thanks guys.
I've been writing code to provide interaction between AutoCAD and Access.
VBA is what I have written, and VB 2005 is what I want to change to.
I may be wrong but I gather I can get more functionality, better looking forms and controls, and the ability to package my code as a freestanding exe. VB 2005 also offers a host of automated database interaction - I can use it to get to my Access databases without having to write much code at all (OK so I'm lazy....).

Ed Jobe
2007-02-19, 06:07 AM
without having to write much code at all (OK so I'm lazy....).
You've been listening to salesmen, right?

Robert Platt
2007-02-19, 11:02 AM
Hi Ed,
Sounds like you are trying to tell me not to bother? Maybe VBA actually has everything I need and I just haven't found it yet.
I must say I've already achieved more with my VBA efforts than I ever thought possible, and I'm certainly delighted I made the change from Lisp (although I'm still using a lisp program to start my VBA program).

MikeJarosz
2007-02-19, 07:15 PM
Hi Ed,
Sounds like you are trying to tell me not to bother? Maybe VBA actually has everything I need and I just haven't found it yet.
I must say I've already achieved more with my VBA efforts than I ever thought possible, and I'm certainly delighted I made the change from Lisp (although I'm still using a lisp program to start my VBA program).
Are you ready for some real fun?

Start Excel or Word from Acad VBA and take info from your drawing and dump it into Excel...

Robert Platt
2007-02-20, 06:46 AM
Actually I sent my data to Excel before I tried Access. I found Access more difficult to set up but now it is done it allows me to query data more efficiently (and from more than one table at a time). I use the element (usually a polyline) handle as the key in Access so clicking on an element pops up a form with the data relevant to that element.
I'm doing land use and masterplanning so this is already saving wads of time.
It's a kind of mini GIS.
What I like about VB is all the database linking automation it has prebuilt into some of the controls - hence my exploration for converting my code from VBA to VB.

Ed Jobe
2007-02-20, 05:45 PM
Hi Ed,
Sounds like you are trying to tell me not to bother? Maybe VBA actually has everything I need and I just haven't found it yet.
No, I just think you have the wrong idea about .Net, specifically that you won't have to write much code. Yes .Net, or more specifically, ADO.Net, has more to offer, but that doesn't equate to less code. It seems to be just the opposite when you are dealing with the .net api for acad.

Robert Platt
2007-02-21, 08:42 AM
Looks like I should just make a point of exploring VBA a bit further.
When I looked at the extra controls that are available (the ones that aren't on the standard tab) I see that some of the database controls I've seen in .Net seem to be available for VBA as well. So I'll give these a try and see where it takes me.
Thanks all, for the advice.

rcrabb
2007-02-22, 01:01 PM
I'm certainly delighted I made the change from Lisp (although I'm still using a lisp program to start my VBA program).

a little off topic here ... but is there a way to use vba to start your vba program? i've experienced the same problem, only finding solutions written in lisp to program a button to load a vba program ...

maybe researching .vbs scripts? i dont mind doing the learning on my own, just need pointed in the right direction ;) thanks

Ed Jobe
2007-02-22, 04:05 PM
The only other way is to use acad.dvb containing a sub called AcadStartup.

MikeJarosz
2007-02-22, 07:25 PM
The only other way is to use acad.dvb containing a sub called AcadStartup.
That's if you want to load AND run your programs. I have about 50 programs, some quite significant in size, in my acad.dvb, but nothing in acadstartup. Typing the Acad command vbaide opens the vba editor without starting any program. Then, click on the program you want to run and hit F5. Where you click in the program is significant. Every program should have a main procedure to start from.

You can also run VB programs from the TOOLS/MACRO menu, without ever seeing the development environment, which spooks some users.

Opie
2007-02-22, 07:47 PM
You can also run VB programs from the TOOLS/MACRO menu, without ever seeing the development environment, which spooks some users.
You can open that without the menu as well with the VBARUN command. If it is not in that list you can use the VBAMAN command to load additional VBA applications.

zoomharis
2007-02-24, 04:01 PM
As far as I know, If the dvb file is in the AutoCAD search path, you can simultaneously load and run a macro using VBARUN command.


-VBARUN dvbFilename!ModuleName.MacroName

It will initiate the VBA System (if not yet initiated) + Load the dvb file + Run the macro.

Capt. Computer Crasher
2007-03-21, 07:23 PM
As far as I know, If the dvb file is in the AutoCAD search path, you can simultaneously load and run a macro using VBARUN command.


-VBARUN dvbFilename!ModuleName.MacroName

It will initiate the VBA System (if not yet initiated) + Load the dvb file + Run the macro.

I tried using that exact statement assign to an icon, However when I hit the icon I get in the command line:

Command: -vbarun
Macro name: <dvbFilename!ModuleName.MacroName>
Macro not found.
Command:

BUT if i right-click after I get

-VBARUN
Macro name:

then I type in just the <MacroName> the macro runs just fine, but this process defeats the reason of a one-step icon. any suggestions. thanks

Ed Jobe
2007-03-21, 08:53 PM
I tried using that exact statement assign to an icon, However when I hit the icon I get in the command line:

Command: -vbarun
Macro name: <dvbFilename!ModuleName.MacroName>
Macro not found.
Command:

You didn't actually type "<dvbFilename!ModuleName.MacroName>" did you? You substituted the correct information?

Capt. Computer Crasher
2007-03-21, 09:00 PM
You didn't actually type "<dvbFilename!ModuleName.MacroName>" did you? You substituted the correct information?

Of course, this is a loose sample. Actual input is name specific

Ed Jobe
2007-03-21, 09:19 PM
The only other explanation is that you got the syntax wrong ("!" between file!project, including spelling) or that the file was not found.


p.s. They left out the project descriptor. The correct syntax is:
FileSpec!ProjectName.ModuleName.ProcedureName

PellaCAD
2007-08-15, 08:45 PM
Have you been able to start your VBA or VB programs from a button without the intermediate step of using LISP?



Hi Ed,
Sounds like you are trying to tell me not to bother? Maybe VBA actually has everything I need and I just haven't found it yet.
I must say I've already achieved more with my VBA efforts than I ever thought possible, and I'm certainly delighted I made the change from Lisp (although I'm still using a lisp program to start my VBA program).

Ed Jobe
2007-08-15, 10:13 PM
Have you been able to start your VBA or VB programs from a button without the intermediate step of using LISP?
VBA doesn't have any mechanism for adding to the command stack like lisp and .net do.