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

free web hosting
Open Discussion > CONTRIBUTE > Tutorials

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

zachtk8702
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

 

 

 


Reply

iGuest
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

Reply

iGuest
how to show multiple form in visualbasic
[tutorial] Visual Basic 6

How to show multiple form in visual basic

-reply by mahaveer

Reply

iGuest
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

Reply

iGuest
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

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Recent Queries:-
  1. visual basic webbrowser href= - 0.19 hr back. (2)
  2. vb newbie tutorial - 1.91 hr back. (1)
  3. close vb 6 form - 2.37 hr back. (1)
  4. open form and close another form vb 6.0 - 2.61 hr back. (1)
  5. visual basic free tutorial open form from command button - 3.09 hr back. (1)
  6. close form vb6 - 3.46 hr back. (1)
  7. vb close form - 7.18 hr back. (1)
  8. visual basic 6.0 closing form - 7.99 hr back. (1)
  9. visual basic 6.0 launch start execute batch program - 8.62 hr back. (1)
  10. close form in visual basic 6.0 - 9.67 hr back. (1)
  11. close application basic visual 6 - 12.03 hr back. (1)
  12. vb6 form nothing unload - 15.02 hr back. (1)
  13. make an ftp program in visual basic 2008 tutorial - 20.24 hr back. (1)
  14. closing visual basic 6 form - 20.47 hr back. (1)
Similar Topics

