Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

instance of form does not pass values to another form 1

Status
Not open for further replies.

nishasp

Programmer
May 13, 2004
33
0
0
GB
I have created on instance of form2 in form1 and need to pass a string value across. However my object does not hold any values of the variables from form2 and shows these as being 0. I have declared the instance of form2 within the Members region of my code and assigned a string to the object that i wish to access. This returns a null value for the string. I am sure that its something silly that i have missed out...please help!!

Thanks in advance...
 
is this how you store the values?
Code:
public string resultString
{
	get
	{
		return JIGString[JIGString.Count-1].ToString();
	}
	set
	{
		JIGString.Add(value);
	}
}

because I've just tried it and it works perfectly...
 
Yes!

In form2 i have set
parentForm.resultString = StartRemoteTest.ToString();

I remove this value from the arraylist once i have used it in form1, so the count will only ever be say 30 and 31.
 
then the problem is when you remove the used value. provide the code you use there because the wrong value gets removed probably.
 
private void WaitTimer_Tick(object sender,System.EventArgs
e)
{
if((this.Port.IsOpen) && (iJIGMsgString <32))
{
//SendStr("a10e<2");
if(JIGString.Count == 31)
{
SendStr(JIGString[iJIGMsgString].ToString());

iJIGMsgString++;
if(iJIGMsgString >=31) //keeps on polling
{
JIGString.RemoveAt(30);
iJIGMsgString = 0;
}
}
else
{
SendStr(JIGString[iJIGMsgString].ToString());
iJIGMsgString++;
if(iJIGMsgString >=30) //keeps on polling
{
iJIGMsgString = 0;
}
}
}
}
 
you always remove the last value therefore, in your scenario, you add a value from the 1st instance of Form2 (let's call it Form2_1) at position (let's say) 29. you don't delete anything yet because count is not greater than or equal to 30. Then when you add a value from the second form (Form2_2), it gets added at position 30 so the count becomes 31. Then you delete the value at position 30 so what you actually do, is remove the value from Form2_2 and have the value from Form2_1 as last value in your array.

You should try to remove values form the start of the array and keep adding at the end of it (like in a FIFO queue)
 
It's really weird, but i restarted the computer and now the messages seem to be going through fine!

So, thanks for that anyway!
 
And another question again...

I have the button control array that opens up different instances of form2. The problem is that if i click on a button more than once, it will keep opening up that same form. I need to click on a button, open up its associated form and only when it is closed can it be open again. How would i do that?

Secondly, i now need to pass values from form1 to a particular instance of form2, depending on which form number test box responds to a polling message. I set up a property on form2 to print the value and passed it across, and it shows up, but on a new instance of form2 and not the form associated with the button tag. Does this make any sense??

Please help me!!!
 
nihasp -
Use the "new" operator to get a new instance of your form.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
I don't want a new instance of the form as this then doesn't have the associated tag value that indexes the buttons. I have tried to create a new instance of form2 in form1, but then i am unable to get multiple instances of the same form...
 
Can't have one without the other, sorry.

If you want a new instance, you'll have to provide a way to set the tag values.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top