-
Module problem
Hi,
In my application I have:
1 MDI (MDIParent1)
2 Forms (frm1 and frm2)
1 Module (module1)
In MDIParent1 I have the foolowing code:
Sub New()
InitializeComponent()
Dim f1 As New frm1: f1.MdiParent = Me : f1.Close()
Dim f2 As New frm2: f2.MdiParent = Me : f2.Close()
end sub
I would like to init module1 too like I done for frm1 and frm2 because when
I am calling a function that is in the module I get an error:
"The type initializer for 'ApplicationName.Module1' threw an exception."
In addition (in the add watch during debug):
"reference to a non-shared member requires an object"
Please help
Eric H.
-
Re: Module problem
Could you show what line of code that caused that error?
-
Re: Module problem
does your code error in the InitializeComponent sub? If so can you post the code for this? and where it dies?
After setting the parent, why do you close the forms?
-
Re: Module problem
Hello,
Thanks for your replies.
I do not have any InitializeComponents function, It is the default one.
The problem is that I am calling to a function that is in the module1 and in this function I am using an ADODB Connection object that is declared in this module.
If I am declaring the ADODB connection to the MDIParent1 and I am writing the function into the MDIParent1, no problem occurred.
SO I presume that the problem is that the I have to init the module1 in the Sub New of the MDIParent1 as I done for frm1 and frm2.
I hope you understand because english is not my mother tongue and VB.NET is new for me.
Thanks
-
Re: Module problem
a module doesn't need to be initialize. It only contains function that are common to different class in your project.
I assume that your connection is to be used every where in your program, instead of defining in form 1, you can as well do all your database interaction in the module and just return the result to the forms.
-
2 Attachment(s)
Re: Module problem
Hi,
I don't know how to explain you my problem, it is little complicated.
I tried to simplify my app and explain you the problem but with no success.
Let's try in another way.
I attaching my app simplified.
Please see attachment of a part of my application.
1) Please insert your db connection in ConnectToDb function in module1
2) run the program
3) Please click on new button from the mdi form.
4) you will get an error in CheckIfOpen function in module1.
Thanks much for your help