Home All Groups Group Topic Archive Search About
Author
28 Mar 2006 5:11 PM
Ronin
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

Author
28 Mar 2006 5:25 PM
Cerebrus
Hi,

Try "Me.Close()"...

Regards,

Cerebrus.
Author
28 Mar 2006 6:04 PM
Herfried K. Wagner [MVP]
"Cerebrus" <zorg***@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/>
Author
28 Mar 2006 6:03 PM
Herfried K. Wagner [MVP]
"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/>
Author
28 Mar 2006 6:29 PM
Ronin
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 Steve.M.Gave***@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
Show quoteHide quote
"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/>
>
>
Author
28 Mar 2006 7:09 PM
Herfried K. Wagner [MVP]
Show quote Hide quote
"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 Steve.M.Gave***@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/>
Author
28 Mar 2006 8:27 PM
Ronin
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?


Show quoteHide quote
"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 Steve.M.Gave***@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/>
>
>
Author
28 Mar 2006 8:58 PM
Herfried K. Wagner [MVP]
"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/>
Author
29 Mar 2006 6:25 AM
Cerebrus
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.
Author
29 Mar 2006 2:21 PM
Ronin
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.GetCurrent.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

Show quoteHide quote
"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.
>
>
Author
29 Mar 2006 8:50 PM
Cerebrus
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.GetCurrent.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.