"Ralph" <
nt_consulting64@yahoo.com>wrote in message
Quote
"Steve Barnett" <noname@nodomain.com>wrote in message
news:u5S6IznoGHA.148@TK2MSFTNGP04.phx.gbl...
>I only have two objections to using With...
>
>Most of the times I used it for anything non-trivial, I ended up removing
it
>due to the bugs it introduced. Of course, this might be because my
>non-trivial code is usually related to automation of one of the MS-Office
>packages, so it might just be that it's not compatible with automation,
>where there is a lot of cross application interaction, which must make
>memory management and the marshalling of data a nightmare for the
>compiler
>writers.
>
Would be very interested in knowing more about these "bugs" that are
introduced when using a With...End With statement.
Prety much what we've been discussing in this thread... code that works on
one machine and fails on another machine, where you can't see any obvious
difference. I've even had apps that work on one machine at the beginning of
the week and are failing days or weeks later. A reboot fixes them
(sometimes).
I can't be more specific, because the errors, by their very nature, aren't
that predictable.
With Word, I've had automation commands that are processing data in a loop
and that will work for dozens of iterations and will then fail for no
apparent reason. I use the usual developer get-out and ask if they can
reproduce the problem and, more often than not, they can't or it happens in
a different place. I generaly put it down to "load ont he machine" and told
the users to close a few apps before trying again.
This solution is utterly unacceptable, so I started playing around and, at
some stage, removed the With statements. Removing the With fixed the issue.
Quote
>
>The second is basically coding style. I just prefer to ensure that
>everything that can self document does so. By using With, you disconnect
>a
>property or method from the object to which it relates.
>
Another interesting observation. How does bracketing related properties
and
methods within a defined block of code lead to a "disconnection"?
As defining subroutines and functions leads to even a greater
"disconnection" I can only assume your advice is to avoid them as well.
-ralph
It's seen two things that led me to this... a piece of code that was setting
the properties of a zip ActiveX. It started with a With statement and went
on for 70 lines before the End With. In and of itself, that's probably not a
problem, but I couldn't get on with this style. If I can't see the With
statement within one scroll of the screen, then it's too far away from what
I'm doing.
The other example was written by one of our contract developers where there
were only 20 (roughly) items in the list, but there was a With nested within
another With. Perfectly acceptable. The fun began when he commented out one
of the With statements in a debugging session and missed one of the
properties. Debugging took somewhat longer than he expected.
It's only my opinion and my coding style, but I prefer the visibility
offered by having to name the object you're referring to.
Steve
-