[AccessD] How explicit do you need to be?

Jim Dettman jimdettman at verizon.net
Mon May 3 05:57:29 CDT 2010


Hi Darryl,

  Welcome back!  Hope your enjoying the new role.

  For the most part, I'm always explicit as possible, although I don't quite
go as far as doing .value for controls, which is the default property for
controls.

  As far as using with, that's not a matter of being explicit; it's just a
matter of using an optimization built into VBA. You still being explicit and
VBA knows exactly what you are referring to.  When you do this: 

With me
  .txtFarm.Visible = False
End with


  VBA knows for sure that it's really:

 me.txtFarm.Visible = False

 that your referring to and because it already has a pointer to it, it's
faster if you have a bunch of statements all referring to the same object. 

 I also do things like:


  Dim db as DAO.Database
  Dim rst as DAO.Recordset

  Rather then:

  Dim db as Database
  Dim db as Recordset

  
  Normally, most think it doesn't make a difference unless you have
conflicting libs (ie. recordset is an object both in DAO and ADO).

  Well first, I don't know if or when I might add ADO to a project, so it's
good to have them on.  Second it's faster because VBA knows exactly which
lib reference I mean.  It doesn't have to go down the reference list and
poll each one like it normally would at runtime asking each one "Do you have
a recordset object?"  All it needs to do is locate the lib.

   To me, it always seems best to be as explicit as possible.

FWIW,
Jim.

  


-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Darryl Collins
Sent: Monday, May 03, 2010 12:39 AM
To: accessd at databaseadvisors.com
Subject: [AccessD] How explicit do you need to be?


____________________________________________________________________________
___________

Note: This e-mail is subject to the disclaimer contained at the bottom of
this message.
____________________________________________________________________________
___________


Hi Folks,

Finally back on the list after changing roles.
Curious about this.
Personally I have always been very precise with references etc as it seems
to improve performance and reliability.  However, does it really matter that
much?
For example what are the advantages and/risk of using the following syntax

x = txtMyTextBox  VS  x = me.txtMyTextBox.value

Or

txtFarm.Visible = False
lblFarm.Visible = False
txtHire.Visible = True
lblHire.Visible = True

VS

With me
        .txtFarm.Visible = False
        .lblFarm.Visible = False
        .txtHire.Visible = True
       .lblHire.Visible = True
End with

I would normally always use the longer syntax, although for typing reasons I
can see the appeal of the shorter style.  In the case of the first example,
I guess the .value is the default so that is probably redundant, although I
like the way it is clear exactly what it is you are looking at/for.

So what would be considered 'best (or better) practice' with coding for this
example?  Or more importantly, which style will return the results faster
and reliably?

Cheers
Darryl.

_____________________________________

Darryl Collins | Database Developer
Insurance Australia Group
+ 61 3 9916 3926 (Desk)
+ 61 418 381 548 (Mobile)



____________________________________________________________________________
___________

The information transmitted in this message and its attachments (if any) is
intended 
only for the person or entity to which it is addressed.
The message may contain confidential and/or privileged material. Any review,

retransmission, dissemination or other use of, or taking of any action in
reliance 
upon this information, by persons or entities other than the intended
recipient is 
prohibited.

If you have received this in error, please contact the sender and delete
this e-mail 
and associated material from any computer.

The intended recipient of this e-mail may only use, reproduce, disclose or
distribute 
the information contained in this e-mail and any attached files, with the
permission 
of the sender.

This message has been scanned for viruses.
____________________________________________________________________________
___________
-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com




More information about the AccessD mailing list