Results 1 to 6 of 6

Thread: Module problem

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2007
    Posts
    12

    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.

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Module problem

    Could you show what line of code that caused that error?
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    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?

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2007
    Posts
    12

    Smile 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

  5. #5
    Fanatic Member
    Join Date
    Feb 2007
    Location
    Eindhoven
    Posts
    828

    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.

  6. #6

    Thread Starter
    New Member
    Join Date
    Mar 2007
    Posts
    12

    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
    Attached Images Attached Images  
    Attached Files Attached Files
    Last edited by ayeleteric; Jun 11th, 2007 at 08:38 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width