Jump to content



Welcome to KnowledgeSutra - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!
- - - - -

[tutorial] Visual Basic 6


12 replies to this topic

#1 zachtk8702

    Member [Level 2]

  • Kontributors
  • PipPipPipPipPip
  • 81 posts

Posted 10 February 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

#2 iGuest

    Hail Caesar!

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,876 posts
  • Interests:Trap17 Free Web Hosting, No Ads

Posted 09 March 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

#3 iGuest

    Hail Caesar!

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,876 posts
  • Interests:Trap17 Free Web Hosting, No Ads

Posted 20 May 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

#4 iGuest

    Hail Caesar!

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,876 posts
  • Interests:Trap17 Free Web Hosting, No Ads

Posted 30 August 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

#5 iGuest

    Hail Caesar!

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,876 posts
  • Interests:Trap17 Free Web Hosting, No Ads

Posted 30 August 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

#6 tinoymalayil

    Premium Member

  • Kontributors
  • PipPipPipPipPipPipPipPip
  • 154 posts
  • Gender:Male
  • Location:India
  • myCENT:23.11

Posted 23 April 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

#7 iGuest

    Hail Caesar!

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,876 posts
  • Interests:Trap17 Free Web Hosting, No Ads

Posted 15 May 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 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 cgom

    Newbie

  • Kontributors
  • Pip
  • 4 posts

Posted 03 June 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.

#9 Gravity17

    Member [Level 1]

  • Kontributors
  • PipPipPipPip
  • 50 posts

Posted 05 June 2009 - 05:13 AM

View PostFeedBacker, on Mar 9 2008, 03:09 PM, said:

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


View PostFeedBacker, on May 20 2008, 02:34 AM, said:

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.hide
show.form2





and



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

#10 iGuest

    Hail Caesar!

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,876 posts
  • Interests:Trap17 Free Web Hosting, No Ads

Posted 20 January 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 /txtmngr/images/smileys/smiley6.Gif






Reply to this topic


This post will need approval from a moderator before this post is shown.

  


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users