CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Guest

    do-while loop & UpdateData(FALSE)

    Dear all,
    I have a button "Go" and an edit box with a member variable
    associated m_var (type double).
    When I pressed the button, the method associated "OnButtonGo" run
    a do-while loop like this:
    ccode
    void CMyCodeDlg::OnButtonGo()
    {
    double err_toll = 0.0001;

    do
    {
    .... //other math code
    m_var = CalculateError();
    UpdateData(FALSE);
    } while (m_var < err_toll);

    }
    /ccode
    the value of variable m_var change during the loop and I would like to see
    the changes for every iteration, but on video is printed only the value
    related to the last iteration. Why?
    I hope that the question is clear. Sorry, for my english!

    Thank, Giuseppe.





  2. #2
    Join Date
    May 1999
    Location
    Seattle, WA USA
    Posts
    423

    Re: do-while loop & UpdateData(FALSE)

    it is probably changing like you want, it is just changing too fast for you to see the difference. Your do-while loop can probably execute about 1000 times a second (On a relatively new computer).

    Try calling
    Sleep (DWORD dwMilliseconds)
    after the UpdateData to pause for a little while before the next iteration of the loop.

    --michael


  3. #3
    Join Date
    May 1999
    Location
    West Sussex, England
    Posts
    1,939

    Re: do-while loop & UpdateData(FALSE)

    The varaible does not update because you need to allow other messages to be processed during your loop. Try adding the following code to the end of your loop aftere the UpdateData() :


    MSG msg ;

    SetDlgItemText(IDC_STATUS, text) ;
    while (::PeekMessage(&msg, NULL, 0, 0, PM_NOYIELD | PM_REMOVE))
    {
    ::TranslateMessage(&msg) ;
    :ispatchMessage(&msg) ;
    }




    Warning : With this in the loop, all the buttons can be clicked on your dialog again, so you will need to block certain funtions from running again, as you could have two concurrent versions of your OnButtonGo() function running at the same time! The easiest wasy around this is to disable the button before your loop and then re-enable it at the end of the procedure.

    GetDlgItem(IDC_GO_BUTTON)->EnableWindow(false) ;

    // loop code

    GetDlgItem(IDC_GO_BUTTON)->EnableWindow(true) ;




    HTH


    Roger Allen
    Please use meaningful question titles - "Help me" does not let me know whether I can help with your question, and I am unlikely to bother reading it.
    Please remember to rate useful answers. It lets us know when a question has been answered.

  4. #4
    Join Date
    Jun 1999
    Posts
    1

    Re: do-while loop & UpdateData(FALSE)

    Dear Roger Allen,
    Thanks for your fast reply, I have insert your code in my application and now it is all ok. It makes what I want! A suggested for you. I have omitted the follow code:
    (*) SetDlgItemText(IDC_STATUS, text) ;
    because I have used UpdateData(FALSE) that updates all edit box. I think that (*) is necessary when I use GetDlgItem(IDC_STATUS) -> SetWindowText(text). What do you think about?

    This Discussion Group is very excellent and I have submitted it. Bye, Bye from ITALIA. Sei stato fantastico (you are fantastic).



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