Display Series of numbers in an edit box of MFC
-
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
-
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
-
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
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[][^]
-
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
SamPrem wrote:
how do i go abt it???
-
No need to call
UpdateData()
. -
Change your
for
loop variable to anint
, as adouble
makes no sense for what you are doing. -
Change
m_d1
from aCString
toCEdit
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
-
-
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
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