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.