why the value enter the IDC_EDIT1 is not shown in IDC_EDIT2?
-
In MFC wizard I have created a dialog form with two EditBoxs(IDC_EDIT1 and IDC_EDIT2). m_var1 and m_var2 are type unsigned integer. The type of the two edit boxes are of unsigned integer data type:). The names of the member variables are m_var1 and m_var2. Their is a Button on the Dialog form Kindly observe the code given void CMFC_7Dlg::OnButton1() { // TODO: Add your control notification handler code here UINT abc = m_var1; m_var2 = abc; UpdateData(FALSE); } the problem is that when click the button1, the value entered in IDC_EDIT1 is not assigned to the temporary variable abc. When I debug the code, the value assigned to abc is zero. For example if enter a unsigned value 23 , the value is not assinged to the variable abc. Kindly observe the code which is given below void CMFC_7Dlg::OnButton1() { // TODO: Add your control notification handler code here UpdateData(TRUE); m_var2 = m_var1; UpdateData(TRUE); } In the above code, the value enter in IDC_EDIT1 is not transferred to IDC_EDIT2 even though m_var1 and m_var2 are both unsigned integer data type. Kindly observe the code which is given below void CMFC_7Dlg::OnButton1() { m_var2 = m_var1; } In the above given code, the direct assinged of m_var1 to m_var2 is not possible. When I debug the program , only zero is assinged to m_var2. My question is why the value enter the IDC_EDIT1 is not shown in IDC_EDIT2? Can any one please help me in this matter. :) -- modified at 6:01 Tuesday 14th March, 2006
-
In MFC wizard I have created a dialog form with two EditBoxs(IDC_EDIT1 and IDC_EDIT2). m_var1 and m_var2 are type unsigned integer. The type of the two edit boxes are of unsigned integer data type:). The names of the member variables are m_var1 and m_var2. Their is a Button on the Dialog form Kindly observe the code given void CMFC_7Dlg::OnButton1() { // TODO: Add your control notification handler code here UINT abc = m_var1; m_var2 = abc; UpdateData(FALSE); } the problem is that when click the button1, the value entered in IDC_EDIT1 is not assigned to the temporary variable abc. When I debug the code, the value assigned to abc is zero. For example if enter a unsigned value 23 , the value is not assinged to the variable abc. Kindly observe the code which is given below void CMFC_7Dlg::OnButton1() { // TODO: Add your control notification handler code here UpdateData(TRUE); m_var2 = m_var1; UpdateData(TRUE); } In the above code, the value enter in IDC_EDIT1 is not transferred to IDC_EDIT2 even though m_var1 and m_var2 are both unsigned integer data type. Kindly observe the code which is given below void CMFC_7Dlg::OnButton1() { m_var2 = m_var1; } In the above given code, the direct assinged of m_var1 to m_var2 is not possible. When I debug the program , only zero is assinged to m_var2. My question is why the value enter the IDC_EDIT1 is not shown in IDC_EDIT2? Can any one please help me in this matter. :) -- modified at 6:01 Tuesday 14th March, 2006
phijophlip wrote:
void CMFC_7Dlg::OnButton1() { // TODO: Add your control notification handler code here UINT abc = m_var1; m_var2 = abc; UpdateData(FALSE); }
UpdateData(TRUE);
UINT abc = m_var1;
m_var2 = abc;phijophlip wrote:
void CMFC_7Dlg::OnButton1() { // TODO: Add your control notification handler code here UpdateData(TRUE); m_var2 = m_var1; UpdateData(TRUE); }
UpdateData(TRUE);
m_var2 = m_var1;
UpdateData(FALSE);
Nibu thomas Software Developer
-
In MFC wizard I have created a dialog form with two EditBoxs(IDC_EDIT1 and IDC_EDIT2). m_var1 and m_var2 are type unsigned integer. The type of the two edit boxes are of unsigned integer data type:). The names of the member variables are m_var1 and m_var2. Their is a Button on the Dialog form Kindly observe the code given void CMFC_7Dlg::OnButton1() { // TODO: Add your control notification handler code here UINT abc = m_var1; m_var2 = abc; UpdateData(FALSE); } the problem is that when click the button1, the value entered in IDC_EDIT1 is not assigned to the temporary variable abc. When I debug the code, the value assigned to abc is zero. For example if enter a unsigned value 23 , the value is not assinged to the variable abc. Kindly observe the code which is given below void CMFC_7Dlg::OnButton1() { // TODO: Add your control notification handler code here UpdateData(TRUE); m_var2 = m_var1; UpdateData(TRUE); } In the above code, the value enter in IDC_EDIT1 is not transferred to IDC_EDIT2 even though m_var1 and m_var2 are both unsigned integer data type. Kindly observe the code which is given below void CMFC_7Dlg::OnButton1() { m_var2 = m_var1; } In the above given code, the direct assinged of m_var1 to m_var2 is not possible. When I debug the program , only zero is assinged to m_var2. My question is why the value enter the IDC_EDIT1 is not shown in IDC_EDIT2? Can any one please help me in this matter. :) -- modified at 6:01 Tuesday 14th March, 2006
If I understand you correctly, you would like the value contained in the EDIT_1 to be shown in the EDIT_2 control, on pressing BUTTON_1 ? try the following... void CMFC_7Dlg::OnButton1(){ // Force DDX- DDV to do it´s stuff // Save and Validate (TRUE) parameter // ********************************** UpdateData(TRUE); // Set the values as required // ************************** m_var2 = m_var1; // Force DDX - DDV to do it´s stuff // Read values from member variables, // and display them (FALSE) parameter // ********************************** UpdateData(FALSE); } alternativly you could do the following void CMFC_7Dlg::OnButton1(){ // Force DDX- DDV to do it´s stuff // Save and Validate (TRUE) parameter // ********************************** UpdateData(TRUE); // Set the values as required // ************************** m_var2 = m_var1; // Update the UI to show the change // ******************************** SetDlgItemInt(IDC_EDIT_2, m_var2, FALSE); } regards Phil bum... and I thought I´d got rid of all the bugs :(
-
In MFC wizard I have created a dialog form with two EditBoxs(IDC_EDIT1 and IDC_EDIT2). m_var1 and m_var2 are type unsigned integer. The type of the two edit boxes are of unsigned integer data type:). The names of the member variables are m_var1 and m_var2. Their is a Button on the Dialog form Kindly observe the code given void CMFC_7Dlg::OnButton1() { // TODO: Add your control notification handler code here UINT abc = m_var1; m_var2 = abc; UpdateData(FALSE); } the problem is that when click the button1, the value entered in IDC_EDIT1 is not assigned to the temporary variable abc. When I debug the code, the value assigned to abc is zero. For example if enter a unsigned value 23 , the value is not assinged to the variable abc. Kindly observe the code which is given below void CMFC_7Dlg::OnButton1() { // TODO: Add your control notification handler code here UpdateData(TRUE); m_var2 = m_var1; UpdateData(TRUE); } In the above code, the value enter in IDC_EDIT1 is not transferred to IDC_EDIT2 even though m_var1 and m_var2 are both unsigned integer data type. Kindly observe the code which is given below void CMFC_7Dlg::OnButton1() { m_var2 = m_var1; } In the above given code, the direct assinged of m_var1 to m_var2 is not possible. When I debug the program , only zero is assinged to m_var2. My question is why the value enter the IDC_EDIT1 is not shown in IDC_EDIT2? Can any one please help me in this matter. :) -- modified at 6:01 Tuesday 14th March, 2006
If I understand you correctly you need to eneter Edit1 value to Edit2 value void CAnswerView::OnBnClickedButton2() { CString str; m_Edit.GetWindowText(str); m_Edit2.SetWindowText(str); //int Index=atoi(str); } I tesed this code and work Now this code is good or bad?
-
If I understand you correctly you need to eneter Edit1 value to Edit2 value void CAnswerView::OnBnClickedButton2() { CString str; m_Edit.GetWindowText(str); m_Edit2.SetWindowText(str); //int Index=atoi(str); } I tesed this code and work Now this code is good or bad?
WhiteSky wrote:
I tesed this code and work Now this code is good or bad?
It is the only way that will not end in blood, sweat and tears, IMHO. NEVER EVER call UpdateData() yourself, but use control-variables and Get/SetWindowText. The value-variables are for shielding the inner workings of a dialog from the outside. INSIDE a dialog they only spread confusion. So far my personal, very dogmatic views.
"We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation." -- Caius Petronius, Roman Consul, 66 A.D. -- modified at 9:42 Tuesday 14th March, 2006 UpdateWindow -> UpdateData
-
In MFC wizard I have created a dialog form with two EditBoxs(IDC_EDIT1 and IDC_EDIT2). m_var1 and m_var2 are type unsigned integer. The type of the two edit boxes are of unsigned integer data type:). The names of the member variables are m_var1 and m_var2. Their is a Button on the Dialog form Kindly observe the code given void CMFC_7Dlg::OnButton1() { // TODO: Add your control notification handler code here UINT abc = m_var1; m_var2 = abc; UpdateData(FALSE); } the problem is that when click the button1, the value entered in IDC_EDIT1 is not assigned to the temporary variable abc. When I debug the code, the value assigned to abc is zero. For example if enter a unsigned value 23 , the value is not assinged to the variable abc. Kindly observe the code which is given below void CMFC_7Dlg::OnButton1() { // TODO: Add your control notification handler code here UpdateData(TRUE); m_var2 = m_var1; UpdateData(TRUE); } In the above code, the value enter in IDC_EDIT1 is not transferred to IDC_EDIT2 even though m_var1 and m_var2 are both unsigned integer data type. Kindly observe the code which is given below void CMFC_7Dlg::OnButton1() { m_var2 = m_var1; } In the above given code, the direct assinged of m_var1 to m_var2 is not possible. When I debug the program , only zero is assinged to m_var2. My question is why the value enter the IDC_EDIT1 is not shown in IDC_EDIT2? Can any one please help me in this matter. :) -- modified at 6:01 Tuesday 14th March, 2006
Yet another example of why
UpdateData()
should be avoided. It's just too easy to mess up. You'd be better off usingGetWindowText()
instead.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
-
WhiteSky wrote:
I tesed this code and work Now this code is good or bad?
It is the only way that will not end in blood, sweat and tears, IMHO. NEVER EVER call UpdateData() yourself, but use control-variables and Get/SetWindowText. The value-variables are for shielding the inner workings of a dialog from the outside. INSIDE a dialog they only spread confusion. So far my personal, very dogmatic views.
"We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation." -- Caius Petronius, Roman Consul, 66 A.D. -- modified at 9:42 Tuesday 14th March, 2006 UpdateWindow -> UpdateData
jhwurmbach wrote:
NEVER EVER call UpdateWindow()...
Perhaps you meant
UpdateData()
.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
-
Yet another example of why
UpdateData()
should be avoided. It's just too easy to mess up. You'd be better off usingGetWindowText()
instead.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
I do not think that UpdateData(x) should be avoided. If used correctly, it is a lot eaiser then GetWindowText/SetWindowText. From the code snippet provided, It is not really clear what the purpose of two variables si, for one value to be retrieved... just my tuppence.. Phil bum... and I thought I´d got rid of all the bugs :(
-
I do not think that UpdateData(x) should be avoided. If used correctly, it is a lot eaiser then GetWindowText/SetWindowText. From the code snippet provided, It is not really clear what the purpose of two variables si, for one value to be retrieved... just my tuppence.. Phil bum... and I thought I´d got rid of all the bugs :(
Phil.Benson wrote:
If used correctly...
That's a mighty big if there. The problem is that most beginners do not use it correctly and end up butchering their code just to get around its caveats. I find it best to avoid altogether.
GetWindowText()
andSetWindowText
are a lot cleaner and you can tell exactly what is going to happen. UsingUpdateData()
is an all-or-nothing operation. Consider the situation where you set some member variables, call a dialog'sDoModal()
method, callUpdateData()
, then click the Cancel button. Now the member variables are potentially not in the same state they were prior to callingDoModal()
. You should be able to assume that member variables retain their same value before and after if the Cancel button has been clicked. Use ofUpdateData()
makes this a bad assumption.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
-
Phil.Benson wrote:
If used correctly...
That's a mighty big if there. The problem is that most beginners do not use it correctly and end up butchering their code just to get around its caveats. I find it best to avoid altogether.
GetWindowText()
andSetWindowText
are a lot cleaner and you can tell exactly what is going to happen. UsingUpdateData()
is an all-or-nothing operation. Consider the situation where you set some member variables, call a dialog'sDoModal()
method, callUpdateData()
, then click the Cancel button. Now the member variables are potentially not in the same state they were prior to callingDoModal()
. You should be able to assume that member variables retain their same value before and after if the Cancel button has been clicked. Use ofUpdateData()
makes this a bad assumption.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
David wrote "That's a mighty big if there. The problem is that most beginners do not use it correctly..." Nobody said programming is easy. If it was, we would not get paid as much :-D As for choosing Cancel, do you manipulate application data directly within the dialog? Or do you wait for the result (IDOK or IDCANCEL) before making any changes resulting from the data being changed within the dialog? again, just my tuppence Phil bum... and I thought I´d got rid of all the bugs :( -- modified at 9:43 Tuesday 14th March, 2006 Here on code project, If I can remember correctly it was PJ Ahrens, has written an interesting article about DDX-DDV in the MFC