Keywords : visual, basic, 6, closing, programs, end, bad

  1. Ftp In Visual Basic 6.0
    Start making your FTP client using VB6 (1)
  2. Start Multiple Programs With One Shortcut
    Windows XP (15)
    Welcome to my turoial on how to start multiple programs using one shortcut. You may probably be
    wondering how this is possible. Well this tutorial will use a language from MS-DOS called batch. I
    am not sure whether it is "language", but I do know that it is a way to program for MS-DOS. Batch is
    simply a way to run several MS-DOS commands with just one command. All batch files are run through
    Command Prompt, but they can be accessed with shortcuts also. Here are a few requirements for this
    tutorial. Requirements Windows XP (I tested this on XP, but it should work on m....
  3. Reducing Windows Vista Start Menu Programs Response Time.
    How to do it. (4)
    If you have been using Microsoft Windows Vista for quite some time, you would have noticed that
    installing a number of programs/softwares into your computer considerably slows down the response
    time of your start menu program folder, sometimes up to one second or more before the programs
    listed in a particular start menu folder is displayed. Worst of all, if you are trying to launch a
    program from you start menu which is within another start menu prrograms folder. Well, I have found
    a way to bypass this very annoying thing in Windows Vista. I have about 98 start menu en....
  4. Giving Important Programs Priority
    Alloacating more resorces with Windows XP (2)
    If you want to allocate more resources to an important program you are running do the following: 1)
    press ctrl+alt+delete 2) select the "processes" tab 3) find the program you are using and
    right-click on it 4) on the drop down bar that appears scroll over "select priority" 5) select
    "high" (CAUTION DO NOT SELECT "REALTIME" AS THIS MAY IMBALANCE YOUR SYSTEM) 6) A warning will
    appear, click yes If you follow these easy steps you will find that whatever program you have done
    this to should run faster and more efficiently. However, this is something that must be done each....
  5. Creating A Timer Program
    Using Visual Basic 2005 (8)
    This tutorial will explain how to create a basic timer using Visual Basic Express 2005. If you
    don't have it, it's free and you can dowload it from Microsoft's website. All you need
    is a few minutes to sit down and read this and a version of Visual Basic. OK, so what will this
    timer actually do? Well, you are able to enter a number of minutes and a message, and then click a
    button. Once the timer is up, your message pops up and you are reminded! So, basically it's
    a little reminder system. I use it to remind me when TV programmes start, when I have to....
  6. Creating A Simple Image Viewer
    Using Visual Basic 2005 Express Edition (4)
    I downloaded Microsoft's Visual Studio Express suite a few months ago, but only recently got
    around to installing it. I have been practising with Visual Basic and making some rather basic
    programs and utilities, but they contain most of the basic concepts. This tutorial will explain how
    to create a basic image viewer, and I will try to explain each step from beginning to end as clear
    as I can. To start you will need: Microsoft Visual Studio About 10-20 minutes free time OK,
    first open up the Visual Basic part of the Studio. I am using the 2005 Express version, so....
  7. How To Make A Web Browser
    Visual Basic 6 (49)
    This is a simple and specific tutorial on how to make a basic web browser in Visual Basic 6. Steps
    1-3 Create a new project, and then go to "Project" on the menu. Click components as shown in the
    following image. Find the component "Microsoft Internet Controls," check it, and click "Apply" and
    then "Close." Click the icon that was just added in the tools window, and draw a large sized
    window with it. This is going to be where you view webpages through your browser, so don't make
    it small, but leave room for buttons and other accessories. Steps 4-6 Make a t....
  8. Bit Shifting In Vb
    Shifting bits in Visual Basic (0)
    This is for all Visual Basic programmers out there, who want to programm some form of encryption
    algorithm, or anything else that includes shifting bits left or right, for that matter. Most of you
    who have tried to accomplish this, know that Visual Basic doesn't have any function for bit
    shifting. And bit shifting si very usefull /smile.gif' border='0' style='vertical-align:middle'
    alt='smile.gif' /> Some of you probably know how to shift bits, but this tutorial is for those who
    don't know how to do it... Shifting bits is actualy easy, we use multiplication ....
  9. Simple Login In Visual Basic 6
    user interaction example trough login programm (6)
    First of all, I am NOT a programmer, this is something my friend taught me. It describes basic
    interaction with the user, while showing basic functionality of this simple programm. So, without
    further ado, we're off to the tutorial: First of all, start your visual basic, when prompted
    for new project, select Standard Exe . Next, we need to open code window, so we can start typing
    the program. This can be done in two ways, one is double clicking on the form, or selecting Code
    from View menu. If you double clicked on the form, you will see following text: CODE ....
  10. How To Remove Programs Safely
    Newbie Tutorial (3)
    How to properly remove programs from your computer: Windows 98 has added a little program that
    helps you delete applications safely and CORRECTLY. Why correctly? Because a lot of new software
    leaves entries in the Registry, and unless you uninstall your programs, the excess code gets left
    behind. Not so tidy. So when you want to uninstall an application, follow these steps: 1. Click
    Start. 2. Choose Settings then Control Panel. 3. In the Control Panel window, double-click the
    Add/Remove Programs icon. 4. Under "The following software can be automatically removed by Wi....
  11. Simple Visual Basic 6 Tutorial
    Tutorial 1: Msgbox (0)
    For this tutorial you will learn how to make a very simple, and basic program. Step one- Create a
    new form. Step two- Click the command button on the side and make two buttons. Step Three- Click
    on on of the command buttons you drew, and on the side there will be a menu. Change the caption to
    Button 1, and repeat the same with the other button, but the caption Button 2. Step four- Double
    click one of the buttons, and put in CODE Dim button button = MsgBox("What you want to
    say here", 65, "Title") Now change that code to what you want it ....
  12. [tutorial] Visual Basic 6
    Adding Commas to Large Numbers (0)
    This isn't a very long tutorial. I get asked this often, so here is the solution. The following
    code will return a string containing a number that has commas appropriately placed: Code:
    myStringOrProperty = FormatNumber(3587532789053, 0) The second parameter (0) represents how many
    decimal places you want the returned number to go out to. Unless your number contains its own
    decimal, you probably don't want .00 at the end of every number you have. The above code would
    return: 3,587,532,789,053 This should make life easier for many.......
  13. Security Programs And Links
    (2)
    I written this security advice for many support services/Forums so i decided to post a copy for
    Trap17 too.Well Choosing security software what's in that?Just install antivirus/firewall,keep
    it updated and Relax.No this will not help you at all.So in this Tutorial what i am going to cover
    is Security software (Antivirus & Firewalls Encryption software, Few utilities).At last i will
    also tell you what to do to avoid virus infecting from your PC. First Lets start with encryption
    software why we need it?Encryption software converts your data into secret code & to co....

    1. Looking for visual, basic, 6, closing, programs, end, bad

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for visual, basic, 6, closing, programs, end, bad

*MORE FROM TRAP17.COM*
advertisement



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



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE