Re: Call statements
- From: "DanMH" <noreply@xxxxxxxxxxxx>
- Date: Tue, 16 Oct 2007 08:22:09 -0800
"Ralph" <nt_consulting64@xxxxxxxxx> wrote in message news:ef53Hj1DIHA.5160@xxxxxxxxxxxxxxxxxxxxxxx
"Pop`" <nodoby@xxxxxxxxxxxxxxxxxxx> wrote in message
news:17MQi.5770$2o1.3334@xxxxxxxxxxx
Hi,far
What is the "danger" in calling command buttons or setting their state =
true in VB6 code?
I have a fair amount of repetitive code, sometimes exactly what a command
button does and so far I've been creating separate subs to hold such code.
e.g. if I have a cmdDoIt_click() I'll create a 'Private Sub DoIt' and dump
the code into that for reuse instead of calling the button.
Instead of duplicating in a few instances, just for grins to see what
happens, I've been Call-ing command buttons or setting them to True. So
nothing untoward has happened, but, though I do NOT Plan to leave thatNOT
there, I did the test because I've received some pretty strong advice to
call buttons or set them to True; instead, create a separate sub for thenow,
code. But there wasn't any reasoning behind the advice, that I can find
at least.
Since nothing untoward has happened, then there must be some other,
possibly non-techical reason for not doing that. I'm hoping someone can
give me the reasoning behind it. It's a "head-around" thing<g>.
To add to the pile.
The only real "danger" in invoking controls in this manner, is if you use it
too much you can end up with "spaghetti events". A play on the term for
"spaghetti code" for when you abuse Gotos. A particular nasty Gotcha is
when, in your enthusiasm, you create a circular call - this button invokes
this listbox which invokes the original button. Usually such mistakes are
readily apparent - but on occasion can be hidden and intermittent and quite
fustrating.
Second, as noted by the others, it is always best to separate Presentation
from Function. It allows you more flexibility during development and
maintenance. So if you confine your calls to simplifying navigation or
defining "Form State" they can be useful. But like all techniques slightly
outside 'normal' procedures they can also be opportunities for confusion.
-ralph
To extend on Ralph's comments, not only is it "best to separate Presentation
from Function", but also you can achieve better "portability" if you separate the function from presentation.
Name your function with a title that represents it's actions. Later, you can use this same chunk of code in other projects. It's
always best to use code that has already been "worked out".
There is another way to look at this. Try to structure your programming so that another person can come in and understand what you
have done. By hiding the function behind the GUI, it is harder to understand it's functionality than if you had placed the
"operational" code into it's own code segment and called it from there.
If I were to look at your code to try to understand how something was working, I would look for a code segment that would be named
for it's purpose. Trying to understand code that references btnDoThis.Value = True is more obscure than calling the routine
"OpenDatabase".
Just my 2cents.
DanMH
.
- Follow-Ups:
- Re: Call statements
- From: Pop`
- Re: Call statements
- References:
- Call statements
- From: Pop`
- Re: Call statements
- From: Ralph
- Call statements
- Prev by Date: Re: VB6 & Vista
- Next by Date: Re: Can't Find Installable ISAM
- Previous by thread: Re: Call statements
- Next by thread: Re: Call statements
- Index(es):
Relevant Pages
|