473,386 Members | 1,766 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,386 software developers and data experts.

How can access variable from different class?

Below; I have 2 classes (forms), Namely, "PrintOneEmployee" and "DeleteOne". In class "PrintOneEmployee";
I want to declare a variable with name of "fileName" to contain the name of the file "Main\\_1Main.txt".
Later on, when I wanted to access the variable "fileName" in the other class, namely, "DeleteOne". The
compiler show an error that the variable is undeclared. What should I do to access the variable "fileName"
in the the other class "DeleteOne"? I am aware of the scope of the variable inside the brackets,
but I am confused about the scope of the different classes.

/************************************************** ********/
Expand|Select|Wrap|Line Numbers
  1. #pragma once
  2. #using <System.dll> 
  3. #using <System.Windows.Forms.dll>  
  4. #using <System.Drawing.dll>  
  5.  
  6. #include "DeleteOne.h"
  7.  
  8. #include "Time.h"
  9. #using <mscorlib.dll>
  10.  
  11. using namespace System;
  12. using namespace System::IO;
  13. using namespace System::ComponentModel;
  14. using namespace System::Collections;
  15. using namespace System::Windows::Forms;
  16. using namespace System::Data;
  17. using namespace System::Drawing;
  18. using namespace System::Drawing::Printing;  
  19.  
  20. namespace TimeTracking 
  21. {
  22.  
  23.  public ref class PrintOneEmployee : public System::Windows::Forms::Form
  24.  {
  25.  
  26.  
  27.  
  28.     private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) 
  29.     {   
  30.  
  31.     { 
  32.     streamToPrint = gcnew StreamReader(  "Main\\_1Main.txt" );
  33.  
  34.     String^ fileName = "Main\\_1Main.txt"String^ fileName;
  35.     } 
  36.  
  37.  
  38.     }
  39.  
  40.  
  41.  };
  42. }
  43.  
  44.  
/************************************************** *******************/

Expand|Select|Wrap|Line Numbers
  1. #pragma once
  2.  
  3. #include "Time.h"
  4. //#include "PrintOneEmployee.h"
  5. #using <mscorlib.dll>
  6.  
  7. using namespace System;
  8. using namespace System::IO;
  9. using namespace System::ComponentModel;
  10. using namespace System::Collections;
  11. using namespace System::Windows::Forms;
  12. using namespace System::Data;
  13. using namespace System::Drawing;
  14.  
  15. namespace TimeTracking 
  16. {
  17.  
  18.  public ref class DeleteOne : public System::Windows::Forms::Form
  19.  {
  20.  
  21.  
  22.    private: System::Void OkBotton_Click(System::Object^  sender, System::EventArgs^  e) 
  23.     {
  24.  
  25.      FileInfo^ fi = gcnew FileInfo(FileName);
  26.      fi->Delete();
  27.  
  28.     }
  29.  
  30.  };
  31. }
  32.  
  33.  






--
Thanks
Allen
Oct 16 '09 #1
1 2840
newb16
687 512MB
1) They are not the same name, it's case-sensitive
2) if there are more than one instance of PrintOneEmployee, how will DeleteOne know which to use?
Then you can write some public getter to access class member.
Oct 16 '09 #2

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

Similar topics

9
by: Banaticus Bart | last post by:
I wrote an abstract base class from which I've derived a few other classes. I'd like to create a base class array where each element is an instance of a derived object. I can create a base class...
166
by: Graham | last post by:
This has to do with class variables and instances variables. Given the following: <code> class _class: var = 0 #rest of the class
7
by: James Fortune | last post by:
In response to different users or situations (data context) I transform the appearance and characteristics of Access Forms through code. This seems to fit in with the idea of polymorphism. Do...
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
7
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
6
by: Christian H | last post by:
Hi! I've created a custom control (myDrawControl) that deals with drawing. This control is then added to a form( myMainForm) Now, whenever something is dragged and dropped onto myDrawControl ,...
4
by: lars.uffmann | last post by:
Hey everyone! I am (still) working on a project that I took over from former students, so don't blame me for the criminal approach on coding *g* The problem I have is fairly easy and while I...
4
by: RedHair | last post by:
I have a base page class A which inherits System.Web.UI.Page class then a aspx page B inherits class A and have a master page C. There is a property D (a string variable) in the master page C. ...
9
by: LamSoft | last post by:
Class B { public B() {} } Class A : B { public static string ABC = "myABC"; public A() {} }
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...

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.