[MFC] Vérification de CString dans une edit box
Bonjour j'ai une edit box dans laquelle l'utilisateur entre une heure (heures, minutes et secondes)!
J'ai déjà posté un message semblable il y a quelques jours, je remercie farscape pour sa collaboration.
A présent j'ai rajouté une partie de code qui est censée vérifier le format des secondes:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| void CWorkshiftDialog::OnChangeHour0()
{
CString str;
GetDlgItem(IDC_HOUR0)->GetWindowText(str);
str.TrimRight();
char *stopstring=NULL;
long l = strtol( str, &stopstring, 10 );
if(l>23)
{
AfxMessageBox("Msg1 Invalid hour format! Must be between 0 and 23!");
str="";
UpdateData(FALSE);
return;
}
if(stopstring && *stopstring && *stopstring!=':')
{
AfxMessageBox("Msg2 Invalid separator character! Must be ':' !");
str="";
UpdateData(FALSE);
return;
}
if(str.GetLength()>3)
{
stopstring=NULL;
l = strtol( str.Mid(3,2), &stopstring, 10 );
if(l>59)
{
AfxMessageBox("Msg3 Invalid minute format! Must be between 0 and 59!");
str="";
UpdateData(FALSE);
return;
}
}
if(stopstring && *stopstring && *stopstring!=':')
{
AfxMessageBox("Msg4 Invalid separator character! Must be ':' !");
str="";
UpdateData(FALSE);
return;
}
if(str.GetLength()>5)
{
stopstring=NULL;
l = strtol( str.Mid(5,2), &stopstring, 10 );
if(l>59)
{
AfxMessageBox("Msg5 Invalid second format! Must be between 0 and 59!");
str="";
UpdateData(FALSE);
return;
}
}
if(str.GetLength()>8)
{
AfxMessageBox("Msg6 Invalid time format!");
return;
}
} |
Le problème est le suivant: lorsque je tape le premier chiffre des minutes, le message 4 s'affiche directement!
Faut-il donner un nom différent au deux séparateurs ':' ??
Ou alors dois-je créer une autre fonction qui vérifiera combien de caractères j'ai entré avant de tester mon deuxième séparateur?