Passing a variable
-
I have this code:
if (a = 1) dwID = IDC_EDIT1; if (a = 2) dwID = IDC_EDIT2; if (a = 3) dwID = IDC_EDIT3; GetString(pView, dwID);
And then this function:CString GetString(CView *pView, UINT dwID) { CString str; CWnd *pWndChild = pView->GetDlgItem( (UINT)dwID); pWndChild->GetWindowText(str); return str; }
If I just called GetString(pView, IDC_EDIT1), the code works. But if I use:if (a = 1) dwID = IDC_EDIT1; if (a = 2) dwID = IDC_EDIT2; if (a = 3) dwID = IDC_EDIT3;
I get an "unhandled exception" and it points to this code:void CWnd::GetWindowText(CString& rString) const { ASSERT(::IsWindow(m_hWnd));
Is there any way I can call GetString(pView, dwID) or something like this instead of GetString(pView, IDC_EDIT1); Please, any response any one can give me will be greatly appreciated. Sincerely, Danielle Brina -
I have this code:
if (a = 1) dwID = IDC_EDIT1; if (a = 2) dwID = IDC_EDIT2; if (a = 3) dwID = IDC_EDIT3; GetString(pView, dwID);
And then this function:CString GetString(CView *pView, UINT dwID) { CString str; CWnd *pWndChild = pView->GetDlgItem( (UINT)dwID); pWndChild->GetWindowText(str); return str; }
If I just called GetString(pView, IDC_EDIT1), the code works. But if I use:if (a = 1) dwID = IDC_EDIT1; if (a = 2) dwID = IDC_EDIT2; if (a = 3) dwID = IDC_EDIT3;
I get an "unhandled exception" and it points to this code:void CWnd::GetWindowText(CString& rString) const { ASSERT(::IsWindow(m_hWnd));
Is there any way I can call GetString(pView, dwID) or something like this instead of GetString(pView, IDC_EDIT1); Please, any response any one can give me will be greatly appreciated. Sincerely, Danielle BrinaIf I understand correctly, you are using a test condition for the following:
if (a = 1) dwID = IDC_EDIT1;
if (a = 2) dwID = IDC_EDIT2;
if (a = 3) dwID = IDC_EDIT3;If that is the case, you should be using the == operator instead of the = operator. if (a == 1) dwID = IDC_EDIT1; if (a == 2) dwID = IDC_EDIT2; if (a == 3) dwID = IDC_EDIT3; It's pretty easy to confuse the assignment operator with the equals operator which is 2 consecutive equal signs. :) -- modified at 13:27 Monday 24th July, 2006
-
If I understand correctly, you are using a test condition for the following:
if (a = 1) dwID = IDC_EDIT1;
if (a = 2) dwID = IDC_EDIT2;
if (a = 3) dwID = IDC_EDIT3;If that is the case, you should be using the == operator instead of the = operator. if (a == 1) dwID = IDC_EDIT1; if (a == 2) dwID = IDC_EDIT2; if (a == 3) dwID = IDC_EDIT3; It's pretty easy to confuse the assignment operator with the equals operator which is 2 consecutive equal signs. :) -- modified at 13:27 Monday 24th July, 2006
-
I appreciate the reply. The = is just a typo on my part. Im using == but I still get the error.
-
I have this code:
if (a = 1) dwID = IDC_EDIT1; if (a = 2) dwID = IDC_EDIT2; if (a = 3) dwID = IDC_EDIT3; GetString(pView, dwID);
And then this function:CString GetString(CView *pView, UINT dwID) { CString str; CWnd *pWndChild = pView->GetDlgItem( (UINT)dwID); pWndChild->GetWindowText(str); return str; }
If I just called GetString(pView, IDC_EDIT1), the code works. But if I use:if (a = 1) dwID = IDC_EDIT1; if (a = 2) dwID = IDC_EDIT2; if (a = 3) dwID = IDC_EDIT3;
I get an "unhandled exception" and it points to this code:void CWnd::GetWindowText(CString& rString) const { ASSERT(::IsWindow(m_hWnd));
Is there any way I can call GetString(pView, dwID) or something like this instead of GetString(pView, IDC_EDIT1); Please, any response any one can give me will be greatly appreciated. Sincerely, Danielle BrinaDanYELL wrote:
if (a = 1) dwID = IDC_EDIT1; if (a = 2) dwID = IDC_EDIT2; if (a = 3) dwID = IDC_EDIT3;
If
a
was equal to1
, why would you want the last two statements to be evaluated?
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
-
I have this code:
if (a = 1) dwID = IDC_EDIT1; if (a = 2) dwID = IDC_EDIT2; if (a = 3) dwID = IDC_EDIT3; GetString(pView, dwID);
And then this function:CString GetString(CView *pView, UINT dwID) { CString str; CWnd *pWndChild = pView->GetDlgItem( (UINT)dwID); pWndChild->GetWindowText(str); return str; }
If I just called GetString(pView, IDC_EDIT1), the code works. But if I use:if (a = 1) dwID = IDC_EDIT1; if (a = 2) dwID = IDC_EDIT2; if (a = 3) dwID = IDC_EDIT3;
I get an "unhandled exception" and it points to this code:void CWnd::GetWindowText(CString& rString) const { ASSERT(::IsWindow(m_hWnd));
Is there any way I can call GetString(pView, dwID) or something like this instead of GetString(pView, IDC_EDIT1); Please, any response any one can give me will be greatly appreciated. Sincerely, Danielle BrinaDanYELL wrote:
if (a == 1) dwID = IDC_EDIT1; if (a == 2) dwID = IDC_EDIT2; if (a == 3) dwID = IDC_EDIT3;
Can you show how 'a' is passed. Possibly it is not going through any of above condition and 'dwID' is having garbage value.
DanYELL wrote:
CWnd *pWndChild = pView->GetDlgItem( (UINT)dwID);
and this statement is initializing pWndChild with NULL.