Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable Not Defined

Status
Not open for further replies.

Vec

IS-IT--Management
Jan 29, 2002
418
US
When I try to compile an exe, I get a "Variable not defined" error
I need to turn this pesky thing off, as we all know, sometimes you don't need to define a variable and I am getting sick of this error checker. I have already UNchecked the Tools>Options>"Require Variable Declaration" check box, and it still does it.

Funny thing is that I have compiled this app before and have not changed anything in it. It created an exe no problem before, now suddenly it decides it doesn't "like" the code?????
-
teklogo.gif

 
You might want to take a look at the Project References and/or Components and see if one is MISSING. This situation sometimes leads to unpredictable errors.
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
You mean I can't turn of this idiot feature? If not, how do I check references etc, and also why would it compile before and with no changes, suddenly not? -
teklogo.gif

 

Yes you can turn off that valuable option. You may want to check each forms code and all modules to make sure that you do not have Option Explicit at the top of any of them. The error would crop up in that particular module because of those keywords. This can happen when copying code or importing code from other projects and then modifying that code.

Good Luck

 
That worked. What exactly does Option Expicit do? I understand the words, meaning that it is a very explicit option but how does vb apply this?
-
teklogo.gif

 

Option Explicit means that all variables must be declared before their use.

Good Luck

 
I think Cajun's answer is the closest to the mark.
You may have missed including the declaration, by not
including the reference or component it was declared in.
 
>as we all know, sometimes you don't need to define a variable

<sigh>
 
&quot;<sigh>&quot;

I know, I know... variables always should be declared. We also &quot;should always drive the speed limit, never eat a grape in the supermarket without paying for it first, always signal before we change lanes, etc, etc etc....

but lets be realistic here, anyone that always does exactly what we &quot;should&quot; do please speak up...............


(this is where the sound of crickets comes in)
:)

Thanks for all of your help everyone, and let not he be judged who would judge others. (Or something like that) -
teklogo.gif

 
Vec,
Variables should be declared. There is no practical reason not to do so, and countless reason to always explicity define your environment, including variable declarations. A minimal short term cost for a long term gain.

Laziness is no substitute for convenience. Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
...bridge builders should undertand the laws of physics, a right angle should be 90 degrees...
 
I am scared to think that ppl don't declare they're variables ... how is that NOT a headache down the track for the poor git who has to work out your source code.

Transcend
[gorgeous]
 
I know I know, OK, everybody can stop slapping my wrists now. I actually went in to the project after all of the frowning and declared all of the variables in the code and will do so from now on. I feel like a scolded child :-( -
teklogo.gif

 
I always declare my variables now and never drink and drive and very rarely speed.
Drinking and Driving (though i've never got in trouble for doing it because I never have) isn't worth the risk to me
Not declaring variables has burnt me so many times its not funny so its just easier declare them now.
Speeding well after getting $500 worth of speeding tickets in one week you'd think that I might never do it agian but I did after 4 years and got caught by a radar camera so maybe I won't ever do it agian.

All 3 have person impacts on me and possibly others. All 3 I'd like to say I try to adhere to because of potential impact on others but speeding came down to more how much it hit my wallet. $100 for just under 10k over the speed limit is just not worth it.

Glad the others guilted you into doing the right thing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top