Re: UserForm Data Validation. I tried and tried but can't figure it out.
- From: "Tony Jollans" <My Forename at My Surname dot com>
- Date: Mon, 12 Dec 2005 08:24:28 -0000
> > I would strongly recommnend that you never explicitly declare a variable
> > with the same name as the default instance. While it will work within
the
> > routine which contains the declaration, there is tremendous scope for
> > confusion since the default instance will still work from any other
> routine.
> > It will be preety much impossible to know whether the specific or the
> > default instance is in use.
> >
>
> It is not good practice to declare variables with the same name both at
> module level and procedure level. That has got nothing to do with
UserForms.
>
> As already said, I should have been clearer about the scope of the
default
> instance.
>
Sorry, Jonathan, that reads as a bit abrupt - it was not meant that way. I
never meant to suggest that a name be used for more than one instance but I
can see how that could perhaps arise from what I wrote. Your warning is a
good reminder that it is important to understand the scope of names -
especially 'hidden' ones - and to avoid writing code that will confuse
humans even if the machine understands perfectly well.
--
Enjoy,
Tony
"Tony Jollans" <My Forename at My Surname dot com> wrote in message
news:Oh5a27b$FHA.3096@xxxxxxxxxxxxxxxxxxxxxxx
> Hi Jonathan,
>
> >
> > More accurately this
> >
> > Public UserForm1 As New UserForm1
> >
>
> Agreed, Public UserForm1 ... is more correct than Dim UserForm1 ... I
> should have made this clearer.
>
> >
> > Better to keep the terminology straight. It loads the default instance
> > (called UserForm1) of the UserForm1 object.
> >
>
> I deliberately didn't want to differentiate between the default instance
> and non-default ones. The behaviour of both is the same - only in the case
> of the default one there is, effectively, a hidden declaration.
>
> >
> > I would strongly recommnend that you never explicitly declare a variable
> > with the same name as the default instance. While it will work within
the
> > routine which contains the declaration, there is tremendous scope for
> > confusion since the default instance will still work from any other
> routine.
> > It will be preety much impossible to know whether the specific or the
> > default instance is in use.
> >
>
> It is not good practice to declare variables with the same name both at
> module level and procedure level. That has got nothing to do with
UserForms.
>
> As already said, I should have been clearer about the scope of the
default
> instance.
>
> --
> Enjoy,
> Tony
>
>
> "Jonathan West" <jwest@xxxxxxxx> wrote in message
> news:#hwskvb$FHA.740@xxxxxxxxxxxxxxxxxxxxxxx
> >
> > "Tony Jollans" <My Forename at My Surname dot com> wrote in message
> > news:e4stiob$FHA.4012@xxxxxxxxxxxxxxxxxxxxxxx
> > > Loading and unloading forms is really quite complex and the behaviour
is
> > > not
> > > quite the same in all Word versions.
> > >
> > > What I presume is meant by "magic forms support." is the implicit
> > > instantiation of userforms on first reference. A Userform definition
is
> an
> > > object definition - it contains the Form and a Class Module. When you
> have
> > > a
> > > UserForm in your project you also have, in effect, this module-level
> > > declaration ...
> > >
> > > Dim UserForm1 As New UserForm1
> >
> > More accurately this
> >
> > Public UserForm1 As New UserForm1
> >
> > This hidden public declaration is generally called the default instance,
> but
> > called the magic form by some.
> >
> > >
> > > Which declares (and tells VBA to load on first use) an object
variable,
> > > called UserForm1, of type UserForm1. You can explicitly code this if
you
> > > like
> > >
> > > Whenever you reference Userform1, if it does not point to an actual
> > > UserForm1 object,
> >
> > Better to keep the terminology straight. It loads the default instance
> > (called UserForm1) of the UserForm1 object.
> >
> > > one is automatically created. You can, if you like make
> > > the instantiation slightly more obvious by using "Load UserForm1" but
> that
> > > doesn't really do anything. This, for example:
> > >
> > > Load UserForm1
> > > Msgbox UserForm1.Frame1.Caption
> > >
> > > is the same as this:
> > >
> > > Msgbox UserForm1.Frame1.Caption
> > >
> > > If you don't do the Load explicitly, it is automaticaly done for you.
> The
> > > userform's Initialize event is fired when the userform is loaded.
> > >
> > > You can override the implicit instantiation if you want To stop the
> > > default
> > > declaration being provided you can explicitly code:
> > >
> > > Dim UserForm1 As UserForm1 ' Without the New keyword
> >
> > I would strongly recommnend that you never explicitly declare a variable
> > with the same name as the default instance. While it will work within
the
> > routine which contains the declaration, there is tremendous scope for
> > confusion since the default instance will still work from any other
> routine.
> > It will be preety much impossible to know whether the specific or the
> > default instance is in use.
> >
> >
> > --
> > Regards
> > Jonathan West - Word MVP
> > www.intelligentdocuments.co.uk
> > Please reply to the newsgroup
> > Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
> >
>
>
.
- Follow-Ups:
- Re: UserForm Data Validation. I tried and tried but can't figure it out.
- From: Jonathan West
- Re: UserForm Data Validation. I tried and tried but can't figure it out.
- References:
- UserForm Data Validation. I tried and tried but can't figure it out.
- From: Greg Maxey
- Re: UserForm Data Validation. I tried and tried but can't figure it out.
- From: Helmut Weber
- Re: UserForm Data Validation. I tried and tried but can't figure it out.
- From: Greg
- Re: UserForm Data Validation. I tried and tried but can't figure it out.
- From: Helmut Weber
- Re: UserForm Data Validation. I tried and tried but can't figure it out.
- From: Greg Maxey
- Re: UserForm Data Validation. I tried and tried but can't figure it out.
- From: Tony Jollans
- Re: UserForm Data Validation. I tried and tried but can't figure it out.
- From: Jonathan West
- Re: UserForm Data Validation. I tried and tried but can't figure it out.
- From: Tony Jollans
- UserForm Data Validation. I tried and tried but can't figure it out.
- Prev by Date: Re: Chechbox problem
- Next by Date: Re: User Defined Object
- Previous by thread: Re: UserForm Data Validation. I tried and tried but can't figure it out.
- Next by thread: Re: UserForm Data Validation. I tried and tried but can't figure it out.
- Index(es):
Relevant Pages
|
Loading