Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making the VB compiler warn when I don't declare variables properly

How can I make the VB6 compiler fail when I forget to declare a variable?

This would stop various typing errors (both keyboard and data types) and errors like this when it tries to access something unexpected.

Problems caused by not correctly declaring variables:

  • Unexplained errors when using an undefined variable, but is in fact pointing to somehting else
  • Variables having different values at different times, due to spelling mistakes
  • Trying to access variables outside of their scope appearing to by uninitialised
like image 929
Deanna Avatar asked Feb 16 '23 21:02

Deanna


1 Answers

You should use Option Explicit. This should be put on the first line of every module and form's code section.

You can also configure the VB6 IDE to add this automatically to all new modules by going to Tools > Options > Require Variable Declaration.

like image 180
Deanna Avatar answered Feb 19 '23 11:02

Deanna