VB6: disable options

I have large VB6 projects where many variables do not have an explicitly defined type, so they automatically use the Variant type by default. Finding it all manually is a huge task, so is there a way to automate this? In VB.Net, you can turn off all automatic use of options using "Option Strict", but VB6 does not have this option.

Right now I have added DefByte AZ for each class, which makes the default type “Byte” instead of “Variant”. This allows me to intercept many undefined variables at runtime as soon as they are assigned a value greater than 255. But it is still not fully tested by the fool.

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

+7
source share
4 answers

I used Aivosto Project Analyzer to pick up such things. There is a demo version that will give you an idea of ​​what it can do.

+5
source

Decorate your modules with Option Explicit .

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

Option Explicit , however, will not prevent declarations of type variables without restrictions, for example

 Dim i 

The variable i will be declared as an option, and no compiler error will be selected even with Option Explicit .

+4
source

I don’t think there is a “reliable” way to detect all undefined variables. However, the Option Explicit statement requires that all variables be declared in the module in which the statement is displayed, so the compiler will flag all instances; this is not the case. There is also an IDE option that automatically adds this statement to the beginning of any new module.

+2
source

Use the programmer’s text editor (I use UltraEdit) and do a bulk search of your project source directories.

Start by looking for Variant (obviously), although you probably already did.

Next, use a regular expression type search for something line by line:

  *Dim [a-zA-Z][a-zA-Z0-9_]*\p 

This should get a Dim x script without an end As DataType .

Use *Dim [a-zA-Z][a-zA-Z0-9_]*,.* To search for script types Dim a, b, c As Integer .

Use *Dim .*, [a-zA-Z][a-zA-Z0-9_]*,.* For scenarios with an odd ball, for example Dim a As Integer, b, c As Long

Repeat the above bindings with Private and Global instead of Dim , and this should get almost everything.

+2
source

All Articles