Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting contents of an edit box into an array

Status
Not open for further replies.

NoClue30

Programmer
Jul 14, 2005
1
0
0
CA
Hey,

I've just started with VC++ and I'm trying to make a GUI to let the user enter a nist of items into a bunch of edit boxes, then take the entries and store them in an array. I've read the MSDN for the functions and that's what I came up with:
Code:
        structLink templink;

	CEdit* pGetEdit[512];
	
	for(i=0; i<FAD.nExpected; i++)
	{
		
		pGetEdit[i] = (CEdit*) GetDlgItem(i+100);

		int len = pGetEdit[i]->LineLength();

		if(len > 0)
		{
			pGetEdit[i]->GetLine(1,templink.ParamName.GetBuffer(len), len);
			templink.Index = i;
			vars.vectParmSelected.push_back(templink);
		}

	}
It works fine if all the edit boxes are filled, but if one is left empty I get a run-time errorr saying that the memory could not be read. I jsut want it to skip that box and go on to the next one. What am I missing?

Thanks
 
1. Is it MFC? Is this snippet a part of View member function?
2. If so, why i loops from 0 to X? Is it true control ids?
3. GetDlgItem() returns CWnd*, not CEdit* pointer. Why you don't use GetWindowText() member (of CWnd) to get text box contents (in CString, for example)?
4. It seems no control for null pointers after GetDlgItem().
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top