In Visual Basic 6, you can use a variable in code without declaring it, sometimes also known as implicit declaration. While it can be useful in some ways, it’s certainly not a good way of making sure that each variable exists and are being used where and when you want it to be used.
If you include the Option Explicit statement in a module, then VB will require explicit declarations for all variables in that module. Any misspelled variables, instead of being created as a new variable with a type of Variant which will happen if you’re using the implicit declaration mode, are now flagged as syntax errors when you try to run the program, and then you can make the necessary corrections. Place the Option Explicit statement at the start of each module (before any procedures). You can make this automatic by selecting Tools | Options and and selecting the Require Variable Declaration option.
Leave a Reply