• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 273
  • Last Modified:

C++ Edit Box Validation

Hi......I am designing a database which shows all the records. The records can be updated using a dialog box. I have added a validation to one of the edit fields so it can only use ints but when i try to shw the results on the main form i get the error:
error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class CString' (or there is no acceptable conversion)
The code im using is:
void CAssignment2View::OnButton1()
{      
        CNewDlg d;      
      int nRet = -1;    
      if( nRet = d.DoModal() )    
      {                            
            switch ( nRet )  
            {   case -1:      
            AfxMessageBox("Error - Please Restart Program");  
            break;    
            case IDOK:
            UpdateData();
m_pSet->m_RegNo = d.m_RegNo;  
       d.m_RegNo = m_pSet->m_RegNo;
       UpdateData(FALSE);
        m_pSet->Update();
0
mtips
Asked:
mtips
  • 4
  • 3
1 Solution
 
jkrCommented:
How are the cariable you are using declared?
0
 
mtipsAuthor Commented:
The first form RegNo is Cstring as the information is  characters as the database info is characters
The dialog box regNo is int as the info must be changed to ints
I have tried changing the first form regNo as a int but it keeps changing back to Cstring on its own.
0
 
jkrCommented:
Well, then you might need to convet it, e.g.

CString tmp;
tmp.Format("%d",d.m_RegNo);
m_pSet->m_RegNo = tmp;  
d.m_RegNo = atoi(m_pSet->m_RegNo);

You'll need to

#include <stdlib.h>

for the above.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
mtipsAuthor Commented:
Hi
Im not to hot on C++ where would this code go?
Thanks
0
 
mtipsAuthor Commented:
I have put it in place of the Original RegNo piece of code but an error occurs saying that tmp is skipped by case and default labels.
0
 
jkrCommented:
>>where would this code go?

The same place as in yours above, i.e.


#include <stdlib.h>

void CAssignment2View::OnButton1()
{    
       CNewDlg d;      
     CString tmp;
     int nRet = -1;    
     if( nRet = d.DoModal() )    
     {                            
          switch ( nRet )  
          {   case -1:      
          AfxMessageBox("Error - Please Restart Program");  
          break;    
          case IDOK:
          UpdateData();
      tmp.Format("%d",d.m_RegNo);
      m_pSet->m_RegNo = tmp;  
      d.m_RegNo = atoi(m_pSet->m_RegNo);
      UpdateData(FALSE);
       m_pSet->Update();
0
 
mtipsAuthor Commented:
Cheers thanks alot for that ive got it working now great stuff.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now