CString return
-
Sure. But you are calling
GetText()
withindex
and_case
. AndGetText
is checking its paramteres... Did you ever check the value ofindex
?
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 -
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
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 -
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 -
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 -
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 wordsrite 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
-
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
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 -
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 -
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 -
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
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 -
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 -
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
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 -
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 -
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 -
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
-
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 -
-
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
tyagineha wrote:
void CClientdemoDlg::OnClientChangeListbox() { CMyProj objnew; CString _temp; _temp=objnew.OnText(); }
But in your example you show the code for CMyProj::OnTextList(). It seems as you think you are calling CMyProj::OnTextList(), but in your sample you call CMyProj::OnText() Maybe you should look for the problem in CMyProj::OnText() ?
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
-
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
Ok. What and where is your Error? Not just "Debug Assert", but complete details, please. I get from what you have written, that
_case
ist still OK, but after it has been assigned to_temp
it is no longer 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 -
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
So you corrected your code sample without telling anyone? I suggest you do like this: 1. Learn how to use the debugger. (It's not too hard). 2. Put a breakpoint on this line: _temp=objnew.OnTextList(); 3. Single-step your code, line by line and examine what's happening. That's it. And that's exactly what other people do, IMO. For a good reason.
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
-
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
Short answer: You have created an object of type CClinetdemoDlg but you have not created the actual dialog. The call to both GetCurSel and GetText will fail because they required a window to operate on. Long answer: You appear to be creating lots of temporary instances of the dialog and your CMyProj class. The act of creating the instance does NOT associate the just-created instance with the already existing one. In OnSelChangeList, you create a CClientdemoDlg. This is NOT associated with the actual dialog that I assume you created elsewhere. You then call OnClientChangeListbox in an instance not associated with a window. This causes the problem I mentioned earlier. Also, in that function, you create an instance of CMyProj. This instance is NOT the same as the one that called the function. This is important because you then call OnTextList in the just-created instance of CMyProj and in that function reference the member variable m_caselist. This variable is not the same as the one in the original class that started this calling chain. Accessing this variable will not affect the original caller. Judy