VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Importance of Option Explicit

by Triumph (2 Submissions)
Category: Coding Standards
Compatability: Visual Basic 5.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (13 Votes)

So many people (especially beginners) do not realize the importance of the simple statement Option Explicit in their code. Find out why it is so important.

Rate Importance of Option Explicit


The Importance of Using Option Explicit



Many programmers (especially new ones) neglect the use of the Option Explicit statement in their programs. THIS IS VERY BAD CODING!!! I have seen many programs not run at all, much less properly because of not having this simple statement. As a matter of fact, Visual Basic makes it simple to include this sttement in all of the programs you write. Go to Tools > Options > Editor (tab) > "Require Variable Declaration". Check it. It does not appear in the program you have running, but the next new one you open will have it.


"Why is it so important to include this?" you ask. Well, there are many reasons.

1. It stops you from making costly errors.


Without Option Explicit, if you spell a variable wrong in a procedure, Visual Basic will think you are trying to create a new vairable and will create one for you. Then, if you try to read that same variable later on (this time spelling it correctly) it will not have the desired value.


2. It is good coding practice.


I know a man who interviews programmers, and the first question he asks in the interview is, "What is Option Explicit?" If they don't know or answer incorrectly, they are not hired. Then, he asks them when they use it, and, usually, if the answer is not "always", they don't get the job. Option Explicit is extremely important when working with other people. Making a spelling error in your code, which you know because you wrote, may be easy to find. But, if someone else, who does not know your code so well, tries to find it, it could take hours. 

 


Overall, using Option Explicit is a good idea, and saves you time and sanity. I know this was not a long drawn out tutorial, but so many people do not use it, and it is so important that they do.

Download this snippet    Add to My Saved Code

Importance of Option Explicit Comments

No comments have been posted about Importance of Option Explicit. Why not be the first to post a comment about Importance of Option Explicit.

Post your comment

Subject:
Message:
0/1000 characters