What is option explicit? Why it is applied?
Printable View
What is option explicit? Why it is applied?
It forces you to predeclare your variables before using them.
Use Option Explicit tol avoid using variables which are not needed or used in the program. Useless variables eat up memory.
Basically you use it to catch any spelling mistakes. Mispelled variables will be declared as variants when they come into scope which, as well as taking up memory, will cause your code to go screwy and make it v. hard to debug. Always use it!
You should add an Option Explicit statement at the very beginning of the code module so that Visual Basic will automatically trap any attempt to use a variable that isn't declared anywhere in the program code. By this single action, you'll avoid a lot of problems later in development phase.
If you go Tools -> Options and then check Require Variable Decleration, then it will always be placed at the top of any new form, module, class etc that you create (no need to write it in)