problems with referring to class variables

Reply

Join Date: Nov 2004
Posts: 15
Reputation: matt_5104 is an unknown quantity at this point 
Solved Threads: 0
matt_5104 matt_5104 is offline Offline
Newbie Poster

problems with referring to class variables

 
0
  #1
Nov 14th, 2004
I'm having a problem with a GUI i'm building. I have a separate class called Calculations.class which does nothing except hold certain variables and do calculations with them. One of my classes requires a user to enter numerical data, and when a button is pressed, these variables are set in calculations.class, which is fine. However, when I try to access these variables in Calculations.class from another class, it seems like all the variables are set back to zero, and do not have the values set by the user originally. Any help would be fantastic!!
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,603
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 713
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: problems with referring to class variables

 
0
  #2
Nov 14th, 2004
It sounds like a scope issue where the Calculations object whose values you're setting is being destroyed and then recreated. When you access the values, they're fresh from the constructor.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 84
Reputation: jerbo is an unknown quantity at this point 
Solved Threads: 1
jerbo jerbo is offline Offline
Junior Poster in Training

Re: problems with referring to class variables

 
0
  #3
Nov 14th, 2004
Hummm, you want an answer without posting any code? Like fixing your car when you left it at home.......
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 1
Reputation: tozaheer is an unknown quantity at this point 
Solved Threads: 0
tozaheer tozaheer is offline Offline
Newbie Poster

Re: problems with referring to class variables

 
0
  #4
Nov 17th, 2004
Your Problem is Scope of variables. Please use static variable which are class variables and retain there values. If U want to use instance variables then U should be careful about the Object which get created when user clicks the button. U can not refer the same object in different file. At that time it creates new instance of that class and hence valued U get will be default. If U want to use in different Independent class then U have to pass these variables to new class thorogh constructor.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC