Re: Call statements

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




"Ralph" <nt_consulting64@xxxxxxxxx> wrote in message news:ef53Hj1DIHA.5160@xxxxxxxxxxxxxxxxxxxxxxx

"Pop`" <nodoby@xxxxxxxxxxxxxxxxxxx> wrote in message
news:17MQi.5770$2o1.3334@xxxxxxxxxxx
Hi,

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
far
nothing untoward has happened, but, though I do NOT Plan to leave that
there, I did the test because I've received some pretty strong advice to
NOT
call buttons or set them to True; instead, create a separate sub for the
code. But there wasn't any reasoning behind the advice, that I can find
now,
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

.



Relevant Pages

  • Re: Problems call DataAdapter.Update and Concurrency
    ... I use a command builder for update command as I want to make use of the ... as soon as the data gets changed it causes a concurrency violation. ... calling the .fill and avoiding another trip to the database. ... By default the DataAdapter will call AcceptChanges on each succesfull ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Adept: Discwasher calling-four
    ... Instead, you insert Discwasher's Calling Four card into slot number seven of the Apple's main board, which is no problem at all if your Apple is accompanied by its manual. ... A connector from the expansion card then plugs into the spot where the joy stick, say, would normally plug into the computer, and the joy stick plug goes into the new card, along with those of any three other controllers you might want to use. ... True, only a single command is involved, but there are preliminaries to be attended to, and here the manual accompanying Calling Four begins to let the novice down. ...
    (comp.sys.apple2)
  • Re: Thread Question
    ... thread start command". ... # He meant calling direct vs. subclassing. ... outros povos sem travar batalha, ...
    (comp.lang.python)
  • Re: Lets leave this confusion and all this illusion behind in the world
    ... has directly commanded you to bless those who curse you. ... sons of vipers is just as bad as calling them dimwits or dopes. ... You aren't Jesus. ... There is no command not to call anyone names. ...
    (soc.religion.quaker)
  • Re: Lets leave this confusion and all this illusion behind in the world
    ... has directly commanded you to bless those who curse you. ... sons of vipers is just as bad as calling them dimwits or dopes. ... You aren't Jesus. ... There is no command not to call anyone names. ...
    (soc.religion.quaker)