From: AR88 Enthusiast on
I'm only raw beginner but what about unload me?

<ducks while experts throw things>

"Bee" <Bee(a)discussions.microsoft.com> wrote in message
news:97B227F0-BB50-4D26-B16C-56C12F432F35(a)microsoft.com...
> Down in the bowels of my VB6 app I need to ask the user to do something or
> "die".
> That is the way it is and I cannot change this structure.
> I have seen applications that use >>> End <<<.
> And I have seen many comments about NOT using End.
> So
> (1) what exactly does End do that is so bad?
> (2) seen Stop too.
> (3) how can I exit the app politely but immediately?
>
> How about calling a sub in a module that calls _unload in the main form?
>
> However, there may be flags set that the main form is supposed to process
> so
> I would have to clear all of those and not do that processing.
>
> Educate me.
>


From: Mayayana on
I always use a Sub Main and an ending sub I call
DropIt, for anything more than 1 form. It seems to
work best to do things from QueryUnload. You can
call your version of DropIt from anywhere in code, but
you may need to handle other closing messages, too,
like a click on the X in the control box.

See the QueryUnload docs for options. UnloadMode
tells you where the quit message is coming from. For
instance, if the person clicks the form close X in the
control box, but they're in the middle of an operation,
you might want to show a msgbox:

If UnloadMode = 0 and SomethingElse = True then
cancel = 1 ' stop the shutdown.
Ret = Msgbox("Are you sure you want to quit?", 36)
If Ret = 6 then Dropit
ElseIf UnloadMode = 1 then 'called from code.
'--confirm quit here
Else
DropIt '-- UnloadMode is > 1. No choice here, Just quit.
End If


From: Mayayana on
One other point I should have mentioned:
Assuming you have multiple forms with
control boxes, and only one is the main program
form, you'll want to block those from unloading
or calling your shutdown sub unexpectedly:

If unloadmode = 0 then
cancel = 1
FormThis.Hide
End If


From: Nobody on
"Bee" <Bee(a)discussions.microsoft.com> wrote in message
news:97B227F0-BB50-4D26-B16C-56C12F432F35(a)microsoft.com...
> Down in the bowels of my VB6 app I need to ask the user to do something or
> "die".
> That is the way it is and I cannot change this structure.
> I have seen applications that use >>> End <<<.
> And I have seen many comments about NOT using End.
> So
> (1) what exactly does End do that is so bad?
> (2) seen Stop too.
> (3) how can I exit the app politely but immediately?
>
> How about calling a sub in a module that calls _unload in the main form?
>
> However, there may be flags set that the main form is supposed to process
> so
> I would have to clear all of those and not do that processing.

What specific situation are you after?

If you have a Timer that you are using in frmMain to process stuff, you can
add a public routine to frmMain, "CloseMe" that disables the Timer and clear
any flags before unloading other forms.


From: Helmut Meukel on
"Bee" <Bee(a)discussions.microsoft.com> schrieb im Newsbeitrag
news:97B227F0-BB50-4D26-B16C-56C12F432F35(a)microsoft.com...
> Down in the bowels of my VB6 app I need to ask the user to do something or
> "die".
> That is the way it is and I cannot change this structure.
> I have seen applications that use >>> End <<<.
> And I have seen many comments about NOT using End.
> So
> (1) what exactly does End do that is so bad?
> (2) seen Stop too.
> (3) how can I exit the app politely but immediately?
>
> How about calling a sub in a module that calls _unload in the main form?
>
> However, there may be flags set that the main form is supposed to process so
> I would have to clear all of those and not do that processing.
>
> Educate me.
>


Hmmm,

I've heard many arguments over the years against End and I know most are valid.
Just let me tell you all a real life story:

Some 10 years ago, I was working on a customers site to upgrade one of my
own programs, when they had a problem with one of their knitting machines.
Some of those machines were enhanced with NT4-boxes with some i/o-cards
connected to the machine. I had also worked as subcontractor for the engeneering
company who built those systems and programmed the data access part of their
program.
They used this NT4-box instead of a PLC to control the knitting machine
to produce made-to-measure stockings.
On one of the boxes the program refused to start, saying "Can't run twice".
I checked it with taskmanager and there really was already an instance of the
program without showing up on the screen. I asked some questions and found it
only happend on one box, and their last resort was to power down machine and
NT4-box and restart both.
I telephoned with the engeneering company and they said they knew but had
nobody who could come in the next 6 or 8 weeks. "Hey, can't you look into it?"

I did and found the program tried to shut down after some communication
problem with the machine and failed.
When started again it looked if there was already an instance running, found the
old no longer responding instance and stopped execution. This was intended,
you can't have two instances of the program concurrently controlling the
machine.

I had never looked into the code controlling the machine and found at first
glance
nothing that could cause this shut-down failure. Debugging wasn't easy, even
just running the program within the IDE on the NT4-box could create new
errors due to the overhead of the IDE on a box with only 16 MB memory.
So I inserted an End statement, compiled the app and let it run.
I was for some more days there and my "fix" seemed to work without obvious
problems.
I wrote a report to the engeneering company, and warned that it was a
quick-and-dirty solution and they should try to find the real cause and fix it.

Some years later I was hired by the engeneering company to combine the
different versions of this program into one. They had different versions due to
hardware differences, i/o-cards sitting in different slots with different
addresses...
and when they fixed some bug in one version they hadn't always checked the
other versions if the fix was needed there too.
During this work I found they had ignored my warning, instead they had added
the End statement to the other versions, too.
I called one of the bosses and tried to convince him to let me search the cause
of the glitch and really fix it.
I got the answer: "We couldn't find the source of the glitch and the End worked
just fine, so let it there, we don't intend to spend more money on this!"

Two years ago the knitting company went out of business, the machines and
the NT4-boxes were sold to Italy. I never heard anything about it, the program
with the End statement will probably still run there.

Helmut.

First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4 5 6 7 8 9 10 11 12
Prev: Convert UTF-16 Unicode to UTF-8 Unicode?
Next: API-Guide