Tony

Tony

  • NA
  • 30
  • 0

Trying to retrieve a variable from a program.

Dec 17 2009 1:13 PM
I have a form (form1.cs) that sends a transaction record variable (TranRec) to a program (Transporter.cs) by calling it using Transporter.ConnectToDMV(TranRec);.

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. Confused

Answers (7)