By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,219 Members | 2,140 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,219 IT Pros & Developers. It's quick & easy.

Form Exit

P: n/a
Group,

i hope someone is able to help with this issue.

I'd like the form to exit after certain logic calculation... i tried the
me.dispose with in the Sub New() procedure, but it does not exit.

i passed the boolean true parameter to the Protected Overloads Overrides Sub
Dispose(ByVal disposing As Boolean), it does not do anything... i've included
a finalize procedure with no codes but still no go.

Please help.
Thanks in advance.
Ronin
Mar 28 '06 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Hi,

Try "Me.Close()"...

Regards,

Cerebrus.

Mar 28 '06 #2

P: n/a
"Ronin" <Ro***@discussions.microsoft.com> schrieb:
I'd like the form to exit after certain logic calculation... i tried the
me.dispose with in the Sub New() procedure, but it does not exit.


What do you mean with exit? To prevent the form from being initialized,
simply throw an exception.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Mar 28 '06 #3

P: n/a
"Cerebrus" <zo*****@sify.com> schrieb:
Try "Me.Close()"...


This won't have any effect inside the form's constructor because the
construction of a form's instance doesn't make the form visible at all.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Mar 28 '06 #4

P: n/a
Where would i put it? with in the Sub New()?
i had a try catch block with in the Sub New():
If intC > 0 Then
MsgBox("A survey was already taken with your information. If
you feel this is an error, please e-mail St*************@mail.sprint.com")
Try
Me.Dispose(True)
Catch ex As Exception
Me.Close()
End Try
End If

and it still loads the form.
Further suggestions?

Thanks in advance.
Ronin
"Herfried K. Wagner [MVP]" wrote:
"Ronin" <Ro***@discussions.microsoft.com> schrieb:
I'd like the form to exit after certain logic calculation... i tried the
me.dispose with in the Sub New() procedure, but it does not exit.


What do you mean with exit? To prevent the form from being initialized,
simply throw an exception.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Mar 28 '06 #5

P: n/a
"Ronin" <Ro***@discussions.microsoft.com> schrieb:
Where would i put it? with in the Sub New()?
i had a try catch block with in the Sub New():
If intC > 0 Then
MsgBox("A survey was already taken with your information.
If
you feel this is an error, please e-mail St*************@mail.sprint.com")
Try
Me.Dispose(True)
Catch ex As Exception
Me.Close()
End Try
End If

and it still loads the form.


\\\
Public Class Form1
Public Sub New()
If...Then
Throw New Exception(...)
Else
...
End If
End Sub
...
End Class
....
Try
Dim f As New Form1()
Catch...
...
End Try
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Mar 28 '06 #6

P: n/a
Herfied,

The try/catch block statment seems to be out side the method body.
would i need to declare a separate class? if so, i'd like to be able to do
this without having to create a separate class in the form or class file.

Any help?
"Herfried K. Wagner [MVP]" wrote:
"Ronin" <Ro***@discussions.microsoft.com> schrieb:
Where would i put it? with in the Sub New()?
i had a try catch block with in the Sub New():
If intC > 0 Then
MsgBox("A survey was already taken with your information.
If
you feel this is an error, please e-mail St*************@mail.sprint.com")
Try
Me.Dispose(True)
Catch ex As Exception
Me.Close()
End Try
End If

and it still loads the form.


\\\
Public Class Form1
Public Sub New()
If...Then
Throw New Exception(...)
Else
...
End If
End Sub
...
End Class
....
Try
Dim f As New Form1()
Catch...
...
End Try
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Mar 28 '06 #7

P: n/a
"Ronin" <Ro***@discussions.microsoft.com> schrieb:
The try/catch block statment seems to be out side the method body.
would i need to declare a separate class? if so, i'd like to be able to do
this without having to create a separate class in the form or class file.


You will have to place it where you are attempting to instantiate the form.
'Me.Close' and 'Me.Dispose' are rather useless because at the beginning of
the constructor the form is neither visible nor completely constructed.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Mar 28 '06 #8

P: n/a
Hi Ronin,
The try/catch block statment seems to be out side the method body.
would i need to declare a separate class? if so, i'd like to be able to do
this without having to create a separate class in the form or class file.
I think someone would be able to help you better, if you gave some
details about How your form is launched ? From which form is it
launched ?

Without that information, I can just suggest that you should add the
code that Herfried suggested, at the place where you launch the form.
(which would have to be in another form class, wouldn't it)

Herfried wrote :
This won't have any effect inside the form's constructor because the
construction of a form's instance doesn't make the form visible at all.


Thanks for the correction, Herfried, I didn't realize that Ronin wanted
to close his form in the Sub New itself. I thought he was looking for
the best place to close the form.

Regards,

Cerebrus.

Mar 29 '06 #9

P: n/a
The project/solution startup object is the actual form itself... i have no
class to launch/initialize anything else. The objective is to just create an
executable form file. The code within the form will then be use to connect to
a DB with DSN-less connection (string).

the form sub new code is as follows:
Public Sub New()
MyBase.New()
InitializeComponent()
With db
.Prop_User =
System.Security.Principal.WindowsIdentity.GetCurre nt.Name
.cnn.Open()
.Prop_String = 1
.rst.Open(.Prop_String, .cnn)
intC = .rst.RecordCount
.Close_DB(.rst)
If intC > 0 Then
MsgBox("Test already taken")
MsgBox("Form will now exit.", MsgBoxStyle.Information +
MsgBoxStyle.OKOnly, "Exiting")
Me.Dispose(True)
Throw New Exception(MsgBox("Testing me",
MsgBoxStyle.OKOnly)) ' newly added code base on previous sugesstions
End If
End With
End Sub

But also tried adding the throw new exception within the Protected Overloads
Overrides Sub Dispose(ByVal disposing As Boolean) with the actual code
procedure below:

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
On Error GoTo ErrorHandler
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
ErrorHandler:
If Err.Number <> 0 Then
Throw New Exception("Testing me")
End If
End Sub

hope this helps. Please advice of further suggestions.

Thanks in advance.
Ronin

"Cerebrus" wrote:
Hi Ronin,
The try/catch block statment seems to be out side the method body.
would i need to declare a separate class? if so, i'd like to be able to do
this without having to create a separate class in the form or class file.
I think someone would be able to help you better, if you gave some
details about How your form is launched ? From which form is it
launched ?

Without that information, I can just suggest that you should add the
code that Herfried suggested, at the place where you launch the form.
(which would have to be in another form class, wouldn't it)

Herfried wrote :
This won't have any effect inside the form's constructor because the
construction of a form's instance doesn't make the form visible at all.


Thanks for the correction, Herfried, I didn't realize that Ronin wanted
to close his form in the Sub New itself. I thought he was looking for
the best place to close the form.

Regards,

Cerebrus.

Mar 29 '06 #10

P: n/a
Hi Ronin,

Now I never realized that you were using a single form application.
That makes it very different. Because when your Main (startup) form
closes, so does your application.

So, why don't you add all the code within the Load event instead of the
Sub New ? As in :

"Windows Form Designer generated code"

....

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

With db
.Prop_User =
System.Security.Principal.WindowsIdentity.GetCurre nt.Name
.cnn.Open()
.Prop_String = 1
.rst.Open(.Prop_String, .cnn)
intC = .rst.RecordCount
.Close_DB(.rst)
If intC > 0 Then
MsgBox("Test already taken")
MsgBox("Form will now exit.", MsgBoxStyle.Information +

MsgBoxStyle.OKOnly, "Exiting")
Me.Close()
End if

End Sub

This should work...

Regards,

Cerebrus.

Mar 29 '06 #11

This discussion thread is closed

Replies have been disabled for this discussion.