473,474 Members | 1,571 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Form Exit

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
10 2239
Hi,

Try "Me.Close()"...

Regards,

Cerebrus.

Mar 28 '06 #2
"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
"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
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
"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
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
"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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Gregory A Greenman | last post by:
I'm trying to write a program in vb.net to automate filling out a series of forms on a website. There are three forms I need to fill out in sequence. The first one is urlencoded. My program is...
14
by: Abhi | last post by:
FYI: This message is for the benefit of MS Access Community. I found that this prblem has been encounterd by many but there is hardly any place where a complete solution is posted. So I thought...
8
by: Zlatko Matić | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the...
11
by: Jozef | last post by:
I have some old code that I use from the Access 95 Developers handbook. The code works very well, with the exception that it doesn't seem to recognize wide screens, and sizes tab controls so that...
5
by: RAJ | last post by:
hi plz tell me how to know "how window is going to close"... i have to right code for X button of forms... plz telll me thanks bye
1
by: dBNovice | last post by:
Please help! I have 3 forms: Task, Subtask, Elements. Elements is a subform of Subtask and Subtask is a subform of Task. I am able to navigate from Task to Subform to Element and from Element to...
6
by: San | last post by:
Hey, I need to create a form with several text boxes in which users type in key words, press a command button on the form and it opens a matching record. Thanking you in advance.
3
mikeinspain
by: mikeinspain | last post by:
hi there.. I have a php form script that is pretty much there... I am however having a problem when I go to test the form. the mail comes through into my inbox displaying the information ok...
2
by: Matuag | last post by:
Hi All, I want to create following command buttons on a Form which users can edit. Save ( Save Changes made) Cancel ( Undo data changes) Exit ( Close form) I am using Macros for each of...
1
by: igor221189 | last post by:
Hello everyone. I have Access 2000 database which holds student records in the school.It stores subject grades for each student.In the 'Student Grade Form', I would like to search student surname...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.