|
-
Oct 27th, 2000, 08:25 AM
#1
Thread Starter
Lively Member
Stupid question, but I'm use to using "Stop" from VBscript, and I noticed that was the same as a breakpoint in VB6 Studio.
-
Oct 27th, 2000, 08:36 AM
#2
Guru
Here's the best way to close the application (anything but the EVIL statement, End):
Code:
' If you have just one form:
Call Unload(Me)
' If you have multiple forms:
Dim Form As Form
For Each Form In Forms
Call Unload(Form)
Next
-
Oct 27th, 2000, 10:16 AM
#3
Frenzied Member
For the first time in my VB career I don't agree with Yonatan 
I think this is the proper way to unload your form:
Code:
Private Sub From_Unload(Cancel As Integer)
Dim Frm As Form
For Each Frm In Forms
Unload Frm
Set Frm As Noting
Next Frm
End 'this is ok in this case!
End Sub

Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Oct 27th, 2000, 10:21 AM
#4
Fanatic Member
-
Oct 27th, 2000, 10:22 AM
#5
Fanatic Member
??
For the first time I disagree with Jop
For Each Frm In Forms
Unload Frm
Set Frm As Noting ??????????? --- = Nothing (Noting is the infinitive of the verb to Note...)
Next Frm
Sorry Jop!... I couldn't resist....
-
Oct 27th, 2000, 10:30 AM
#6
Frenzied Member
-
Oct 27th, 2000, 10:33 AM
#7
Guru
-
Oct 27th, 2000, 01:49 PM
#8
It is good to set the form to nothing so it frees up any resources and use the Unload statement with it as well.
That's very good Yonatan. So many mistakes! Glad you aren't a teacher .
And lighten up on Jop, he had the idea.
I'm not disagreeing with anyone.
But here, use this code.
I'm right, as usual, your all wrong! 
Code:
Public Sub UnloadAllForms()
Dim Form As Form
For Each Form In Forms
Unload Form
Set Form = Nothing
Next Form
End Sub
Usage
UnloadAllForms
-
Oct 27th, 2000, 02:20 PM
#9
Fanatic Member
Matthew, this code looks better... 
Code:
Public Sub UnloadAllForms()
Dim Form As Form
For Each Form In Forms
Unload Form
Set Form = Nothing
Next Form
End Sub
-
Oct 27th, 2000, 02:25 PM
#10
Guru
Originally posted by Matthew Gates
I'm not disagreeing with anyone.
...
I'm right, as usual, your all wrong!
Self-contradiction sucks. 
Anyways, as I said, only one instance of each form exists, until it is unloaded with Unload.
So, Set Form = Nothing won't help with anything, and will only make it a few milliseconds slower.
You agree that this code:
Code:
For Each Form In Forms
Call Unload(Form)
Next Form
Is pretty much equivalent to:
Code:
Set Form = Form1
Call Unload(Form) ' Now Form1 is invalid
Set Form = Form2
Call Unload(Form) ' Now Form2 is invalid
Set Form = Form3
Call Unload(Form) ' Now Form3 is invalid
' And so on... (Form1 and Form2 and Form3 were all in memory)
So, how would this help?
Code:
Set Form = Form1
Call Unload(Form) ' Now Form1 is invalid
Set Form = Nothing ' Why? It is already 100% not in memory,
' and now Form points at something illegal and setting it
' to Nothing doesn't do anything.
Set Form = Form2 ' VB says: "It was just Nothing! Jeez!"
Call Unload(Form)
Set Form = Nothing
Set Form = Form3 ' "Make up your mind!"
' Etc.
So, I just proved that I'm right 99% of the time, and besides, I don't care about the remaining 3%. 
Lighten up some more? I tried, but couldn't jam any more smilies into that post. 
Well, that was useless, but fun!
Yeah, and by the way, indentation rocks.
-
Oct 27th, 2000, 02:27 PM
#11
Fanatic Member
Originally posted by Yonatan So, I just proved that I'm right 99% of the time, and besides, I don't care about the remaining 3%.  [/B]
100 - 3 = 97
-
Oct 27th, 2000, 02:31 PM
#12
Guru
oetje: It's because there are three kinds of people in the world. Those who can count and those who can't.
-
Oct 27th, 2000, 02:33 PM
#13
Fanatic Member
Poor
Poor Hambone....!
He just asked a question he thought was a stupid question..!
Ha!!Ha!!
-
Oct 31st, 2000, 09:31 AM
#14
transcendental analytic
the remaining 3% Yonatan, is coming back to get you
Because you ever wondered why End has remained intact upto vb6 even if it has such a bad reputation. I'm using it regulary, and i'm going to use it as often as i can (just kidding).
Code:
Public Declare Function GetTickCount Lib "kernel32" () As Long
Private die As Long, temp As Class1
Sub main()
Set temp = New Class1
Form1.Show
DoEvents
Do
If Forms.Count Then
DoEvents
Else
If die Then
If GetTickCount > die Then End 'Exit Do
Else
die = GetTickCount + 1000
End If
End If
Loop
End Sub
Now actually i'm sure you can change this a bit and solve it wihtout End, but that's not the point. The point is that i have a break in class1 terminate event, and
1. It doesn't fire when End is used
2. It fires when Exit Do is used.
That means End don't unload properly, but if you exit the code the sub main, it will. If you on the other hand use unload statement to unload the object, the codes will be equal. That's why End has this bad reputation. Now what proves you can have use of End? Well it's simple, if you just unload everything correctly, it can be equally usefull as a exit do, or exit for in a loop. Might not be much use but when you get into complicated algoritms, it can.
t h E E n d
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Oct 31st, 2000, 10:08 AM
#15
Fanatic Member
Unloading Forms
Hmmm.
Set frm = Nothing - releases a reference
Unload frm - Unloads the form and kills references
Neither is foolproof since if you access the forms properties in the Unload Event it will maintain the Instance Data associated with the form - the form might disappear from view but you won't have cleaned up properly...
Your approaches are all far too wimpish...
Take the BRS approach (Big Red Switch) for those who remember the IBM PC (original). Turn the bugger off and you will DEFINITELY release that memory.
So you might get a bit of data corruption - means they have to rely on some guru to fix it...
Wonder who that might be?
Hehehe.
Cheers all,
Paul
Not nearly so tired now...
Haven't been around much so be gentle...
-
Oct 31st, 2000, 10:33 AM
#16
Lively Member
Sub ExitForms()
Dim iFormCount As integer
For iFormCount = Forms.Count - 1 To 0 Step -1
Unload Forms(iFormCount)
Next iFormCount
End
Exit Sub
This will also do - a little bit simple compared to the above but it works. It ensures all the forms are unload before closing the application.
H.
-
Oct 31st, 2000, 10:50 AM
#17
Hyperactive Member
You do need to Set frm = Nothing to release a form completely from memory, according to the help file:
"The only way to release all memory and resources is to unload the form and then set all references to Nothing. The reference most commonly overlooked when doing this is the hidden global variable mentioned earlier. If at any time you have referred to the form by its class name (as shown in the Properties Window by the Name property), you've used the hidden global variable. To free the form's memory, you must set this variable to Nothing."
This quote is under "Life Cycle of Visual Basic Forms" in MSDN.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|