Re: UserForm Data Validation. I tried and tried but can't figure it out.



> > 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
> >
>
>


.



Relevant Pages

  • Re: which compiler is right?
    ... >> neither a primitive subprogram nor is overriding. ... I'm not sure how this is pertinent, since the routine causing the ... a declaration can override another homograph if the declaration ... in a nested inner package, it cannot override a routine declared ...
    (comp.lang.ada)
  • Re: Intermittent Error 12 - Variable Not Found
    ... routine in which they are defined. ... Variable declared PRIVATE work more like what you described. ... A private variable's scope is that of the ... overridden by another declaration further down the call tree. ...
    (microsoft.public.fox.programmer.exchange)
  • Re: Reported any bugs in C-LAPACK routine DSPEVX?
    ... >>and call the latest Fortran LAPACK routines directly. ... For the dstevx routine I do it like this. ... the declaration can be done also in a header.h file which is ... There exists other ways of including lapack routines into C. ...
    (sci.math.num-analysis)
  • Re: F200x (was Re: When to expect a F2003 compiler?)
    ... Fortran 90 chose to ... > hobble it. ... If the called routine is declared as having CONTROLLED ... (and the declaration must match the declaration in ...
    (comp.lang.fortran)
  • Re: object as parameter
    ... Though it doesn't affect the results in any way, the last declaration might ... lead to confusion as the parameter shouldn't be notated or make any ... suggestion it might be a "bstr". ... It is a Variant with type VT_DATE and value ...
    (microsoft.public.vb.general.discussion)

Loading