Jump to content
xisto Community
Sign in to follow this  
zachtk8702

[tutorial] Visual Basic 6 Closing Programs Right, Why END is bad

Recommended Posts

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 ObjectFor Each o In Me Set o = Nothing Unload oNext' If you have multiple forms and you want to close the entire app:Dim f As FormFor Each f In Forms Set f = Nothing Unload fnext' If you have multiple forms and possible leftovers (this is the best way, just to be safe):Dim o As ObjectDim f As FormFor Each f In Forms For Each o In f Set o = Nothing Unload o Next Set f = Nothing Unload fNext' NOW you can put whatever you want, because you safely and methodically cleaned up your program's trail:Unload MeEnd ' 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 upEnd Sub

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

how to show multiple form in visualbasic

[tutorial] Visual Basic 6

 

How to show multiple form in visual basic

 

-reply by mahaveer

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
...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 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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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


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

me.hideshow.form2

 

 

 

and

 

 

 

to open multiple what do you mean like on startup or open them 1 by one?

Share this post


Link to post
Share on other sites
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 /txtmngr/images/smileys/smiley6.Gif

Share this post


Link to post
Share on other sites

the syntax is very similar because they are both basic compilers and with very basic knowledge of both you could convert visual basic 6.0 to visual basic 2008 and if you can't do it then just ask you are on http://forums.xisto.com/ :)
Best wishes, caleb :)

I don't think so. It's alot different like C#'s web request and whatnot... The functions have similar names like messagebox.display("") and msgbox("").. i really don't know what would be what.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.