Vb Window Form Error " The form referred to itself during construction ......."

MichMat
MichMat used Ask the Experts™
on
Hi,

After 7 weeks of work last night I must have done something to the program because no it throws up this error

The form referred to itself during construction from a default instance, which led to infinite recursion.  Within the Form's constructor refer to the form using 'Me.'
   at Project.My.MyProject.MyForms.Create__Instance__[T](T Instance) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 180
   at Project.My.MyProject.MyForms.get_FormDB()
   at Project.FormDB_Calls.CreateDBMeetingsDS() in D:\adress witheld.vb:line 285

what can I do about this I have no idea about the first thing what I could do.

Michal
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
hi

i think you must have decalre a new control in another form as a global object in this form, which referred to this form or another form.

Commented:
try and avoid calling the same form within its form load

eg

public class form1
private m_form as form1
privaye sub form1_load() handles form1.load
m_form = new form1

end sub
end class

Author

Commented:
Oh Boy ......

 I dont understand this at all, I call the form from a nother form using formname.show

That is where I get the error, the curious thing when I continue the form behaves and works exactly as before.

Using any of the error mesage above can I see where the error is originating ? If so how would I do that ?
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009

Commented:
Show us any code you have in the "startup forms":

(1) Constructors
(2) Load Event
(3) Shown Event

Commented:
let see code samples from the form startup

Author

Commented:
Im afaraid I dont understand what is the 'startup forms'

Commented:
the form load event of the errortic window
Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009
Commented:
"I call the form from a nother form using formname.show"

Yes...it's fine to refer to the default instance of a Form when in a DIFFERENT form.

But, let's say that you are IN Form1, then you can't use "Form1" but instead need to use "Me":

    Public Class Form1

        Public Sub Foo()
            Form1.xxx = yyy ' <-- do NOT do this!  can't use "Form1" from within Form1
            ' instead, do this:
            Me.xxx = yyy
        End Sub

    End Class

But it is ok to use "Form1" form a DIFFERENT Form.  =)

Author

Commented:
Hi in the form load event of the form I have this

        Call CreateDataBaseRacesGrid()
        Call CreateImportChanges()


both those subs are in a separate module , and every reference in them refres to the form as formname.control as if I use me.control its flaged as an error.

However the program is crashing when it tries to execute a call from a radio button change of state event which happens when loading. This same event dosent crash when executed once the form is loaded

I deleted the call from the radio button change of state event and the form dosent crash when loading , even when I placed the crashing call directly into the load form event.

However that code has been in the form for weeks just like it is now and it never crashed before.

I suppose I can do one of two things , either persue this further and figure out what it is or somehow prevent the form from executing the change of state event while loading

Author

Commented:
I was able to change the state of the radio button to false which stops the code excuting and the form crashing. The code works after the form is loaded, I suppose that is a solution but its kinda dirty dont you think ? I would really like to get to the bottom of the issue
Commented:
use a private variable to flag this event

so as the event does not do any this on load and when the form finish loading it set the flag to a state that the event call will work

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial