CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 1999
    Posts
    17

    Displaying two types of units

    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


  2. #2
    Join Date
    May 1999
    Location
    Toronto, Ontario, Canada
    Posts
    155

    Re: Displaying two types of units

    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:ata1()
    {
    if (m_bNorthAmerican) return m_nData1;

    // function BritishStandard converts the NorthAmerican Standard to British
    return BritishStandard(m_nData1);
    }

    int someData:ata2()
    {
    if (m_bNorthAmerican) return m_nData2;

    // function BritishStandard converts the NorthAmerican Standard to British
    return BritishStandard(m_nData2);
    }




    -Safai



  3. #3
    Join Date
    Apr 1999
    Posts
    17

    Re: Displaying two types of units

    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


  4. #4
    Join Date
    Apr 1999
    Posts
    17

    Re: Displaying two types of units

    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



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured