Accurately accessing VB6 limitations
Asked Answered
I

6

14

As antiquated and painful as it is - I work at a company that continues to actively use VB6 for a large project. In fact, 18 months ago we came up against the 32k identifier limit.

Not willing to give up on the large code base and rewrite everything in .NET we broke our application into a main executable and several supporting DLL files. This week we ran into the 32k limit again.

The problem we have is that no tool we can find will tell us how many unique identifiers our source is using. We have no accurate way to gauge how our efforts are reducing the number of identifiers or how close we are to the limit before we reach it.

Does anyone know of a tool that will scan the source for a project and return some accurate metrics and statistics?

Isochronize answered 17/4, 2009 at 12:58 Comment(0)
A
2

OK. The Project Metrics Viewer which is part of the Project Analyzer tool from Aivosto will do exactly what you want. I've included a screenshot and also the link to the metrics list which includes numbers of variables etc.

Metrics List

alt text
(source: aivosto.com)

Anny answered 17/4, 2009 at 17:4 Comment(1)
I wish this tool worked... It shows the number of variable declarations (as does CodeSMART) but it still doesn't show the number of unique identifiers. If you have three subs which all contain the same variable "myvar", then it counts as three variable declarations but just one unique identifier. Project analyzer only shows the count of declarations...Lenard
A
1

CodeSmart by AxTools is very good.
alt text
(source: axtools.com)

Anny answered 17/4, 2009 at 13:15 Comment(7)
Yes, but the asker needs a count of the number of variable declarations, and I can't see where CodeSmart shows that figure. Can you tell us where it should be? Thanks.Matisse
It is there, but I don't have image hosting to correct the screenshot from the manufacturer's website. If you download the Trial and install it you can run it and see for yourself.Anny
I've CodeSMART installed but I cannot find it. Can you tell the "path" of the tree where this value is displayed?Lenard
Sure thing. Open up the CodeSmart Project Explorer (alternative to the VB Ctrl-R version) and drill into the objects to see more detail including lists of variable declares.Anny
I must be blind or something... I can see number of methods, public identifiers, but I cannot find the number of unique identifiers...Lenard
Please see following post on Project Analyzer, CodeSmart will provide the information but not in a summarised form as you required.Anny
It's worse. It counts the number of declarations. If you just add them up, you don't get the number of unique identifiers. If two classes have the same property it counts only once!Lenard
W
1

The company I work for also has a large VB6 project that encountered the identifier limit. I developed a way to accurately count the number of identifiers remaining, and this has been incorporated into our build process for this project.

After trying several tools without success, I finally realized that the VB6 IDE itself knows exactly how many identifiers it has remaining. In fact, the VB6 IDE throws an "out of memory" error when you add one variable past its limit.

Taking advantage of this fact, I wrote a VB6 Add-In project that first compiles the currently loaded project in the IDE, then adds uniquely named variables to the project until it throws an error. When an error is raised, it records the number of identifiers added before the error as the number of identifiers remaining.

This number is stored in file in a location known to our automated build process, which then reads this number and reports it to the development team. When it gets below a value we feel comfortable with, we schedule some refactoring time and move more code out of this project into DLL projects. We have been using this in production for several years now, and has proven to be a reliable process.

To directly answer the question, using an Add-In is the only way I know to accurately measure the number of remaining identifiers. While I cannot share the Add-In code our project is using, I can say there is not much code involved, and it did not take long to develop.

Microsoft has a decent guide for how to create an Add-In, which can get you started: https://support.microsoft.com/en-us/kb/189468

Here are some important details specific to counting identifiers:

  • The VB6 IDE will not consistently throw an error when out of identifiers until the current loaded project has been compiled. Our Add-In programmatically does this before adding identifiers to guarantee an accurate count. If the project cannot be compiled, then an accurate count cannot be obtained.
  • There are 32,500 identifiers available to a new, empty VB6 project.
  • Only unique identifier names count. Two local variables with the same name in two different routines only count as one identifier.
Westbrook answered 30/9, 2015 at 17:11 Comment(0)
W
0

You could get this from a tool that extracted identifiers from VB6 code. Then all you'd have to do is sort the list, eliminate duplicates, and measure the list size. We have a source code search engine that breaks up source code into language tokens ("lexes"), with some of those tokens being exactly those identifiers. That would contain exactly the data you want.

But maybe there's another way to solve your problem: find out which variable names which occur rarely and replace them by a set of standard names (e.g., "temp"). So what you really want is a count of the number of each variable name so you can sort for "small numbers of references". The same lexer data can provide this information.

Then all you need is a tool to rename low-occurrence identifiers to something from the standard set. We offer obfuscators that replace one name by another that could probably do this.

[Oct 2014 update]. Just had a long conversation with somebody with this problem. It turns out there's a pretty conceptual answer on which to base a tool, and that is called register coloring, which allocates a fixed number of registers to an arbitrary number of operands. This works by computing an "interference graph" over operands; and two operands that don't "interfere" can be assigned the same register. One could use that to allocate 2^16 available variable names names to an arbitrary number of identifiers, if the interference graph isn't bad enough. My guess is that it is not. YMMV, and somebody still has to build such a tool, needing likely a VB6 parser and machinery to compute such a graph. [Check out my bio].

Windgall answered 12/8, 2009 at 4:10 Comment(0)
S
0

Cheat - create an unused class with #### unique variables in it. Use Excel or something to generate the alphabetical unique variable names. Remove the class from the project when you hit the limit, or comment out blocks of 100 unique variables..

I'd rather lean on the compiler (which defines how many variables are too many) than on some 3rd party tool anyway.

(oh crud, sorry to necro - didn't notice the dates)

Stopoff answered 16/3, 2010 at 19:41 Comment(0)
L
-1

It seems that Compuware's DevPartner had that kind of code analysis. I don't know if the current version still supports Visual Basic 6.0. (But at least there's a 14-day trial available)

Lenard answered 17/4, 2009 at 13:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.