IPB

Welcome Guest ( Log In | Register )



Tags
This content has not been tagged yet
 
Reply to this topicStart new topic

[tutorial] Visual Basic 6

Closing Programs Right, Why END is bad


zachtk8702
no avatar
Member [Level 2]
*****
Group: Members
Posts: 81
Joined: 3-August 04
Member No.: 609



Post #1 post Feb 10 2005, 03:25 AM
This tutorial applies to all those people who insist upon using "End" to close their programs:

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
Go to the top of the page
+Quote Post
iGuest
no avatar
Hail Caesar!
*********************
Group: Members
Posts: 5,876
Joined: 21-September 07
Member No.: 50,369



Post #2 post Mar 9 2008, 07:09 PM
How to close 1 form and open another in a button
[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
Go to the top of the page
+Quote Post
iGuest
no avatar
Hail Caesar!
*********************
Group: Members
Posts: 5,876
Joined: 21-September 07
Member No.: 50,369



Post #3 post May 20 2008, 06:34 AM
how to show multiple form in visualbasic
[tutorial] Visual Basic 6

How to show multiple form in visual basic

-reply by mahaveer
Go to the top of the page
+Quote Post
iGuest
no avatar
Hail Caesar!
*********************
Group: Members
Posts: 5,876
Joined: 21-September 07
Member No.: 50,369



Post #4 post Aug 30 2008, 07:50 AM
how to close a form, and open one in a button
[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
Go to the top of the page
+Quote Post
iGuest
no avatar
Hail Caesar!
*********************
Group: Members
Posts: 5,876
Joined: 21-September 07
Member No.: 50,369



Post #5 post Aug 30 2008, 07:48 AM
how to close a form, and open one in a button
[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
Go to the top of the page
+Quote Post
tinoymalayil
no avatar
Advanced Member
*******
Group: Members
Posts: 125
Joined: 20-April 09
From: India
Member No.: 80,483
myCENT:91.98



Post #6 post Apr 23 2009, 02:00 AM
VTC Tutorial for VB 6 is good..Please visit website of Virtual training Company to get VTC VB6 Video Tutorial
VTC Tutorials are helpful to study programming languages
Go to the top of the page
+Quote Post
iGuest
no avatar
Hail Caesar!
*********************
Group: Members
Posts: 5,876
Joined: 21-September 07
Member No.: 50,369



Post #7 post May 15 2009, 05:00 PM
...problem
[tutorial] Visual Basic 6

There is a small problem with the code snippets - the object should be unloaded before being deallocated:

Dim o As Object
For Each o In Me
    Unload o
    Set o = Nothing
Next

Dim f As Form
For Each f In Forms
   Unload f
   Set f = Nothing
next

Dim o As Object
Dim f As Form
For Each f In Forms
   For Each o In f
       Unload o
       Set o = Nothing
   Next
   Unload f
   Set f = Nothing
Next


Go to the top of the page
+Quote Post
cgom
no avatar
Newbie
*
Group: Members
Posts: 4
Joined: 3-June 09
Member No.: 82,818



Post #8 post Jun 3 2009, 06:40 PM
I don't mean to be rude... but VB 6 is still being used? It was the last version of VB before .NET was released, and I thought everybody had moved onto that.

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.
Go to the top of the page
+Quote Post
Gravity17
no avatar
Member [Level 1]
****
Group: Members
Posts: 50
Joined: 4-June 09
Member No.: 82,866
myCENT:58.97



Post #9 post Jun 5 2009, 05:13 AM
QUOTE (FeedBacker @ Mar 9 2008, 03:09 PM) *
How to close 1 form and open another in a button
[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



QUOTE (FeedBacker @ May 20 2008, 02:34 AM) *
how to show multiple form in visualbasic
[tutorial] Visual Basic 6

How to show multiple form in visual basic

-reply by mahaveer

To close 1 form and open another 1 is simply
CODE
me.hide
show.form2






and



to open multiple what do you mean like on startup or open them 1 by one?
Go to the top of the page
+Quote Post
iGuest
no avatar
Hail Caesar!
*********************
Group: Members
Posts: 5,876
Joined: 21-September 07
Member No.: 50,369



Post #10 post Jan 20 2010, 09:14 AM
cgom comment
[tutorial] Visual Basic 6

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



Go to the top of the page
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

    Topic Title Replies Topic Starter Views Last Action
No New Posts   0 Albus Dumbledore 3,218 18th June 2006 - 08:28 AM
Last post by: Albus Dumbledore
No New Posts   9 noxit 7,820 30th July 2004 - 02:57 PM
Last post by: templest
No new   32 ultrasmad 23,128 14th February 2005 - 11:01 AM
Last post by: Someone
No new   16 ultrasmad 12,812 21st May 2005 - 10:04 AM
Last post by: alexia
No New Posts   3 ultrasmad 6,866 30th July 2004 - 03:27 PM
Last post by: templest
No new   22 Shackman 39,118 27th October 2009 - 07:39 AM
Last post by: NxTGaming
No new   39 Bash 41,425 28th May 2009 - 01:47 AM
Last post by: nol
No New Posts   0 Jarlaxe 1,691 23rd June 2007 - 11:13 AM
Last post by: Jarlaxe
No New Posts   0 etycto 1,012 2nd September 2007 - 09:43 PM
Last post by: etycto
No New Posts   10 neeki4444 14,034 12th February 2009 - 08:32 AM
Last post by: iG-AeRo
No New Posts   7 truvu17 8,518 1st May 2006 - 03:20 PM
Last post by: shadowx
No New Posts   1 NeXDesigns 5,237 16th September 2004 - 07:46 PM
Last post by: ipunto21
No New Posts   7 NeXDesigns 4,908 30th September 2004 - 01:16 PM
Last post by: Amorphia
No New Posts   0 Zenchi 3,634 28th September 2004 - 03:35 AM
Last post by: Zenchi
No New Posts   3 X3r0X 5,493 28th September 2004 - 02:30 PM
Last post by: X3r0X


 



RSS Open Discussion Time is now: 22nd March 2010 - 03:51 PM

Web Hosting Powered by ComputingHost.com.
Xisto.com : HONESTY ROCKS! truth rules.
Creative Commons License