Thursday, April 26, 2018

variables need to be explicitly declared even though óption explicit'option not given

INTRODUCTION
1. It is considered a good practice to use óption explicit'at the beginning of a module or code block, doing so, will need unique declaration of each variable in the module.

2. Though, this is good for organized coding, it can take the fun out of quick coding.

PROBLEM
1. I had not used option explicit anywhere, however, when a excel macro file developed elsewhere, was copied to my system, the code execution stopped at each undeclared variable. Declaring that variable solved the issue, however, code will stop at the next undeclared variable.

2. I checked the options menu in VB editor, "require variable declaration was also unchecked". This was a huge problem as I may have had dozens of undeclared variables. Why was I facing this problem in my home laptop while elsewhere it worked?

3. googled, found someone else also faced the same problem. The issue was using "References"which are not installed (Active X controls, like comctl2.ocx etc).

4. Clicked Tools-->References, and indeed there was highlighted a checkbox with "Missing: common controls (SP6). Unchecked this missing reference, and everything solved.  The code did not stop at any undeclared variable.

5. Meanwhile installed the common control active x and got the functionality was also obtained (separate blog post created for same)
 

No comments: