• Welcome to Valhalla Legends Archive.
 

Connecting,Connected,Diconnected

Started by Miccolo, August 03, 2003, 02:54 PM

Previous topic - Next topic

dxoigmn

#15
Quote from: Camel on August 10, 2003, 04:07 PM
Never use incomplete sentances!!  Instead you should making all the words being in the sentance.

What's so horrible about End?

From Hardcore Visual Basic by Bruce McKinney

Quote
WARNING Terminating a duplicate instance is one of those rare cases when you should actually use the End statement. Although the name sounds harmless, End is actually more like an Abort statement that means stop by any means even if it can't do normal cleanup. Experienced Visual Basic programmers terminate their programs by unloading all the active forms. Normally, all it takes is an Unload Me statement in the main form. But if you're trying to terminate in the main Form_Load, there is, by definition, nothing to unload. So the rule is simple: Never use End except in Form_Load. In the first edition of this book, I violated this rule by providing a procedure that looked for a duplicate instance and terminated that instance with an End statement inside the procedure. I got a rude surprise when I tried to put that procedure in the VBCore component. Visual Basic won't let you use the End statement in a DLL or a control.

Oh and by the way, while we're on the subject of critizing simple mistakes, it's "sentence."

Grok

#16
Quote from: kamakazie on August 10, 2003, 04:35 PM
From Hardcore Visual Basic by Bruce McKinney

... is an Unload Me statement in the main form. But if you're trying to terminate in the main Form_Load, there is, by definition, nothing to unload. So the rule is simple: Never use End except in Form_Load. ...

Except this is wrong.  Form_Load fires after the process has been created, thus there is something to unload.  If Form_Load fired before you had a process, you could not run any code in the procedure.

Private Sub Form_Load()
   Set gObj1 = CreateObject("BlahLib.X1")
   Set gObj2 = CreateObject("BlahLib.Y2")
   Set gObj3 = CreateObject("BlahLib.Z3")
   Set gObj4 = CreateObject("BlahLib.A4")
   Set gObj5 = CreateObject("BlahLib.B5")
   End
End Sub

Now who do you suppose is going to do the cleanup on the 5 out-of-process servers just created?

Yoni

IIRC, Unload Me in Form_Load works fine. But I could be wrong, and I'm not going to test this, of course.

QuoteNow who do you suppose is going to do the cleanup on the 5 out-of-process servers just created?
Bruce McKinney, apparently.

Camel

Quote from: Yoni on August 13, 2003, 12:21 PM
QuoteNow who do you suppose is going to do the cleanup on the 5 out-of-process servers just created?
Bruce McKinney, apparently.
Good call.

Adron

Private Sub Form_Load()
   Open "c:\temp\tempfile.tmp" for output as #1
   Unload Me
End Sub

Now who do you suppose is going to do the cleanup of your temp file?

Camel

Quote from: Adron on August 13, 2003, 01:28 PM
Private Sub Form_Load()
   Open "c:\temp\tempfile.tmp" for output as #1
   Unload Me
End Sub

Now who do you suppose is going to do the cleanup of your temp file?

That's simply poor code.

Skywing

Quote from: Adron on August 13, 2003, 01:28 PM
Private Sub Form_Load()
   Open "c:\temp\tempfile.tmp" for output as #1
   Unload Me
End Sub

Now who do you suppose is going to do the cleanup of your temp file?
CreateFile(FileName, Access, ShareMode, SecAttrs, Disposition, FILE_FLAG_DELETE_ON_CLOSE | Attrs, Template);

Adron

Quote from: Skywing on August 13, 2003, 04:34 PM
Quote from: Adron on August 13, 2003, 01:28 PM
Private Sub Form_Load()
   Open "c:\temp\tempfile.tmp" for output as #1
   Unload Me
End Sub

Now who do you suppose is going to do the cleanup of your temp file?
CreateFile(FileName, Access, ShareMode, SecAttrs, Disposition, FILE_FLAG_DELETE_ON_CLOSE | Attrs, Template);

Exactly!

The problem is not that of using the End or the Unload Me statements!

You just have to be aware of what other calls you use and how to ensure that they are cleaned up.

RhiNo

christ didnt think it was that big of a deal and if he made a bot im sure he dont want it to unload in form load cause that defeats the perpose of making a bot to stay online