• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 484
  • Last Modified:

How do I fill a text box with another class value

I'm a beginner in C#
I declare a structure in a class named OakSensor.cs

public struct tOakSensor
        [MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 24)]
        public string SN;
I try to use the SN value in another class named form3.cs

private void CmdLancer_Click(object sender, EventArgs e)
            tOakSensor sensorxx = new tOakSensor();
            textBox1.Text = (sensorxx.SN);

There is no error message but the textbox remains empty.
Within the OakSensor.cs the line :
        Console.WriteLine("SN:{3}", Sensor.SN);
returns the correct value

1 Solution
AndyAinscowFreelance programmer / ConsultantCommented:
You haven't assigned a value to the string SN, hence it uses the (default) value of "".  So everything is working correctly.
luciepaulAuthor Commented:
Actually the line "Console.WriteLine("SN:{3}", Sensor.SN); works well when embedded in  a method:
 public static void Oak_PrintSensorInfo(ref tOakSensor Sensor)
          Console.WriteLine("SN:{3}", Sensor.SN);

I guess the method gives a value to" sensor" and consequently to SN

How can I reproduce that in the form3 class ( ie finding the sensor serial number Sensor.SN) ?

Thanks for helping a real beginner in C#
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now