Option Explicit

LadyDi

Registered User.
Local time
Today, 12:40
Joined
Mar 29, 2007
Messages
894
I just have a quick question for you. I had an interview the other day and the manager conducting the interview asked me what the definition for "Option Explicit" is. Unfortunately, I do not know the definition for that phrase, I just know that it is needed at the beginning of a module. I was wondering if one of you could tell me what "Option Explicit" means. I have a second interview and want to be prepared incase they ask that question again. Thank you very much for your assistance.
 
What was unclear/unsatisfactory about the explanations found using google?
 
I agree with spike but perhaps you've been looking at very technical definitions:

With Option Explicit every variable and object must be declared. If the compiler finds a word that hasn't been declared (a typo for instance) it won't compile (will raise a compilation error).

Without Option Explicit, if the compiler finds a word that hasn't been declared it will immediately declare it as a new variant. Therefore any typo in the code won't be reported as an error - it will become a new variable. This can lead to very hard to find bugs that produce erratic behavior but don't throw errors. So, always use Option Explicit.
 
In my dB, In one form's codes, I did not use "Option Explicit" but now I wanted to. So, after doing so, it gives error that "txtClosingDate" is not defined as a variable. I just wanted to know where I should I declare the variables and the way to do so.

Thanks and best regards.
 
OK, to directly answer the question:

You declare variables with Dim inside a sub
Dim txtClosingDate As String

or with Private or Public outside a sub
Private txtClosingDate As String
Public txtClosingDate As String


However, that variable name looks like it might be meant to be a reference to a textbox control. If so then, either it's spelt wrong or the control has been deleted.

Either way, Option Explicit has informed you of a bug in your code.

Only you can tell what should be done with it:
Declare the variable,
Correct the spelling
or
Delete the line (or block) that uses it
 

Users who are viewing this thread

Back
Top Bottom