Hi All !(CString Class)
-
How can alow the user to enter only numbers lets say with "4" into CEditBox ! for ex: 41,42,411,42222 !!!!!! i have tried this : CString sCod; m_cod.GetWindowText(sCod); if(!sCod.Left(1).Compare("4")) { //something } else { AfxMessageBox("Incorect number"); } but is not working ! please help me !
Bravoone
-
How can alow the user to enter only numbers lets say with "4" into CEditBox ! for ex: 41,42,411,42222 !!!!!! i have tried this : CString sCod; m_cod.GetWindowText(sCod); if(!sCod.Left(1).Compare("4")) { //something } else { AfxMessageBox("Incorect number"); } but is not working ! please help me !
Bravoone
In the dialog editor right click the edit box and check the Number property to true.
Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_
-
How can alow the user to enter only numbers lets say with "4" into CEditBox ! for ex: 41,42,411,42222 !!!!!! i have tried this : CString sCod; m_cod.GetWindowText(sCod); if(!sCod.Left(1).Compare("4")) { //something } else { AfxMessageBox("Incorect number"); } but is not working ! please help me !
Bravoone
Assign an integer variable to edit box.(See
DDX_
) And UseUpdateData
accordingly.
Prasad MS MVP - VC++
-
How can alow the user to enter only numbers lets say with "4" into CEditBox ! for ex: 41,42,411,42222 !!!!!! i have tried this : CString sCod; m_cod.GetWindowText(sCod); if(!sCod.Left(1).Compare("4")) { //something } else { AfxMessageBox("Incorect number"); } but is not working ! please help me !
Bravoone
Use Dialog Data Exchange or Validate. This will not allow the user to enter anything other than number. int iCod; void CYourClassName::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); DDX_Text(pDX, IDC_EDIT, iCod); DDV_MinMaxInt(pDX, iCod, 0, 1000); //Third and fourth parameter is min and max value. } Hope this will work. Anurag Gandhi.
-
How can alow the user to enter only numbers lets say with "4" into CEditBox ! for ex: 41,42,411,42222 !!!!!! i have tried this : CString sCod; m_cod.GetWindowText(sCod); if(!sCod.Left(1).Compare("4")) { //something } else { AfxMessageBox("Incorect number"); } but is not working ! please help me !
Bravoone
you can try the
_ttoi
function to determine if the string is actually an integer. The function will return0
if the string cannot be parsed as integer. So you should also check if user actually entered0
in theCEditBox
. "What if user enters something like0000
?" question still remains, but this is better than nothing :)int val = _ttoi(sCod); if (val == 0 && sCod != _T("0")) { AfxMessageBox(_T("Incorrect number")); }
-
How can alow the user to enter only numbers lets say with "4" into CEditBox ! for ex: 41,42,411,42222 !!!!!! i have tried this : CString sCod; m_cod.GetWindowText(sCod); if(!sCod.Left(1).Compare("4")) { //something } else { AfxMessageBox("Incorect number"); } but is not working ! please help me !
Bravoone
First of all, I haven´t found a Left member inside the CString class :confused: I would do that way: char sCod[20]; strcpy(sCod,m_cod.GetWindowText()); if (strcmp(sCod[0],"4")==0) { //Here write your code } else { MessageBox("Incorrect number"); } I hope it may help you! Good luck from Bilbao! (SPAIN) :-D
-
How can alow the user to enter only numbers lets say with "4" into CEditBox ! for ex: 41,42,411,42222 !!!!!! i have tried this : CString sCod; m_cod.GetWindowText(sCod); if(!sCod.Left(1).Compare("4")) { //something } else { AfxMessageBox("Incorect number"); } but is not working ! please help me !
Bravoone
all i want is to enter only numbers that have 4 first number for example 48956687 the first number is 4 !!!!!! Thank you !
Bravoone
-
First of all, I haven´t found a Left member inside the CString class :confused: I would do that way: char sCod[20]; strcpy(sCod,m_cod.GetWindowText()); if (strcmp(sCod[0],"4")==0) { //Here write your code } else { MessageBox("Incorrect number"); } I hope it may help you! Good luck from Bilbao! (SPAIN) :-D
-
First of all, I haven´t found a Left member inside the CString class :confused: I would do that way: char sCod[20]; strcpy(sCod,m_cod.GetWindowText()); if (strcmp(sCod[0],"4")==0) { //Here write your code } else { MessageBox("Incorrect number"); } I hope it may help you! Good luck from Bilbao! (SPAIN) :-D
i have 2 errors to your code : 1)error C2661: 'GetWindowTextA' : no overloaded function takes 0 parameters 2)error C2664: 'strcmp' : cannot convert parameter 1 from 'char' to 'const char *' what is wrong ?
Bravoone
-
Gosh!! Next time remember me to write the name of the function like this "Left" and not like this "left". I´m really ashamed... :doh: :laugh:
-
How can alow the user to enter only numbers lets say with "4" into CEditBox ! for ex: 41,42,411,42222 !!!!!! i have tried this : CString sCod; m_cod.GetWindowText(sCod); if(!sCod.Left(1).Compare("4")) { //something } else { AfxMessageBox("Incorect number"); } but is not working ! please help me !
Bravoone
Nope nothing,nothing is working i don t know what to do ! The first number in the string must be 4 ! this is a serious problem i dont expect to be so hard !
Bravoone
-
Nope nothing,nothing is working i don t know what to do ! The first number in the string must be 4 ! this is a serious problem i dont expect to be so hard !
Bravoone
If you want to let the user only enter the number's that start with 4 you would need to override the EN_CHANGE notification. When the user hits anything except a 4 for the first time just discard the value else continue. I hope I do get you correctly now and this helps you.
Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_
-
Nope nothing,nothing is working i don t know what to do ! The first number in the string must be 4 ! this is a serious problem i dont expect to be so hard !
Bravoone
void CBravooneTest::OnEnChangeEdit1() { CString str; if(((CEdit*)GetDlgItem (IDC_EDIT1))->GetWindowTextLength()>0){ ((CEdit*)GetDlgItem(IDC_EDIT1))->GetWindowText (str); if(str.GetAt(0)!='4') ((CEdit*)GetDlgItem(IDC_EDIT1))->SetWindowText(""); } }
See if this is what you need.
Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_
-
How can alow the user to enter only numbers lets say with "4" into CEditBox ! for ex: 41,42,411,42222 !!!!!! i have tried this : CString sCod; m_cod.GetWindowText(sCod); if(!sCod.Left(1).Compare("4")) { //something } else { AfxMessageBox("Incorect number"); } but is not working ! please help me !
Bravoone
-
Nope nothing,nothing is working i don t know what to do ! The first number in the string must be 4 ! this is a serious problem i dont expect to be so hard !
Bravoone
Hi Bravoone, I have a hardware question do you know about DVD players?
WhiteSky