Click to See Complete Forum and Search --> : Displaying two types of units
Amy
May 4th, 1999, 12:33 PM
Hi,
I want to display the data in two type of units - North American and Brithsh standards. The unit type can be selected by the radio button. The structure that holds the data is in NorthbAmerican Standard units.
My trivia is how to display the two types of the units as the app has many edit boxes on different dialog boxes.
How should I approach this problem so that there is minimal duplication of the code??
Thanks.
Amy
Safai Ma
May 4th, 1999, 02:17 PM
One option is to make a class out of your structure and use functions to extract values instead of accessing them directly. Here is an example.
class someData
{
public:
someData(); // constructor
int Data1();
int Data2();
void UseBritishStandard() { m_bNorthAmerican = FALSE; };
void UseNorthAmerican() { m_bNorthAmerican = TRUE; };
private:
BOOL m_bNorthAmerican; // display in north american standard
// these data are stored in North American standard
int m_nData1;
int m_nData2;
};
someData::someData()
{
// by default, use North American standard
m_bNorthAmerican = TRUE;
// initialize other variables....
m_nData1 = 0;
m_nData2 = 0;
}
int someData::Data1()
{
if (m_bNorthAmerican) return m_nData1;
// function BritishStandard converts the NorthAmerican Standard to British
return BritishStandard(m_nData1);
}
int someData::Data2()
{
if (m_bNorthAmerican) return m_nData2;
// function BritishStandard converts the NorthAmerican Standard to British
return BritishStandard(m_nData2);
}
-Safai
Amy
May 19th, 1999, 02:05 PM
Hi Safai,
Thanks for your reply.
The problem with my app is that the data is spread out in more that one structure.
Moreover, the data is always stored in NorthAmerican standard irrespective of the fact how it is being read.
Do you think I can still use the hint that you provided me for the above problem???
Thanks.
Amy
Amy
May 19th, 1999, 02:07 PM
Hi Safai,
Thanks for your reply.
The problem with my app is that the data is spread out in more that one structure.
Moreover, the data is always stored in NorthAmerican standard irrespective of the fact how it is being read.
Do you think I can still use the hint that you provided me for the above problem???
Thanks.
Amy
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.