[AccessD] listbox question

Henry Simpson hsimpson88 at hotmail.com
Fri Sep 5 19:08:17 CDT 2003


Steve:

Good intentions I'm sure.  I used to do exactly the same thing until I read 
otherwise in the 97 version of the Access Developer's handbook.  Quite 
frankly, I doubt you'd see even a few milliseconds in a full 64K item 
listbox.  It is still worthwhile keeping table data types small as the time 
to transfer bytes over a LAN or even from a local disk is greater than the 
time taken to convert to a processor friendly long.

Not to be obtuse, but what the code does and what the comment says it does 
are not in concurrence.
What the code does is pass an object variable and that is, in my opinion, 
the best possible way to implement a procedure of this nature.  Dimensioning 
a 'ListBox' variable rather than a 'Control' variable was merely a 
suggestion but is not by any means necessary.  What is not correct is that 
it is not the name of the control you are passing, qualified or otherwise, 
but an object variable.  The object variable points to the object but the 
NAME itself is not passed as suggested in the comment.  Although you have 
not explicitly stated so in the comment, the comment implies that the 
parameter is a string variable.  Given that the comment is supposed to 
clarify the meaning of the parameters, it may be confusing to people who 
wonder how one ought to pass a fully qualified name.  This can be misleading 
to consumers of your function and in my opinion, the usage of your function 
would have been clearer had you not included the comment.

I have always written this procedure as a sub rather than a function and 
generally use an 'On Error Resume Next' in the error handler for the 
improbable evenuality that the object variable is destroyed within the 
routine as it cannot be set to nothing if it doesn't exist.  Although the 
function's parameter type checking should prevent nearly every possible 
misadventure relating to an invalid object, I've found it never hurts to use 
an abundance of caution.  For this reason also my preference is to explictly 
pass a variable of ListBox type.  I can imagine one or two situations where 
one might need the return value from such a function though I have yet to 
experience the need and I note that your function doesn't set the return 
value in your posted routine.  You can probably save both a few bytes of 
memory and a few processor cycles if you don't need a return value and just 
define the routine as a sub procedure.

Here I am being unnecessarily particular again.  Sorry.  I think your 
example is a pretty darn good and useful procedure that responded well to a 
need and went beyond as an example of using a general reusable procedure.  
Credit to you and I'll just shut up again for a while.

Hen

