473,394 Members | 1,806 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Problem getting back Results from Classes in a different namespace.

Hello guys, I got this problem.

I have a Window Form project within on it I have 2 Buttons and 1 Label

btSet (button)
btGet (button)
lbResult (label)

When I click on btSet I save the value in other class in a different namespace.
Expand|Select|Wrap|Line Numbers
  1. private void btSet_Click(object sender, EventArgs e)
  2.         {
  3.             RailLib.Alarm aux = new RailLib.Alarm();
  4.             aux.AlarmResetMask = 5;
  5.         }
  6.  
Expand|Select|Wrap|Line Numbers
  1. namespace RailLib
  2. {
  3.     public class Alarm
  4.     {
  5.         public int AlarmResetMask;        
  6.     }
  7. }
  8.  
The problem is that when I want to get back the value with the get button, the class is empty.. what I can do to dont lose the saved values:

Expand|Select|Wrap|Line Numbers
  1. private void btTry_Click(object sender, EventArgs e)
  2.         {
  3.             RailLib.Alarm aux = new RailLib.Alarm();
  4.             lbResult.Text = aux.AlarmResetMask.ToString();
  5.             Refresh();
  6.         }
  7.  
The return value in the label field its 0. And I really saved a lot of values within the RailLib namespace and when I want to get them back with other button, it seems to be that they are not there anymore.

Preveously I had to move all my classes to RailLib because if I leave them in the same namespace as the form class is I got this error:

The class Form1 can be designed, but is not the first class in the file. Visual Studio requires that designers use the first class in the file. Move the class code so that it is the first class in the file and try loading the designer again.

What do you think?
May 11 '09 #1
2 1601
cloud255
427 Expert 256MB
Hi

When you try to access the class to read the data you say:

Expand|Select|Wrap|Line Numbers
  1.  RailLib.Alarm aux = new RailLib.Alarm();
This means that you now have a NEW instance, so it doesn't contain any data...
The other problem is that the first instance you declared is now out of scope so you will not be able to access it.

The variable only lives as long as the scope you declared it in.

You could use one global instance of the object declared within the form class,
You could create a static class,
You could save the data in a database/file for later use.
May 11 '09 #2
Bassem
344 100+
Or you could make a singleton just like a static class but using a static field instead to avoid the static class restrictions.
Sure the easiest is a global instance.
May 11 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Alexis | last post by:
Hello, I have a set of classes I created from schema files using the xsd.exe tool. I'm using namespaces in the clases ( I had to because I have some classes with the same name but not the same...
1
by: andrewcw | last post by:
There is an error in XML document (1, 2). I used XML spy to create the XML and XSD. When I asked to have the XML validated it said it was OK. I used the .net SDK to generate the class. I have...
14
by: Lee Franke | last post by:
I can't seem to figure this one out. Here is my class structure namespace name { public class foo { } }
2
by: Rob Garfoot | last post by:
I'm hoping someone here can help with this one as I've been looking all around for a solution to this and I've yet to find one that is satisfactory. I'm trying to add support for different...
13
by: Simon Matthews | last post by:
I am having issues with the right way to architecture the following (using c# asp.net):- The question I have is how best pass the collected data from one web page for use in another. The...
8
by: moondaddy | last post by:
I need to convert a byte array to a string and pass it as a parameter in a URL and then convert it back to the original byte array. However, its getting scrambled in the conversion. In short,...
7
by: garyusenet | last post by:
This is the first time i've worked with openfile dialog. I'm getting a couple of errors with my very basic code. Can someone point out the errors in what i've done please....
5
by: michael.d.pedersen | last post by:
Hello group, I am new to Visual C++ 8 and have a seemingly trivial problem using namespaces. The scenario: I have two classes, TestClass1 and TestClass2, in the namespace Test. I would like to...
9
by: HC | last post by:
Hello, all, I started out thinking my problems were elsewhere but as I have worked through this I have isolated my problem, currently, as a difference between MSDE and SQL Express 2005 (I'll just...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.