dudearcher

I am a noob, and I am having a problem with variables in my progect. When I import them to another namespace it throws and exception about endless loops. Please help!!



Re: Visual C# Language Variable import problems

Peter Ritchie

Could you post the code that is causing this exception






Re: Visual C# Language Variable import problems

dudearcher

In form 1 it is

private IsThisYou otherForm;
private void GetVariable()
{
preschoolName = otherForm.PreschoolName;
}

And on Form 2


public Form1 PreschoolName
{
get
{
return preschoolName;
}
}





Re: Visual C# Language Variable import problems

dudearcher

Sorry, preschoolName is the variable I want to import. IsThisYou is Form2.






Re: Visual C# Language Variable import problems

Peter Ritchie

Are you sure your PreschoolName property doesn't return PreschoolName and not preschoolName If that were capitalized it would end up calling itself infinitely.






Re: Visual C# Language Variable import problems

dudearcher

That helped, but now it says that ir can't convert preschoolName to a string. I am using the Get a value from another Form example in the MSDN library.





Re: Visual C# Language Variable import problems

Peter Ritchie

The property PreschoolName returns the type Form1, to assign that to a String variable you'd have to call its ToString method: String text = PreschoolName.ToString();






Re: Visual C# Language Variable import problems

dudearcher

How would that code look





Re: Visual C# Language Variable import problems

dudearcher

Thank You!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!





Re: Visual C# Language Variable import problems

dudearcher

That helped, but the it still throws the exception. the exception is StackOverflowEcxeption.





Re: Visual C# Language Variable import problems

Peter Ritchie

You'll have to post the actual code, for you to get that exception you must be calling the property indirectly from itself. The code you've posted so far does not have that problem.






Re: Visual C# Language Variable import problems

dudearcher

Here is the code: in IsThisYou

public Form1 PreschoolName
{
get
{
return PreschoolName;
}
}

And in Form1

private IsThisYou otherForm;
private void GetVariable()
{
preschoolName = otherForm.PreschoolName.ToString();
}

The first variable is used to store a name that is selected in a listbox that needs to be displayed in IsThisYou. The exception is thrown when I click on the name in the listbox.





Re: Visual C# Language Variable import problems

Peter Ritchie

dudearcher wrote:
public Form1 PreschoolName
{
get
{
return PreschoolName;
}
}


PreschoolName recursively calls itself until it runs out of stack space.




Re: Visual C# Language Variable import problems

Peter Ritchie

PreschoolName implies you're getting text, why would you return a Form1 type here






Re: Visual C# Language Variable import problems

dudearcher

So what should I do to fix it I am getting text, so what should I write instead of Form1