>From: "Steve Capistrant" <scapistrant at symphonyinfo.com>
>Reply-To: Access Developers discussion and problem 
>solving<accessd at databaseadvisors.com>
>To: "Access Developers discussion and problem 
>solving"<accessd at databaseadvisors.com>
>Subject: RE: [AccessD] listbox question
>Date: Fri, 5 Sep 2003 15:48:28 -0500
>
>Henry, you make my head hurt.
>
>But seriously, thanks for the comments; we've got hundreds of functions in
>which we consciously chose the smaller data type in an effort to be more
>efficient, and it sounds like that is just an example of good intentions
>with opposite results.
>
>Regarding this comment....
>
>------snip begin-------
>The comment suggests that it is a fully 'articulated' (qualified?) name and
>spells out what appears to be misconstrued as a string name.  What is
>actually being passed is an object variable by reference which amounts to 
>no
>more than a long pointer directly to the object in situ
>--------snip end -------
>
>...Yes, I meant "qualified".  But I don't understand what is wrong with the
>parameter being sent, and how it might be done differently.
>
>Steve Capistrant
>Symphony Information Services
>scapistrant at symphonyinfo.com
>Phone: 612-333-1311
>www.symphonyinfo.com
>212 3rd Ave N, Ste 404
>Minneapolis, MN 55401
>
>
>-----Original Message-----
>From: accessd-bounces at databaseadvisors.com
>[mailto:accessd-bounces at databaseadvisors.com]On Behalf Of Henry Simpson
>Sent: Friday, September 05, 2003 11:56 AM
>To: accessd at databaseadvisors.com
>Subject: RE: [AccessD] listbox question
>
>
>Just another comment on the comments pertaining to the parameters and the
>parameters themselves.  First, the function definition accepts a parameter
>of type 'Control' which, although acceptable, is not as narrow as it could
>be for the intended purpose.  It would be more accurate to define that
>parameter as type 'ListBox' and that permits intellisense and autocomplete.
>In a sense, the converse is true of the other parameter; although a byte is
>the most limited variable one can use to pass one of eight choices and it
>only uses 8 bits whereas a boolean requires 16.  But long gone are the days
>where the extra 24 bits of a 32 bit long will run an application out of
>memory.  Although an application may benefit in terms of storage and LAN
>traffic from using a smaller datatype when many records reside in large
>tables, there is a small overhead when converting the smaller datatype for
>use by a 32 bit operating system that results in superior performance with 
>a
>long datatype.  As the parameter being passed is a single value, it is more
>efficient to use a long.  The iteration variable is typed as an Integer
>which is all that is required as the scroll bar of list boxes constrains 
>the
>number of elements in a list box to exactly the number addressble by an
>integer but it too is more efficient as a Long.  For a mere 16 bits of RAM,
>a loop that may run up to 64K times is a bit faster and that is a 
>worthwhile
>tradeoff.
>
>The comment suggests that it is a fully 'articulated' (qualified?) name and
>spells out what appears to be misconstrued as a string name.  What is
>actually being passed is an object variable by reference which amounts to 
>no
>more than a long pointer directly to the object in situ.  I always add an
>'invert' option for those cases where you want to select all items except
>one or two.  That way it is easy to click on the exceptions and invert the
>selections.  For this purpose it is useful to declare three Long constants
>to pass.  The third Case (invert) might look like this (if one changes the
>iteration variable to a Long for the reasons mentioned above, named lngI):
>
>
>     Case 3
>         For lngI = 0 To ctlList.ListCount - 1
>             ctlList.Selected(lngI) = cltList.Selected(lngI) + 1
>         Next
>
>
>Hen
>
> >From: "Steve Capistrant" <scapistrant at symphonyinfo.com>
> >Reply-To: Access Developers discussion and problem
> >solving<accessd at databaseadvisors.com>
> >To: "Access Developers discussion and problem
> >solving"<accessd at databaseadvisors.com>
> >Subject: RE: [AccessD] listbox question
> >Date: Fri, 5 Sep 2003 08:03:57 -0500
> >
> >Call this public function from any form that has a list box.  It can be
> >used
> >to SELECT ALL or UNSELECT ALL items.
> >----------------
> >
> >Public Function FillClearListBox(ctlList As Control, bytAction As Byte) 
>As
> >Boolean
> >'Selects or Deselects all items in list box
> >Arguments:
> >     'ctlList: the fully articulated name of the listbox (e.g.
> >Forms!frmMyForm!lstMyList)
> >     'bytAction: The type of action desired; 1=Select All, 2=Unselect All
> >
> >On Error GoTo eh
> >
> >     Dim intItem As Integer
> >
> >'Loop through each item on list and either select or deselect it.
> >     For intItem = 0 To ctlList.ListCount - 1
> >         Select Case bytAction
> >             Case 1:  ctlList.Selected(intItem) = True
> >             Case 2:  ctlList.Selected(intItem) = False
> >         End Select
> >     Next
> >
> >ex:
> >     Set ctlList = Nothing
> >     Exit Function
> >eh:
> >     MsgBox Err.Description
> >     GoTo ex
> >End Function
> >--------------------------
> >
> >Steve Capistrant
> >Symphony Information Services
> >scapistrant at symphonyinfo.com
> >Phone: 612-333-1311
> >www.symphonyinfo.com
> >212 3rd Ave N, Ste 404
> >Minneapolis, MN 55401
> >
> >
> >-----Original Message-----
> >From: accessd-bounces at databaseadvisors.com
> >[mailto:accessd-bounces at databaseadvisors.com]On Behalf Of Dale Kalsow
> >Sent: Friday, September 05, 2003 7:41 AM
> >To: accessd at databaseadvisors.com
> >Subject: [AccessD] listbox question
> >
> >
> >Ok,  I know this should be easy but I am still having a problem with it.
> >Does any know how to select all of the items in a listbox?
> >
> >Thanks!
> >
> >Dale

_________________________________________________________________
The new MSN 8: smart spam protection and 2 months FREE*  
http://join.msn.com/?page=features/junkmail



More information about the AccessD mailing list