Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB6: Disable variants

I have a large VB6 projects where a lot of variables don't have an explicitly defined type, so they automaticly default to Variant type. Finding all those by hand is a massive task, so is there any way to automate this? In VB.Net it's possible to disable all automatic use of variants using 'Option Strict', but VB6 doesn't have that option.

Right now I added DefByte A-Z to every class, which makes the default type 'Byte' instead of 'Variant'. This let me catch a lot of undefined variables at run-time, as soon as they are assigned a value larger than 255. But it's still not fully fool-proof.

Is there a more reliable way to detect all undefined variables?

like image 362
Maestro Avatar asked Jan 19 '12 13:01

Maestro


2 Answers

I used to use Aivosto's Project Analyzer to pick up things like this. There's a demo version which will give you a good idea what it can do.

like image 191
MartW Avatar answered Nov 11 '22 13:11

MartW


Decorate your modules with Option Explicit.

This phrase should go at the top of each module you create. When done so, it will cause a compiler error when undeclared variables are encountered.

Option Explicit will not, however, prevent type-less variable declarations, such as

Dim i

The variable i will be declared as a variant, and no compiler error will be thrown even with Option Explicit defined.

like image 25
ken Avatar answered Nov 11 '22 11:11

ken