hide or close?

ssfftt

Well-known member
Joined
Oct 27, 2005
Messages
163
Programming Experience
1-3
[solved]hide or close?

when i finish editing in a frm at runtime, i want it disappear, e.g. when i finish adding a new customer, i want customer form disppear, which doesnt effect any other forms. Should i call "me.hide" or "me.close"? whats the difference? if i use "me.hide", next time when i open this form, the procedures under form_onLoad event will still function? what about "me.close"?
 
Last edited:
Hide just makes the form not visible. The form still exists and can do processing if required, plus it can be made visible again. Use Hide if you need to display the same instance of the form again later, like if it contains certain data that needs to be redisplayed.

Close destroys the form so it is, for all intents and purposes, inaccessible through code. Use Close if you don't intend to show the form again, or you don't need to keep the data it contains so creating a new instance is not an issue.
 
If you put "Private oCP As New Rs232()" at the top of the Form and then you repeatly call the Form using CLOSE then it will it will show the first time but the second, third, and so on, it will trip a exception error. So you will need to use "HIDE". Now if you put "Dim oCP As New Rs232()" as part of the SUB that opens the FORM then you can use CLOSE and all will be OK. Example:

"Private oCP As New Rs232()"


Private Sub CallRS232()

Show.RS232()
End Sub

Private Sub RS232()
"Do Rs232 stuff"
Hide.RS232
End Sub

OR use

Private Sub Call232()
Dim oCP As New Rs232()

Show.RS232()
End Sub

Private Sub RS232()
"Do Rs232 stuff"
Close.RS232
End Sub
 
ssfftt said:
if i use "me.hide", next time when i open this form, the procedures under form_onLoad event will still function? what about "me.close"?
The Load event is raised once and once only for each form object. That means if you call Hide on a form, calling Show will NOT raise the Load event again.
 
thx for all ur replies, very very helpful. I think i will try me.close for now, if any further problem happened, i will try something else, thx!
 
Another way to look at this is if you do

Private Sub Form_Load()
Dim fOForm as New Form()
End Sub

Private Sub Button1_Click(....)
fOForm.Hide.Form2
End Sub

or

Private Sub Button1_Click(....)
Dim fOForm as New Form()

fOForm.Close.Form2
End Sub

In the first part the Form object get initialized only once
In the second part the Form object get initialized each time the
button is clicked.
in the first part if you use CLOSE instead of HIDE, it will work the
first time, but after that it will fail and cause a exception.
 
Kulrom, i already accepted the answers and edited my first post yesterday, thx for help. I noticed that when i execute frm.close and try to open it again (frm.show) from button click on another form, it gives error. but i think i will be get around with it. cheers!
 
You "noticed" that when you Close a form you get an error if you try to Show it again? I already said that calling Close destroys the form in the very first reply. You can't display an object that's been destroyed. You need to create a new instance, i.e. a new form object, if you want to display another form.
 
so i have to dim the same frm every time when i want to use it again after i clicked on the red-cross on the top-right?
 
ssfftt......

Look at my second post. It should explain it. Basicly if you declare the
Form Object at the top of your program, then you will need to use

SHOW/HIDE

Private Sub Form_Load()
Dim fOForm as New Form()
End Sub

Private Sub Button1_Click(....)
fOForm.Show.Form2
'do Form2 stuff
'Close Form2 using HIDE
fOForm.Hide.Form2
End Sub


If you declare the Form Object from within the Button_Click sub routine

then you use

SHOW/CLOSE.

Private Sub Button1_Click(....)
Dim fOForm as New Form()

fOForm.Show.Form2
' Do Form2 stuff
' Close Form2 using CLose
fOForm.Close.Form2
End Sub
 
i declare forms within a module, so that wherever i want to use a form, i dont need to dim again, just use: "module1.form1.show" , i will try your suggestion johnadonaldson, thx
 
btw, in my module, i have:
VB.NET:
Expand Collapse Copy
    Public frmLogin As New frmLogin    Public frmPWReminder As New frmPWReminder    Public frmTestList As New frmTestList    Public frmCategoryMgt As New frmCategoryMgt    Public frmUserRegistration As New frmUserRegistration
do they look ok?
 
Public frmLogin As New frmLogin
Public frmPWReminder As New frmPWReminder

This is fine if you are declaring them outside of the Button_Click routine.
You will need to use the HIDE statement to be able to redisplay the form.

If you put them inside of the Button_Click routine you need to change them
to read

Dim frmLogin As New frmLogin
Dim frmPWReminder As New frmPWReminder

Then you can use the CLOSE statement. Each time you click on the button
it will reinitialize the Object and you can then use SHOW and CLOSE.
 
Back
Top