|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Form ExitGroup,
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 "Cerebrus" <zorg***@sify.com> schrieb: This won't have any effect inside the form's constructor because the > Try "Me.Close()"... 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/> "Ronin" <Ro***@discussions.microsoft.com> schrieb: What do you mean with exit? To prevent the form from being initialized, > 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. simply throw an exception. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> 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/> > >
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/> 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/> > > "Ronin" <Ro***@discussions.microsoft.com> schrieb: You will have to place it where you are attempting to instantiate the form. > 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. '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/> Hi Ronin,
>> The try/catch block statment seems to be out side the method body. I think someone would be able to help you better, if you gave some>> 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. 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 Thanks for the correction, Herfried, I didn't realize that Ronin wanted>> construction of a form's instance doesn't make the form visible at all. to close his form in the Sub New itself. I thought he was looking for the best place to close the form. Regards, Cerebrus. 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. > > 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.
VB.NET Threaded DLL
Update an Access DB using VB.Net Generic path description - please help Folder size in VB.NET? VB 2005 .net- Login control - how do I validate user no / password against SQL server multitier app IntelliSense Code Comments? set default printer Re: Replace problem Using VB 2005 assemblies with VB 2003 |
|||||||||||||||||||||||