Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Hi All !(CString Class)

Hi All !(CString Class)

Scheduled Pinned Locked Moved C / C++ / MFC
help
15 Posts 8 Posters 4 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Bravoone_2006

    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

    A Offline
    A Offline
    ajitatif angajetor
    wrote on last edited by
    #5

    you can try the _ttoi function to determine if the string is actually an integer. The function will return 0 if the string cannot be parsed as integer. So you should also check if user actually entered 0 in the CEditBox. "What if user enters something like 0000?" question still remains, but this is better than nothing :)

    int val = _ttoi(sCod);
    if (val == 0 && sCod != _T("0"))
    {
       AfxMessageBox(_T("Incorrect number"));
    }
    
    1 Reply Last reply
    0
    • B Bravoone_2006

      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

      G Offline
      G Offline
      garfield185
      wrote on last edited by
      #6

      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

      P B 2 Replies Last reply
      0
      • B Bravoone_2006

        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

        B Offline
        B Offline
        Bravoone_2006
        wrote on last edited by
        #7

        all i want is to enter only numbers that have 4 first number for example 48956687 the first number is 4 !!!!!! Thank you !

        Bravoone

        1 Reply Last reply
        0
        • G garfield185

          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

          P Offline
          P Offline
          prasad_som
          wrote on last edited by
          #8

          garfield185 wrote:

          First of all, I haven´t found a Left member inside the CString class

          Here[^] it is.


          Prasad MS MVP -  VC++

          G 1 Reply Last reply
          0
          • G garfield185

            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

            B Offline
            B Offline
            Bravoone_2006
            wrote on last edited by
            #9

            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

            1 Reply Last reply
            0
            • P prasad_som

              garfield185 wrote:

              First of all, I haven´t found a Left member inside the CString class

              Here[^] it is.


              Prasad MS MVP -  VC++

              G Offline
              G Offline
              garfield185
              wrote on last edited by
              #10

              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:

              1 Reply Last reply
              0
              • B Bravoone_2006

                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

                B Offline
                B Offline
                Bravoone_2006
                wrote on last edited by
                #11

                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

                _ H 3 Replies Last reply
                0
                • B Bravoone_2006

                  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

                  _ Offline
                  _ Offline
                  _AnsHUMAN_
                  wrote on last edited by
                  #12

                  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_

                  1 Reply Last reply
                  0
                  • B Bravoone_2006

                    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

                    _ Offline
                    _ Offline
                    _AnsHUMAN_
                    wrote on last edited by
                    #13
                    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_

                    1 Reply Last reply
                    0
                    • B Bravoone_2006

                      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

                      G Offline
                      G Offline
                      GuyM
                      wrote on last edited by
                      #14

                      the "Compare" function returns 0 (!!!) if the two strings are EQUAL, like strcmp(...)

                      1 Reply Last reply
                      0
                      • B Bravoone_2006

                        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

                        H Offline
                        H Offline
                        Hamid Taebi
                        wrote on last edited by
                        #15

                        Hi Bravoone, I have a hardware question do you know about DVD players?


                        WhiteSky


                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups