CLOSE() is not closing my form :------((

  • Thread starter Thread starter Zalek Bloom
  • Start date Start date
Z

Zalek Bloom

Up to today Close() always worked like a charm in my programs, but
something happened when I coded:

If w_password_created = True Then
If Text_password1 = w_password Then
MsgBox("equal")
Close()
Else
MsgBox("Invalid password, enter again")
Return
End If
End If

If Text_password1 <> Text_password2 Then
MsgBox("password 1 not = password 2, please correct")
Return
End If

What I am getting in my program that first I see MsgBox("equal")
display, next I see MsgBox("password 1 not = password 2, please
correct")

But I coded Close() after the first display - why Close() is not
working?

Thanks,

Zalek
 
It is really intriguing why the form is not closing. Are you sure that
you have not written anything in the Closing or Closed event-handlers
(or their overridden method couterparts) to cancel the closure?

You are lucky that are saved from a definite program-crash due to this.
The movement the Close method start working, your program would throw a
ObjectDisposedException on reach the second If statement. Add a "Exit
Sub" after the Close call to avoid the error.
 
warning : Close() is not equal Return; ...

so If you Close() method you must call Return just after it ...
 
Try Me.Close().

Didn't help.

I changed the code:

If w_password_created = True Then
If Text_password1 = w_password Then
MsgBox("equal")
Me.Close()
MsgBox("Now it closed")

I see MsgBox("equal") and after MsgBox("Now it closed"). Under the
box I see the original form.

There no events defined in this form.

Zalek
 
warning : Close() is not equal Return; ...

so If you Close() method you must call Return just after it ...

Thanks azerty,

Return solved this problem.

Zalek
 
Thanks azerty,

Return solved this problem.

Zalek

I want to add - Close() always worked in my programs because I usually
put CLOSE() at end of SUB. Now I will remember for the safty always to
add return.
Thanks again,

Zalek
 
In fact,event if you close() something, (form, stream, or other) >>> the
execution code path continue ...

Close() is not a key word of VB language, it is just a method of Form class

so, if Close() throw an exception, your code stop BUT if Close() don't throw
an exception, code continue ...

you an also write something like this (I don't know the syntax in VB, but I
am sure you can do same thing)

try
{
if (something)
{
...
...
return;
}
else
{
...
...
return;
}
}
finally
{
Close();
}
 
Back
Top