Re: Passing "Controls" collection to a class method not defined in .ctl file

Tech-Archive recommends: Fix windows errors by optimizing your registry



Eric Chevalier wrote:
MsgBox "UserControl_InitProperties() has been invoked."

I'd *strongly* advise that you not use MsgBox to troubleshoot event firings. That's
just begging for trouble. That said...

I'm guessing that a key clue is the statement from the VB6 help file:
"InitProperties event occurs only ... when an instance of the control
is placed on a form.". That leads me to believe that InitProperties is
called only at *design time*, not runtime.

Which is, I suspect, what Larry was trying to get you to realize. As the helpfile
snippet he posted went on to say, ReadProperties is the other, far more common,
option for (post-siting) startup initialization.

The original developers of this application[1] apparently decided that
UserControl_Initialize was the best place to put a large body of
initializaton code.

It can be, but there are lines that must be drawn.

I'm not sure I agree with their decision, since
some of their logic has potential failure points, but there's
apparently no way to return a failure status to the caller of
UserControl_Initialize.

Right. Can't raise an error there, for one thing. And, as you've found, the
control hasn't been sited yet, either, which tends to introduce even more errors if
you depend on that.

But I'm stuck with the code the way it is. :-(

Bummer. I'd consider just shuffling stuff around a bit, stuffing most of that into
ReadProperties instead. Initialize is really only proper for assigning default
values to module-level variables.
--
..NET: It's About Trust!
http://vfred.mvps.org


.