| |
|
Welcome to KnowledgeSutra - Dear Guest | |
[tutorial] Visual Basic 6
#1
Posted 10 February 2005 - 03:25 AM
End stops the program immediately without any thought as to what's going on - it's like a high speed train hitting a brick wall. It can cause unwanted errors and is bad programming practice in general. END gets rids of the form, but NOT its leftovers. This leaves a bunch of memory that will still be in use even after your program has supposedly closed. An object or variable won't be terminated properly - it's just not a graceful exit.
The only time that it's okay to use end is in Form_Load, because there is essentially nothing to unload. Ending the program abruptly also ignores whatever code you have in your Form Terminate, Unload, or UnloadQuery subs.
If you don't have leftover objects that you have neglected to nullify (ie - you are a really meticulous coder) and you don't have multiple forms loaded all at once, then "unload me" is the correct thing to do. Otherwise, putting a variation of the following in your Unload sub is the best:
Code:
Private Sub Form_Unload(Cancel as Integer)
On Error Resume Next 'should be at the top of this sub regardless of circumstances
' If you only have 1 form:
Dim o As Object
For Each o In Me
Set o = Nothing
Unload o
Next
' If you have multiple forms and you want to close the entire app:
Dim f As Form
For Each f In Forms
Set f = Nothing
Unload f
next
' If you have multiple forms and possible leftovers (this is the best way, just to be safe):
Dim o As Object
Dim f As Form
For Each f In Forms
For Each o In f
Set o = Nothing
Unload o
Next
Set f = Nothing
Unload f
Next
' NOW you can put whatever you want, because you safely and methodically cleaned up your program's trail:
Unload Me
End ' you can even put end if you really really want, because at this point it's safe and there's no garbage left to clean up
End Sub
#4
Posted 30 August 2008 - 07:48 AM
[tutorial] Visual Basic 6
Replying to iGuest
Haha aiite m8 prety much
Imagine this
You got 1 form, say form1 , and you have a command button rite
And you got one that you want to open , called form 2
What you want is
When say
Sub_command_click
Form1.Visible = False
Form2.Visible = True
and yeh.. Thats it HAHAH
So prty much, when that BUTTON is click
BAM!, form 1 = disappeared
Form 2 = INFRONT OF YOU = 0
Haha <3 hope that helps m8
Xx.
-reply by TheLove
#5
Posted 30 August 2008 - 07:50 AM
[tutorial] Visual Basic 6
Replying to iGuest
Haha aiite m8 prety much
Imagine this
You got 1 form, say form1 , and you have a command button rite
And you got one that you want to open , called form 2
What you want is
When say
Sub_command_click
Form1.Visible = False
Form2.Visible = True
and yeh.. Thats it HAHAH
So prty much, when that BUTTON is click
BAM!, form 1 = disappeared
Form 2 = INFRONT OF YOU = 0
Haha <3 hope that helps m8
Xx.
-reply by TheLove
#7
Posted 15 May 2009 - 05:00 PM
There is a small problem with the code snippets - the object should be unloaded before being deallocated:
Dim o As ObjectFor Each o In Me Unload o Set o = Nothing NextDim f As FormFor Each f In Forms Unload f Set f = Nothing nextDim o As ObjectDim f As FormFor Each f In Forms For Each o In f Unload o Set o = Nothing Next Unload f Set f = Nothing Next
#8
Posted 03 June 2009 - 06:40 PM
If that is not the case, I would love to enlightened. Regardless, it is a good language to get started in. The syntax might not make sense at first, but it is a pleasure once you understand it.
#9
Posted 05 June 2009 - 05:13 AM
FeedBacker, on Mar 9 2008, 03:09 PM, said:
[tutorial] Visual Basic 6
Can somone Please post a snippet of code on how to close a form and open one in a button.
-question by Sanyo
FeedBacker, on May 20 2008, 02:34 AM, said:
[tutorial] Visual Basic 6
How to show multiple form in visual basic
-reply by mahaveer
me.hide show.form2
and
to open multiple what do you mean like on startup or open them 1 by one?
#10
Posted 20 January 2010 - 09:14 AM
cgom, I wished people like you didn't exist. I really do. Forget his poor English, just can't understand why people post their stupid feelings or comments like this, when no one cares. This post was to help, or get info, and this cgom retard gives us all what he thinks without so much as offering it's help (notice I said it's). If you're so "cool" and "moved on" then why are you posting here. Oh, wait! Oh, I get it, because you know nothing.
In fact, thank you cgom, this world DOES need idiots like you. If you didn't exist, then who will we take our money from?
sad /txtmngr/images/smileys/smiley6.Gif
Reply to this topic

1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users














