Home All Groups Group Topic Archive Search About

not getting 'variable not defined' with Option Explicit

Author
30 May 2009 12:27 PM
vbDavidC
I have an app that has multiple forms and procedures.  I added a
string variable to a new procedure (in a form module) without dim'ing
it and I am not getting a variable not defined error.  I am also able
to compile to an exe without any error messages.  That same variable
name is defined in a BAS module with a DIM.  I have OPTION EXPLICIT on
my first line of the FORM module.

I think I have seen this similar behavior before recently in a
different variable.  However, I noticed it but I shut down VB and
reopened my app and when I hit F5 it gave me the 'variable not
defined' error.  This is not happening this time though.

David

Author
30 May 2009 1:22 PM
Bob Butler
"vbDavidC" <davidsusergro***@yahoo.com> wrote in message
news:0e047110-26b6-4c06-88df-88cdc2dca3e0@z14g2000yqa.googlegroups.com...
>I have an app that has multiple forms and procedures.  I added a
> string variable to a new procedure (in a form module) without dim'ing
> it and I am not getting a variable not defined error.  I am also able
> to compile to an exe without any error messages.  That same variable
> name is defined in a BAS module with a DIM.  I have OPTION EXPLICIT on
> my first line of the FORM module.

try right-clicking the variable in the form code and selecting "Definition";
perhaps it is defined somewhere.  If that fails post the cod that references
the undeclared variable.
Author
30 May 2009 1:32 PM
Ralph
Show quote Hide quote
"vbDavidC" <davidsusergro***@yahoo.com> wrote in message
news:0e047110-26b6-4c06-88df-88cdc2dca3e0@z14g2000yqa.googlegroups.com...
> I have an app that has multiple forms and procedures.  I added a
> string variable to a new procedure (in a form module) without dim'ing
> it and I am not getting a variable not defined error.  I am also able
> to compile to an exe without any error messages.  That same variable
> name is defined in a BAS module with a DIM.  I have OPTION EXPLICIT on
> my first line of the FORM module.
>
> I think I have seen this similar behavior before recently in a
> different variable.  However, I noticed it but I shut down VB and
> reopened my app and when I hit F5 it gave me the 'variable not
> defined' error.  This is not happening this time though.
>
> David

The OPTION EXPLICIT Declarative only impacts parsing behavior in the module
where it appears.

You can insure all new modules have the Option declared by selecting
"Tools"->"Options" and click "Require Variable Declaration". This will not
retroactively add it to existing modules, you will have to do that manually.

Right-click on the offending variable and select "Definition". This will
take you the declaration.

-ralph
Author
30 May 2009 2:48 PM
vbDavidC
Thanks for the help.

I did have a declaration that I did not see before that I found based
on you input about Declaration.

One reason I thought I was right was because of my previous problem I
had mentioned.

thanks,