Hi,
I'm trying to format the date I am typing into an edit box to read mm/dd/yy. The code I have below does insert the forward slash where I want. The problem occurs when I use the back space key or arrow key to move through the text to do any additional editing.
The way I originally designed my OnChange() message handler to keep track of the number of time this method was called and insert the forward slash based on a count. This works fine. I'm also able to insert the forward slashes by keeping track of the length of the string in the edit box. But with using the "length" method I reach a point where one of the if() statements for checking the length is always true.
I tried resetting the count value in OnChar but I'm not making progress with this either. Any insight would be appreciated.
MPSoutine
void CEdSample2Dlg::OnChangeEditName()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
static bool IgnorNextChange = 0;
char Buffer[50];
m_edDate.LimitText(8);
m_edDate.GetWindowText( Buffer, 50 );
if(!IgnorNextChange && FormatDate(Buffer) )
{
IgnorNextChange = 1;
m_edDate.SetWindowText(""
m_edDate.ReplaceSel(Buffer);
}
IgnorNextChange = 0;
}
bool CEdSample2Dlg::FormatDate(char *Buffer)
{
char Message[25] = "in formatdate()";
char NewChar[3] = "/";
char EOL[3] = "\n";
int nLen = strlen(Buffer);
nCount = nCount++;
// DD/MM/YY
if(nCount == 2)
//if(nLen == 2)///*date buffer needs modifing then*/true )
{
//modifiy the date string etc...
//AfxMessageBox(Message);
strcat(Buffer,NewChar);
int nMonth = atoi(Buffer);
if(nMonth>12)
{
AfxMessageBox("Value to large"
//char Replacement[3] = " ";
//strcpy(Buffer,Replacement);
}
return 1;
}
if(nCount == 5)
//if(nLen == 5)
{
strcat(Buffer,NewChar);
return 1;
}
// if(nLen == 8)
// {
//AfxMessageBox("You entered to many characters"
//strcat(Buffer,EOL);
// return 1;
// }
return 0;
}
I'm trying to format the date I am typing into an edit box to read mm/dd/yy. The code I have below does insert the forward slash where I want. The problem occurs when I use the back space key or arrow key to move through the text to do any additional editing.
The way I originally designed my OnChange() message handler to keep track of the number of time this method was called and insert the forward slash based on a count. This works fine. I'm also able to insert the forward slashes by keeping track of the length of the string in the edit box. But with using the "length" method I reach a point where one of the if() statements for checking the length is always true.
I tried resetting the count value in OnChar but I'm not making progress with this either. Any insight would be appreciated.
MPSoutine
void CEdSample2Dlg::OnChangeEditName()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
static bool IgnorNextChange = 0;
char Buffer[50];
m_edDate.LimitText(8);
m_edDate.GetWindowText( Buffer, 50 );
if(!IgnorNextChange && FormatDate(Buffer) )
{
IgnorNextChange = 1;
m_edDate.SetWindowText(""
m_edDate.ReplaceSel(Buffer);
}
IgnorNextChange = 0;
}
bool CEdSample2Dlg::FormatDate(char *Buffer)
{
char Message[25] = "in formatdate()";
char NewChar[3] = "/";
char EOL[3] = "\n";
int nLen = strlen(Buffer);
nCount = nCount++;
// DD/MM/YY
if(nCount == 2)
//if(nLen == 2)///*date buffer needs modifing then*/true )
{
//modifiy the date string etc...
//AfxMessageBox(Message);
strcat(Buffer,NewChar);
int nMonth = atoi(Buffer);
if(nMonth>12)
{
AfxMessageBox("Value to large"
//char Replacement[3] = " ";
//strcpy(Buffer,Replacement);
}
return 1;
}
if(nCount == 5)
//if(nLen == 5)
{
strcat(Buffer,NewChar);
return 1;
}
// if(nLen == 8)
// {
//AfxMessageBox("You entered to many characters"
//strcat(Buffer,EOL);
// return 1;
// }
return 0;
}