Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I catalog, index, and/or print VB6 source code, with each sub/function on a page..?

How can I catalog, index, and/or print VB6 source code with each sub or function on its own page..? I would like to do so with free or included Visual Studio Add-Ins if possible, but I'm not adverse to writing something myself. I'm familiar with "Microsoft Office Visual Basic for Applications Extensibility", and it seems that VB6 has a similar module, which may allow me to simply "For Each" through the code module collection and throw the subs at the printer one at a time. It would take maybe 10-15 lines of code.

My first priority is the printing, preferably with each sub/function on its own page, but with the normal print function of the IDE, all the code runs together in one long printout. Next after that, I would like to create an index/toc of the names of every sub, function, variable, and constant in each VBP. We have the Visual Studio 6.0 Enterprise Edition, but there does not seem to be anything in it to do any of these kinds of things.

You may laugh and ask, "Why VB6..?? LOL!!". It's because I've been tasked with upgrades and changes to VB6 source code of a large software system that runs a factory. It's on an isolated network with no connection to the outside world, and it's been running fine for 14 years, but now they want to start upgrading some things. The system is composed of many VBP files, each with many modules and forms.

Edit: I did try Googling for answers to this, but that proved impossible. All I got was coded samples about printing from apps written in VB6, not printing the source code from the IDE.

like image 987
spinjector Avatar asked Dec 08 '16 03:12

spinjector


3 Answers

You don't need to properly parse the code to meet your requirements. Write something yourself. You could output to a printer or to HTML files. I did this once, it worked fine.

The source code files are just text files. Read the files line by line, printing each line. Start a new page every time you see "end sub" or "end function" or "end property". That way each method will start on a separate page. FRM files have control definitions at the top, you can skip that by just looking for a line containing only "end". The code starts there.

If you are doing a lot of VB6 I also recommend getting the brilliant add in MZ Tools. It has excellent search tools. Unfortunately no longer free, but worth the money IMHO. I have no links with the vendor.

like image 191
MarkJ Avatar answered Sep 30 '22 12:09

MarkJ


Write an Add-In. It is far easier than you might suspect.

Get ahold of the book "Developing Visual Basic Add-Ins" by Steven Roman (O'Really, 1999, ISBN 1-56592-527-0).

like image 20
Herb Avatar answered Sep 30 '22 14:09

Herb


Parsing the module for procedures and functions is hard, believe me. Particularly with line continuations like this:

 _
Public _
Sub _
Foo() ' _
End Sub
 _
End _
 _ 
Sub _

Furthermore, a Property can be ended with End Property, but also with End Function or End Sub

Fortunately, the VBIDE for VB6 has more classes and methods for working with VB projects than the VBA version of VBIDE.

One of those is the CodePane.Members property that returns a collection of all of the identifiers (although, I think it omits Type and Enum identifiers, but they're declared in the declarations section of a module anyway) in a module.

enter image description here

And each member exposes various properties including it's location in the module: enter image description here

If you're interested in parsing in more detail, and in a fully-featured add-in for the IDE, you should take a look at Rubberduck-VBA on GitHub (I'm a contributor). It's currently working with VBA hosts, but VB6 is on the road-map. It has one of the most robust VB parsers available, and it's open-source.

like image 20
ThunderFrame Avatar answered Sep 30 '22 14:09

ThunderFrame