Transporter.cs does what it needs to do and returns to form1.cs for the user to enter and submit another transaction. Here's part of the Transporter.cs code.
Transporter.cs
public partial class Transporter
{
public static void ConnectToDMV(string TranRec)
{ rest of code processing TranRec ...
What I also need Transporter.cs to do is return a variable (logLU) back to form1.cs. For this I am using the following code;
Transporter.cs
Form1 aForm = new Form1();
aForm.SetValue(logLU);
form1.cs
public void SetValue(string luValue)
{
logLU = luValue;
// for testing purposes
MessageBox.Show("Here's the value of (form1)luValue: " + luValue);
MessageBox.Show("Here's the value of (form1)logLU: " + logLU);
}
I can see both variables in the messageboxes so I know logLU gets to form1.cs but then it returns to null when I need it in other parts of form1.cs. What am I missing??? Similar code works in other parts of my program but not here. BTW, I'm a newbie to C# and this is my first application.
Any advise will be very much apprecaited.

theLizardPosted Dec 17, 2009, 3:26 PM
What you need is a static class with static variables.
public static class myVars
{
private static int logLU =0;
private static int luValue=0;
public static int LogLU
{
get{reurm(logLU);}
set{logLU=value;}
}
public static int LuValue
{
get{return(luValue);}
set{luValue=value;}
}
}
myVars v = new myVars();
Form1 aForm = new Form1();
v.LogLU = a value;
aForm.SetValue(v);
public void ShowValue(myVars v) //you don't need to set the values on the other form although it is a simple matter to do so
{
//v values are set in form 1 OR
// you could do this v.LuValue = a new value, because v is sent as a reference and the vars are static returning to form 1 will show the same values as you set here.
// for testing purposes
MessageBox.Show("Here's the value of (form1)luValue: " + v.LuValue);
MessageBox.Show("Here's the value of (form1)logLU: " + v.LogLU);
}
of course you could also declare the variables as public members of form1 and do something like this
MessageBox.Show("Here's the value of (form1)luValue: " + Form1.LuValue);
Aliens!!!!! back to earth people...
Kirtan PatelPosted Dec 17, 2009, 3:51 PM
Happy coding :)
TonyPosted Dec 17, 2009, 3:38 PM
I fixed the problem by doing the following in form1.cs
namespace DMV_Access_App
{
public partial class Form1 : Form
{
public static string logLU;
public Form1()
{ Rest of form1.cs code ...
This took care of the problem. Seems so simple. Of course, being a newbie, I am not sure what ramifications there are but it does work. This is great forum!
TonyPosted Dec 17, 2009, 2:57 PM
Kirtan PatelPosted Dec 17, 2009, 2:15 PM
its some minor mistake somewhere .i have to look at whole to find it where.
can you provide the whole class code you are using ??? if possible in mail ??
my mail address is [email protected]
TonyPosted Dec 17, 2009, 2:09 PM
I've looked through my code and here's what I do to set up logLU
Transporter.cs - (64, 24) : string logLU = m_terminal.Screen.GetText(18, 18, 10);
Form1.cs - (53, 23) : public string logLU = null to initialize logLU
I don't think this is causing the problem.
Kirtan PatelPosted Dec 17, 2009, 1:19 PM
public void SetValue(string luValue)
{
logLU = luValue;
// for testing purposes
MessageBox.Show("Here's the value of (form1)luValue: " + luValue);
MessageBox.Show("Here's the value of (form1)logLU: " + logLU);
}
if logLU is defined as Global Variable then check again if value of logLU is changing some where else in other methods / events ???
it it does not solve it then if still need help then let me know i will help you :)