473,804 Members | 3,182 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem getting back Results from Classes in a different namespace.

31 New Member
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 1616
cloud255
427 Recognized Expert Contributor
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 Contributor
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
10084
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 class ) Here is how a given class wil looks like. <System.Xml.Serialization.XmlRootAttribute(:="mynamespace", IsNullable:=False)> _ Public Class ClassName
1
4365
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 done this before but this time I have no idea why I am getting the error. Any ideas ?? THANKS ! <qcsttatus> <manual sourcerootfolder="" manualname="">
14
1991
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
1953
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 languages to my ASP.NET project. I have read the docs in MSDN and several sites and newsgrops but still can't get this working as advertized. I have created string resources in both a .txt and a .resx
13
1739
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 question I have is how best pass the search criteria from the first page to the second. The search criteria exists as a structure and is filled when the user presses the 'Search' button on the first page.
8
4207
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, here's the code: ====================================== Dim textConverter As New ASCIIEncoding Dim sParam As String = "This is my cool param" Dim bytParam() As Byte 'load the byte array here...
7
4717
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. ========================================== using System; using System.Collections.Generic; using System.ComponentModel; using System.Data;
5
1450
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 create a reference to TestClass2 in TestClass1; but the compiler doesn't seem to recognize the namespace Test and any classes in it. Here are my class definitions and declarations:
9
5763
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 call it Express for simplicity). I have, to try to simplify things, put the exact same DB on two systems, one running MSDE and one running Express. Both have 2 Ghz processors (one Intel, one AMD), both have a decent amount of RAM (Intel system...
0
9706
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9577
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10325
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10315
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9140
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7615
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5519
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2990
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.