Home All Groups Group Topic Archive Search About

Code Runs During Compile

Author
26 Mar 2009 11:28 PM
Bee
I have a app that contains a usercontrol in the project.
The usercontrol is on one form.
When I compile it runs the usercontrol code during the writing phase of the
compile.
What causes this and is there a way to avoid it?

The compile errors out because in the usercontrol it calls a sub that has a
filename that is not defined yet  and is trying to open the un-named
file(gets defined in the main app when it runs).
I have a Debug.Assert False in the error handler and the compile writing
stops dead there.
I OK then I F8 it until it completes but I am not totally sure if the
compile is good.
No other errors occurr.

What's up with that?
VB6 SP6

Author
27 Mar 2009 12:39 AM
Larry Serflaten
"Bee" <B**@discussions.microsoft.com> wrote
> I have a app that contains a usercontrol in the project.
> The usercontrol is on one form.
> When I compile it runs the usercontrol code during the writing phase of the
> compile.
> What causes this and is there a way to avoid it?

Try checking the AmbientProperties object (UserMode) and see if
that will help....

LFS
Author
27 Mar 2009 12:41 AM
MikeD
Show quote Hide quote
"Bee" <B**@discussions.microsoft.com> wrote in message
news:4A48CDEF-DC68-42F1-9337-44DA585FB3CE@microsoft.com...
>I have a app that contains a usercontrol in the project.
> The usercontrol is on one form.
> When I compile it runs the usercontrol code during the writing phase of
> the
> compile.
> What causes this and is there a way to avoid it?
>
> The compile errors out because in the usercontrol it calls a sub that has
> a
> filename that is not defined yet  and is trying to open the un-named
> file(gets defined in the main app when it runs).
> I have a Debug.Assert False in the error handler and the compile writing
> stops dead there.
> I OK then I F8 it until it completes but I am not totally sure if the
> compile is good.
> No other errors occurr.
>
> What's up with that?


I just ran a simple test (added a Debug.Print "<eventname>" to a few events
and checked the immediate window to see what got printed) and confirmed the
Initialize event is fired during compilation.  This was a Standard EXE
project with a UserControl added to it.  I don't know if this event would
fire if the UserControl were instead part of an ActiveX Control project when
you compile (easy enough to test this too I guess....nope, not in my test at
least). I can't say I know why this event fires when you compile, but for
whatever reason VB instantiates the usercontrol during compilation (also
don't know if this would be considered a bug or if it's maybe documented
somewhere).

It looks like you'll just need to write code to deal with it. Perhaps you
can check to see if Len(filename) = 0 and not run your code to open the file
if it is (or better, only attempt to open it if Len(filename) >0). Or
perhaps you'll need to do something a bit more drastic. If worse comes to
worst and you can't work around this any other way, I suppose you could make
your UserControl an OCX instead of that module just being added to another
type of project.

--
Mike
Author
27 Mar 2009 1:20 AM
Nobody
"Bee" <B**@discussions.microsoft.com> wrote in message
news:4A48CDEF-DC68-42F1-9337-44DA585FB3CE@microsoft.com...
> is there a way to avoid it?

http://vbnet.mvps.org/code/core/isinide.htm
Author
27 Mar 2009 2:08 AM
MikeD
"Nobody" <nob***@nobody.com> wrote in message
news:uwsv9onrJHA.2484@TK2MSFTNGP03.phx.gbl...
> "Bee" <B**@discussions.microsoft.com> wrote in message
> news:4A48CDEF-DC68-42F1-9337-44DA585FB3CE@microsoft.com...
>> is there a way to avoid it?
>
> http://vbnet.mvps.org/code/core/isinide.htm
>

I don't think you understood the problem. <g>

--
Mike
Author
27 Mar 2009 2:46 AM
Eduardo
Show quote Hide quote
"Bee" <B**@discussions.microsoft.com> escribió en el mensaje
news:4A48CDEF-DC68-42F1-9337-44DA585FB3CE@microsoft.com...
>I have a app that contains a usercontrol in the project.
> The usercontrol is on one form.
> When I compile it runs the usercontrol code during the writing phase of
> the
> compile.
> What causes this and is there a way to avoid it?
>
> The compile errors out because in the usercontrol it calls a sub that has
> a
> filename that is not defined yet  and is trying to open the un-named
> file(gets defined in the main app when it runs).
> I have a Debug.Assert False in the error handler and the compile writing
> stops dead there.
> I OK then I F8 it until it completes but I am not totally sure if the
> compile is good.
> No other errors occurr.
>
> What's up with that?
> VB6 SP6

Yes, some events are fired when you compile. But I think there must be
something wrong with the design. What UserControl event is triggering that
file read?  I think you should explain how your code works in order to help
you find out what's wrong and what to change. I can guess that you shouldn't
be reading that file at that time.