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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CString return

CString return

Scheduled Pinned Locked Moved C / C++ / MFC
databasehelpquestion
28 Posts 6 Posters 0 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.
  • T tyagineha

    i m using following function in my project but gtng an exception error: CString CMyProj::OnTextList() { int index; CString _case; index = m_caselist.GetCurSel(); m_caselist.GetText(index,_case); return _case; } can any body tell me why i m getting error in this code????????? NT

    K Offline
    K Offline
    karle
    wrote on last edited by
    #2

    may check if the index is >= 0 If no item is selected the index has a value of -1. Check LastError code using GetLastError() Otherwise please post the error message / exception.

    T 1 Reply Last reply
    0
    • K karle

      may check if the index is >= 0 If no item is selected the index has a value of -1. Check LastError code using GetLastError() Otherwise please post the error message / exception.

      T Offline
      T Offline
      tyagineha
      wrote on last edited by
      #3

      exception error i m geeting is "Debug Assertion Error". NT

      J D 2 Replies Last reply
      0
      • T tyagineha

        exception error i m geeting is "Debug Assertion Error". NT

        J Offline
        J Offline
        jhwurmbach
        wrote on last edited by
        #4

        GetText is checking its input data. What are you inputting to it? Use the debugger to set a breakpoint and check the value.


        Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
        George Orwell, "Keep the Aspidistra Flying", Opening words

        T 1 Reply Last reply
        0
        • J jhwurmbach

          GetText is checking its input data. What are you inputting to it? Use the debugger to set a breakpoint and check the value.


          Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
          George Orwell, "Keep the Aspidistra Flying", Opening words

          T Offline
          T Offline
          tyagineha
          wrote on last edited by
          #5

          I dont want return value of GetText() function i want return value of _case variable NT

          J 1 Reply Last reply
          0
          • T tyagineha

            I dont want return value of GetText() function i want return value of _case variable NT

            J Offline
            J Offline
            jhwurmbach
            wrote on last edited by
            #6

            Sure. But you are calling GetText() with index and _case. And GetText is checking its paramteres... Did you ever check the value of index?


            Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
            George Orwell, "Keep the Aspidistra Flying", Opening words

            T 1 Reply Last reply
            0
            • J jhwurmbach

              Sure. But you are calling GetText() with index and _case. And GetText is checking its paramteres... Did you ever check the value of index?


              Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
              George Orwell, "Keep the Aspidistra Flying", Opening words

              T Offline
              T Offline
              tyagineha
              wrote on last edited by
              #7

              But i think the function of GetText() is that watever text is at index(watevr value) will be stored in _case. just tell the way i m returning the value of _case is correct or not???? NT

              J 1 Reply Last reply
              0
              • T tyagineha

                But i think the function of GetText() is that watever text is at index(watevr value) will be stored in _case. just tell the way i m returning the value of _case is correct or not???? NT

                J Offline
                J Offline
                jhwurmbach
                wrote on last edited by
                #8

                tyagineha wrote:

                But i think the function of GetText() is that watever text is at index(watevr value) will be stored in _case.

                You could have read MSDN about GetText(). The index is zerobased. Hence my repeated question (which you seem to refuse to answer): What are you calling GetText() with? Are you calling it with invalid indices (like, perchance, -1)?


                Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
                George Orwell, "Keep the Aspidistra Flying", Opening words

                T 1 Reply Last reply
                0
                • J jhwurmbach

                  tyagineha wrote:

                  But i think the function of GetText() is that watever text is at index(watevr value) will be stored in _case.

                  You could have read MSDN about GetText(). The index is zerobased. Hence my repeated question (which you seem to refuse to answer): What are you calling GetText() with? Are you calling it with invalid indices (like, perchance, -1)?


                  Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
                  George Orwell, "Keep the Aspidistra Flying", Opening words

                  T Offline
                  T Offline
                  tyagineha
                  wrote on last edited by
                  #9

                  ok i m sorry 4 that.... i m inputting a ListBox value.......... NT

                  J 1 Reply Last reply
                  0
                  • T tyagineha

                    ok i m sorry 4 that.... i m inputting a ListBox value.......... NT

                    J Offline
                    J Offline
                    jhwurmbach
                    wrote on last edited by
                    #10

                    And your Listbox does have 5 entries? Or does it have 4, and the last one is selected? Then you have falling in the ole off-by-one trap. ;P Indices are counting from 0: the last element of the Listbox has the index (SizeOfListbox -1)


                    Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
                    George Orwell, "Keep the Aspidistra Flying", Opening words

                    T 1 Reply Last reply
                    0
                    • J jhwurmbach

                      And your Listbox does have 5 entries? Or does it have 4, and the last one is selected? Then you have falling in the ole off-by-one trap. ;P Indices are counting from 0: the last element of the Listbox has the index (SizeOfListbox -1)


                      Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
                      George Orwell, "Keep the Aspidistra Flying", Opening words

                      T Offline
                      T Offline
                      tyagineha
                      wrote on last edited by
                      #11

                      rite now listbox has only one entry. this function i m defining in one class and calling in another class... the problem which u r saying.. that problem i m nt gntng when i m in same class but when calling this function fron another class then error is cuming. tell me watshld i do now?? Nt

                      J 2 Replies Last reply
                      0
                      • T tyagineha

                        rite now listbox has only one entry. this function i m defining in one class and calling in another class... the problem which u r saying.. that problem i m nt gntng when i m in same class but when calling this function fron another class then error is cuming. tell me watshld i do now?? Nt

                        J Offline
                        J Offline
                        jhwurmbach
                        wrote on last edited by
                        #12

                        tyagineha wrote:

                        tell me watshld i do now??

                        Write proper English. I am not a native speaker and may get your abbreviations wrong. Also, this stuff is complicated enough.


                        Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
                        George Orwell, "Keep the Aspidistra Flying", Opening words

                        T 1 Reply Last reply
                        0
                        • J jhwurmbach

                          tyagineha wrote:

                          tell me watshld i do now??

                          Write proper English. I am not a native speaker and may get your abbreviations wrong. Also, this stuff is complicated enough.


                          Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
                          George Orwell, "Keep the Aspidistra Flying", Opening words

                          T Offline
                          T Offline
                          tyagineha
                          wrote on last edited by
                          #13

                          Tell me what should i do now???? NT

                          J 1 Reply Last reply
                          0
                          • T tyagineha

                            Tell me what should i do now???? NT

                            J Offline
                            J Offline
                            jhwurmbach
                            wrote on last edited by
                            #14

                            Set a breakpoint on return _case; and see if it looks OK in the debugger. If it does, single step into your other class and look if it is still OK.


                            Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
                            George Orwell, "Keep the Aspidistra Flying", Opening words

                            T 1 Reply Last reply
                            0
                            • T tyagineha

                              rite now listbox has only one entry. this function i m defining in one class and calling in another class... the problem which u r saying.. that problem i m nt gntng when i m in same class but when calling this function fron another class then error is cuming. tell me watshld i do now?? Nt

                              J Offline
                              J Offline
                              jhwurmbach
                              wrote on last edited by
                              #15

                              tyagineha wrote:

                              rite now listbox has only one entry.

                              But you are calling for the 4th one? Could this work?


                              Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
                              George Orwell, "Keep the Aspidistra Flying", Opening words

                              T 1 Reply Last reply
                              0
                              • J jhwurmbach

                                Set a breakpoint on return _case; and see if it looks OK in the debugger. If it does, single step into your other class and look if it is still OK.


                                Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
                                George Orwell, "Keep the Aspidistra Flying", Opening words

                                T Offline
                                T Offline
                                tyagineha
                                wrote on last edited by
                                #16

                                its not ok in debugger... its giving debug error. i just want to return the value which is in _case. i want to use this value furthur. NT

                                J 1 Reply Last reply
                                0
                                • T tyagineha

                                  its not ok in debugger... its giving debug error. i just want to return the value which is in _case. i want to use this value furthur. NT

                                  J Offline
                                  J Offline
                                  jhwurmbach
                                  wrote on last edited by
                                  #17

                                  tyagineha wrote:

                                  i just want to return the value which is in _case.

                                  So the CString _case is ok at the end of your function (as listed above). And it is not OK in the function calling that?


                                  Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
                                  George Orwell, "Keep the Aspidistra Flying", Opening words

                                  1 Reply Last reply
                                  0
                                  • J jhwurmbach

                                    tyagineha wrote:

                                    rite now listbox has only one entry.

                                    But you are calling for the 4th one? Could this work?


                                    Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
                                    George Orwell, "Keep the Aspidistra Flying", Opening words

                                    T Offline
                                    T Offline
                                    tyagineha
                                    wrote on last edited by
                                    #18

                                    sorry i m not getting you. Nt

                                    J T 2 Replies Last reply
                                    0
                                    • T tyagineha

                                      sorry i m not getting you. Nt

                                      J Offline
                                      J Offline
                                      jhwurmbach
                                      wrote on last edited by
                                      #19

                                      You said: "The index is 4" and "rite now listbox has only one entry." Are you calling CListBox::GetText( 4, _case) in a CListBox that has only 1 entry?


                                      Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
                                      George Orwell, "Keep the Aspidistra Flying", Opening words

                                      T 1 Reply Last reply
                                      0
                                      • T tyagineha

                                        sorry i m not getting you. Nt

                                        T Offline
                                        T Offline
                                        tyagineha
                                        wrote on last edited by
                                        #20

                                        Okey let me explain in detail. void CMyProj::OnSelchangeList() { CClientdemoDlg dlgobj; dlgobj.OnClientChangeListbox(); } void CClientdemoDlg::OnClientChangeListbox() { CMyProj objnew; CString _temp; _temp=objnew.OnTextList(); } CString CMyProj::OnTextList() { int index; CString _case; index = m_caselist.GetCurSel(); m_caselist.GetText(index,_case); return _case; } notice the classes....... NT -- modified at 5:54 Thursday 16th August, 2007 NT

                                        K J J 4 Replies Last reply
                                        0
                                        • J jhwurmbach

                                          You said: "The index is 4" and "rite now listbox has only one entry." Are you calling CListBox::GetText( 4, _case) in a CListBox that has only 1 entry?


                                          Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
                                          George Orwell, "Keep the Aspidistra Flying", Opening words

                                          T Offline
                                          T Offline
                                          tyagineha
                                          wrote on last edited by
                                          #21

                                          hey i didnt said 4.... i said only that my listbox has only 1 entry.. NT

                                          J 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