loop error
-
Hi.
bool FrmIsOpen = false; for (int i=0; i < **this.MdiParent.MdiChildren.Length**; i++) { if (this.MdiParent.MdiChildren[i].GetType() == typeof(FrmPassword)) { FrmIsOpen = true; break; } } if (!FrmIsOpen) { FrmPassword r = new FrmPassword(); r.MdiParent = this; r.Show(); }
An unhandled exception of type 'System.NullReferenceException' occurred in CLINICINFORMATIONSYSTEM.exe Additional information: Object reference not set to an instance of an object. the error's pointing to the line that has been bold...i dont understand what is it trying to say?.... CODER -
Hi.
bool FrmIsOpen = false; for (int i=0; i < **this.MdiParent.MdiChildren.Length**; i++) { if (this.MdiParent.MdiChildren[i].GetType() == typeof(FrmPassword)) { FrmIsOpen = true; break; } } if (!FrmIsOpen) { FrmPassword r = new FrmPassword(); r.MdiParent = this; r.Show(); }
An unhandled exception of type 'System.NullReferenceException' occurred in CLINICINFORMATIONSYSTEM.exe Additional information: Object reference not set to an instance of an object. the error's pointing to the line that has been bold...i dont understand what is it trying to say?.... CODERIt's trying to tell you that something is null; this.MdiParent or MdiParent.MdiChildren is null. Check for that condition before entering the loop. --------------------------- He who knows that enough is enough will always have enough. -Lao Tsu
-
It's trying to tell you that something is null; this.MdiParent or MdiParent.MdiChildren is null. Check for that condition before entering the loop. --------------------------- He who knows that enough is enough will always have enough. -Lao Tsu
-
Hi, Im sorry Judah, im a beginner...i would appreciate it if you could show me how i can do that. thx in advance CODER
bool FrmIsOpen = false;
if(this.MdiParent != null && this.MdiParent.MdiChildren != null)
{
for (int i=0; i < this.MdiParent.MdiChildren.Length; i++)
{
if (this.MdiParent.MdiChildren[i].GetType() == typeof(FrmPassword))
{
FrmIsOpen = true;
break;
}
}
}if (!FrmIsOpen)
{
FrmPassword r = new FrmPassword();
r.MdiParent = this;
r.Show();
}--------------------------- He who knows that enough is enough will always have enough. -Lao Tsu
-
Hi.
bool FrmIsOpen = false; for (int i=0; i < **this.MdiParent.MdiChildren.Length**; i++) { if (this.MdiParent.MdiChildren[i].GetType() == typeof(FrmPassword)) { FrmIsOpen = true; break; } } if (!FrmIsOpen) { FrmPassword r = new FrmPassword(); r.MdiParent = this; r.Show(); }
An unhandled exception of type 'System.NullReferenceException' occurred in CLINICINFORMATIONSYSTEM.exe Additional information: Object reference not set to an instance of an object. the error's pointing to the line that has been bold...i dont understand what is it trying to say?.... CODERMy first question would be where is this code sitting? Is it in a child form or an MDIParent? It looks like a parent form has this code, in which case the parent form has no MDIParent. This reference would be null, and therefor, your reference to 'this.MdiParent.MdiChildren.Length' would return null. If this code is in a parent form, then your reference should be this.MdiChildren.Length. RageInTheMachine9532
-
My first question would be where is this code sitting? Is it in a child form or an MDIParent? It looks like a parent form has this code, in which case the parent form has no MDIParent. This reference would be null, and therefor, your reference to 'this.MdiParent.MdiChildren.Length' would return null. If this code is in a parent form, then your reference should be this.MdiChildren.Length. RageInTheMachine9532
its in a parent form. i tried editing the code your way..but it is still able to open up two same forms...
bool FrmIsOpen = false; if(this.MdiParent != null && this.MdiChildren != null) { for (int i=0; i < this.MdiChildren.Length; i++) { if (this.MdiParent.MdiChildren[i].GetType() == typeof(FrmPassword)) { FrmIsOpen = true; break; } } } if (!FrmIsOpen) { FrmPassword r = new FrmPassword(); r.MdiParent = this; r.Show(); }
CODER -
its in a parent form. i tried editing the code your way..but it is still able to open up two same forms...
bool FrmIsOpen = false; if(this.MdiParent != null && this.MdiChildren != null) { for (int i=0; i < this.MdiChildren.Length; i++) { if (this.MdiParent.MdiChildren[i].GetType() == typeof(FrmPassword)) { FrmIsOpen = true; break; } } } if (!FrmIsOpen) { FrmPassword r = new FrmPassword(); r.MdiParent = this; r.Show(); }
CODEROK. The loop now runs but your references in your if statement are still screwed up. Use this instead:
bool FrmIsOpen = false;
if (this.MdiChildren.Length > 0)
for (int i=0; i < this.MdiChildren.Length; i++)
{
if (this.MdiChildren[i].GetType() == GetType(FrmPassword))
{
FrmIsOpen = true;
break;
}
}
}
if (!FrmIsOpen)
{
FrmPassword r = new FrmPassword();
r.MdiParent = this;
r.Show();
}The first bolded statement was changed because 'this.MDIParent' will always return null if 'this' is an MDIParent. This was changed to checking if the MDIChildren collection has anything in it. In the second bolded statement, the 'typeof()' reference was changed to 'GetType()'. If you have to, you could change this to 'Type.GetType()'. This should take care of your problem. RageInTheMachine9532