I know there is a windows board, but I think the problem is in the non-visual part.
I want to extract user input from edit boxes into an array. The code I have only works if all the boxes are filled. I want it to keep going if the edit box is empty and just not put that value into the vector. Here's what I got:
I get a run time error that memory could not be read. My check for emprty strings maybe wrong or something else.
for(i=0; i<FAD.nExpected; i++)
pGetEdit[i] = (CEdit*) GetDlgItem(i+100);
int len = pGetEdit[i]->LineLength();
if(len > 0)
templink.Index = i;
thanks a lot.
I think this should be in the Windows board.
Obviously you declared i higher up?
From MSDN (CEdit::GetLine): The copied line does not contain a null-termination character.
From MSDN (CString::GetBuffer): If you use the pointer returned by GetBuffer to change the string contents, you must call ReleaseBuffer before using any other CString member functions.
From MSDN (CString::GetBuffer): Note that if you keep track of the string length yourself, you should not append the terminating null character. You must, however, specify the final string length when you release the buffer with ReleaseBuffer. If you do append a terminating null character, you should pass –1 for the length to ReleaseBuffer and ReleaseBuffer will perform a strlen on the buffer to determine its length.
Translation: You need to call ReleaseBuffer with the Length specified (len). As I said last time the problem is not with how you are using the vector, it's with how you are using CEdit and CString.
I've included the ReleaseBuffer line, but there's still a problem. same thing with the if statement. I also tried checking how many characters getLine retrieved, but same thing.
Daved, is there an on-line tutorial that explains all this, or any good VC++ tutorials?
int len = 1;
pGetEdit = (CEdit*) GetDlgItem(i+100);
len = pGetEdit->LineLength();
templink.Index = i;
Not that I know of... I just use MSDN (you can use MSDN online as well, but it's harder to find stuff).
The only other suspicious thing is the cast of the return value of GetDlgItem. Are you sure that the IDs you are passing it are valid IDs and are all edit boxes?
I'd suggest you use your debugger (I assume you're using VC++) to get more information. It is a powerful tool. There should be tutorials for using the VC++ debugger online, I don't know any myself. At the least you should run it through the debugger, and set your exceptions to always stop. If you are using VC++ 6.0, once the program is running, go to Debug->Exceptions..., then select all the exceptions in the box and hit the Stop Always option, then hit OK. This should get the debugger to stop right when the error occurs. If you are using another IDE let us know and somebody might be able to tell you how to do the same thing if you cannot find it yourself.
I tried the exceptions thing, and all I got was an access violation at the line of the if statement. I'm not sure what to do about it.
Try not to dual-post.
I answered your question in the proper thread on the Windows board here.