Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Which is best? form.show or form.visible

Status
Not open for further replies.

SkennyR

Programmer
Mar 7, 2004
157
US
When I first started programming with VB6, seems like the most popular way to load another form from within a form would be:
form2.visible = true

But lately I have seen a lot of people using:

form2.show

What is the main difference between these? And which is the preferred method?
Thanks.
 
There is technically no difference,

To Quote from VB5 Help Files:

"Note: Using the Show or Hide method on a form is the same as setting the form's Visible property in code to True or False, respectively."

However, in VB6 it has been the "Method with etiquette" to use the Show Method after you have loaded a form,
It appears that using the Show method ALWAYS ensures that the form is loaded, because it automatically invokes the loading of a form that is not already loaded.

Setting the visible property does do this aswell, but not under all circumstances, there was a blip in SP3 i think that caused certain forms with certain properties not to load when invoked using the visible property.

Also, it is impossible to use the 'MODAL' property when using the Visible Property to show a form. Which effectively disallows you the use of Code Stopping forms.

HTH.

JaG

yosherrs.gif

[tt]'Very funny, Scotty... Now Beam down my clothes.'[/tt]
 
Yes, the main reason to use Show is that it makes the load statement unnecessary. In this way, the load statement is only used when you want to initialize a form and call its load event handler prior to actually making it visible to a user.

The main reason that you might want to do that is in a form that requires some overhead to load, such as a form with a lot of graphics. You may want to assign the associated performance hit when the user first loads the program, rather than when he/she first accesses the form. In general, perceived overhead during initial load is much less than perceived overhead in the middle of a thought process.

Bob
 
I generally use Form.Load and then Form.Show when displaying forms. Many of my programs require loading another form from a double click on a row so it make sense for me to :

Load Form1

'Set some values on Form1

Form1.Show vbModal

It stops the screen from flickering and ,as JAG14 mentioned, many coding standards require you to load the form and then show it. If I ever see a Form.visible after a load then I change it to Form.Show.

I have always found the Show method to be more effective and ensure that the form is always loaded properly.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top