Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. Clever Code
  4. A timely fix

A timely fix

Scheduled Pinned Locked Moved Clever Code
3 Posts 2 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Ravi Bhavnani
    wrote on last edited by
    #1

    So it's 4:00am and I'm spending the last few minutes of my wake cycle to add some prettiness to my GUI. The underlying code works, it's fast, and things are looking good. So before I call it a night (or day), I figure why not add a "Reset" button to reset the time interval (specified by a pair of CDateTimeCtrls) in the GUI. Clicking "Reset" is supposed to set the time interval to (365-days-ago to today). Easy enough. Wiping the last few crumbs of a ham sandwich from my face, I start typing furiously.

    void CMyDlg::OnBnClickedResetInterval()
    {
    // Compute interval
    CTime tmZero = 0;
    CTime tmEnd = CTime::GetCurrentTime();
    CTimeSpan tmTimeInterval (365, 0, 0, 0);
    CTime tmStart = tmEnd - tmTimeInterval;

    // Set "Start" date selector
    CString strFormat = "dd MMM yyyy";
    m_dtCtrlStart.SetFormat (strFormat);
    VERIFY (m_dtCtrlStart.SetTime (&tmStart));
    VERIFY (m_dtCtrlStart.SetRange (&tmZero, &tmEnd));

    // Set "End" date selector
    m_dtCtrlEnd.SetFormat (strFormat);
    VERIFY (m_dtCtrlEnd.SetTime (&tmEnd));
    VERIFY (m_dtCtrlEnd.SetRange (&tmZero, &tmEnd));
    }

    Of course it works. Once. :) The fix is easy, but it took a few hours of zzz's and a cuppa joe to see it. Good grief - it's almost lunch time. Time for a ham sandwich... /ravi

    This is your brain on Celcius Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com

    R M 2 Replies Last reply
    0
    • R Ravi Bhavnani

      So it's 4:00am and I'm spending the last few minutes of my wake cycle to add some prettiness to my GUI. The underlying code works, it's fast, and things are looking good. So before I call it a night (or day), I figure why not add a "Reset" button to reset the time interval (specified by a pair of CDateTimeCtrls) in the GUI. Clicking "Reset" is supposed to set the time interval to (365-days-ago to today). Easy enough. Wiping the last few crumbs of a ham sandwich from my face, I start typing furiously.

      void CMyDlg::OnBnClickedResetInterval()
      {
      // Compute interval
      CTime tmZero = 0;
      CTime tmEnd = CTime::GetCurrentTime();
      CTimeSpan tmTimeInterval (365, 0, 0, 0);
      CTime tmStart = tmEnd - tmTimeInterval;

      // Set "Start" date selector
      CString strFormat = "dd MMM yyyy";
      m_dtCtrlStart.SetFormat (strFormat);
      VERIFY (m_dtCtrlStart.SetTime (&tmStart));
      VERIFY (m_dtCtrlStart.SetRange (&tmZero, &tmEnd));

      // Set "End" date selector
      m_dtCtrlEnd.SetFormat (strFormat);
      VERIFY (m_dtCtrlEnd.SetTime (&tmEnd));
      VERIFY (m_dtCtrlEnd.SetRange (&tmZero, &tmEnd));
      }

      Of course it works. Once. :) The fix is easy, but it took a few hours of zzz's and a cuppa joe to see it. Good grief - it's almost lunch time. Time for a ham sandwich... /ravi

      This is your brain on Celcius Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com

      R Offline
      R Offline
      Ravi Bhavnani
      wrote on last edited by
      #2

      // Set "End" date selector
      m_dtCtrlEnd.SetFormat (strFormat);
      VERIFY (m_dtCtrlEnd.SetTime (&tmEnd));
      VERIFY (m_dtCtrlEnd.SetRange (&tmZero, &tmEnd));
      CTime tmEndOfToday (tmEnd.GetYear(), tmEnd.GetMonth(), tmEnd.GetDay(), 23, 59, 59); VERIFY (m_dtCtrlEnd.SetRange (&tmZero, &tmEndOfToday));

      Urp. /ravi

      This is your brain on Celcius Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com

      1 Reply Last reply
      0
      • R Ravi Bhavnani

        So it's 4:00am and I'm spending the last few minutes of my wake cycle to add some prettiness to my GUI. The underlying code works, it's fast, and things are looking good. So before I call it a night (or day), I figure why not add a "Reset" button to reset the time interval (specified by a pair of CDateTimeCtrls) in the GUI. Clicking "Reset" is supposed to set the time interval to (365-days-ago to today). Easy enough. Wiping the last few crumbs of a ham sandwich from my face, I start typing furiously.

        void CMyDlg::OnBnClickedResetInterval()
        {
        // Compute interval
        CTime tmZero = 0;
        CTime tmEnd = CTime::GetCurrentTime();
        CTimeSpan tmTimeInterval (365, 0, 0, 0);
        CTime tmStart = tmEnd - tmTimeInterval;

        // Set "Start" date selector
        CString strFormat = "dd MMM yyyy";
        m_dtCtrlStart.SetFormat (strFormat);
        VERIFY (m_dtCtrlStart.SetTime (&tmStart));
        VERIFY (m_dtCtrlStart.SetRange (&tmZero, &tmEnd));

        // Set "End" date selector
        m_dtCtrlEnd.SetFormat (strFormat);
        VERIFY (m_dtCtrlEnd.SetTime (&tmEnd));
        VERIFY (m_dtCtrlEnd.SetRange (&tmZero, &tmEnd));
        }

        Of course it works. Once. :) The fix is easy, but it took a few hours of zzz's and a cuppa joe to see it. Good grief - it's almost lunch time. Time for a ham sandwich... /ravi

        This is your brain on Celcius Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com

        M Offline
        M Offline
        megaadam
        wrote on last edited by
        #3

        Shouln't you call it an untimely fix ?

        _____________________________________ Action without thought is not action Action without emotion is not life

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups