?
Solved

How do I fill a text box with another class value

Posted on 2011-04-22
2
Medium Priority
?
478 Views
Last Modified: 2013-12-16
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

0
Comment
Question by:luciepaul
2 Comments
 
LVL 45

Accepted Solution

by:
AndyAinscow earned 2000 total points
ID: 35446613
You haven't assigned a value to the string SN, hence it uses the (default) value of "".  So everything is working correctly.
0
 

Author Comment

by:luciepaul
ID: 35446706
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#
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question