472,989 Members | 2,843 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,989 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 2818
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() {} }
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

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.