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. General Programming
  3. C / C++ / MFC
  4. Display Series of numbers in an edit box of MFC

Display Series of numbers in an edit box of MFC

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++
5 Posts 5 Posters 0 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.
  • S Offline
    S Offline
    SamPrem
    wrote on last edited by
    #1

    I wanted to display a sequence of numbers in an Edit box just like a timer or a stop watch.Below is my code void CEditDlg::OnButtonOK() { UpdateData(); for(double i=0;i<=25;i++){ m_d1=i; //m_d1 is the name of the variable of edit box UpdateData(false); Sleep(10); } } the above code gives me an output of 25 whereas i want a sequence of numbers to be displayed b/w 0-25.how do i go abt it??? Sam

    H P D K 4 Replies Last reply
    0
    • S SamPrem

      I wanted to display a sequence of numbers in an Edit box just like a timer or a stop watch.Below is my code void CEditDlg::OnButtonOK() { UpdateData(); for(double i=0;i<=25;i++){ m_d1=i; //m_d1 is the name of the variable of edit box UpdateData(false); Sleep(10); } } the above code gives me an output of 25 whereas i want a sequence of numbers to be displayed b/w 0-25.how do i go abt it??? Sam

      H Offline
      H Offline
      houari_id
      wrote on last edited by
      #2

      You can use GetDlgItem(IDC_OF_TEXTBOX)->SetWindowText(m_putStringHere); instead...

      -Houari

      1 Reply Last reply
      0
      • S SamPrem

        I wanted to display a sequence of numbers in an Edit box just like a timer or a stop watch.Below is my code void CEditDlg::OnButtonOK() { UpdateData(); for(double i=0;i<=25;i++){ m_d1=i; //m_d1 is the name of the variable of edit box UpdateData(false); Sleep(10); } } the above code gives me an output of 25 whereas i want a sequence of numbers to be displayed b/w 0-25.how do i go abt it??? Sam

        P Offline
        P Offline
        prasad_som
        wrote on last edited by
        #3

        SamPrem wrote:

        Sleep(10);

        You have ket delay of 10 ms. Thats the reson, you are able to recognize last character displayed. Your code is setting text 0-25 to edit box. But, you are not able to see i, because it happens in very short time. May be, you can try setting dealy of 2 sec(2000ms).

        Prasad Notifier using ATL | Operator new[],delete[][^]

        1 Reply Last reply
        0
        • S SamPrem

          I wanted to display a sequence of numbers in an Edit box just like a timer or a stop watch.Below is my code void CEditDlg::OnButtonOK() { UpdateData(); for(double i=0;i<=25;i++){ m_d1=i; //m_d1 is the name of the variable of edit box UpdateData(false); Sleep(10); } } the above code gives me an output of 25 whereas i want a sequence of numbers to be displayed b/w 0-25.how do i go abt it??? Sam

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          SamPrem wrote:

          how do i go abt it???

          • No need to call UpdateData().

          • Change your for loop variable to an int, as a double makes no sense for what you are doing.

          • Change m_d1 from a CString to CEdit instead.

          • Update the edit control with m_d1.ReplaceSel() instead.

          • Using a different 'sleep' value is irrelevant.

            SamPrem wrote:

            the above code gives me an output of 25

            Of course it does, since you are overwriting the contents of the edit control each time through the for loop.


            "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

            "Judge not by the eye but by the heart." - Native American Proverb

          1 Reply Last reply
          0
          • S SamPrem

            I wanted to display a sequence of numbers in an Edit box just like a timer or a stop watch.Below is my code void CEditDlg::OnButtonOK() { UpdateData(); for(double i=0;i<=25;i++){ m_d1=i; //m_d1 is the name of the variable of edit box UpdateData(false); Sleep(10); } } the above code gives me an output of 25 whereas i want a sequence of numbers to be displayed b/w 0-25.how do i go abt it??? Sam

            K Offline
            K Offline
            krmed
            wrote on last edited by
            #5

            In your for loop, you use the UpdataData (and that's OK), then sleep, but stay in the loop. The UpdateData actually updates the data, and posts a message for the window to update, however, the message can't be processed until you leave this loop - that's why you only see the last number. You can modify your code as follows to see each value. (and as noted, your loop control variable should be an int instead of a double).

            void CEditDlg::OnButtonOK()
            { UpdateData();
            for(int i=0;i<=25;i++){
            m_d1=i; //m_d1 is the name of the variable of edit box
            UpdateData(false);
            GetDlgItem(IDC_YOUR_EDIT_BOX_ID)->UpdateWindow();
            Sleep(10);
            }
            }

            Hope that helps.

            Karl - WK5M PP-ASEL-IA (N43CS) PGP Key: 0xDB02E193 PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193

            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