Getting the contents of edit boxes into an array

This is a discussion on Getting the contents of edit boxes into an array within the Windows Programming forums, part of the Platform Specific Boards category; Hello, I'm trying to get the contents of dynamically created edit boxes into a vector of CStrings. It copies most ...

  1. #1
    Registered User
    Join Date
    May 2005
    Location
    Toronto, Canada
    Posts
    257

    Getting the contents of edit boxes into an array

    Hello,

    I'm trying to get the contents of dynamically created edit boxes into a vector of CStrings. It copies most of the entries, but leaves some of them out. I don't kow why.
    here's the retreaval code:
    Code:
    //////////////////////////////////////////////////////////////////////
    // COPY ALL THE SELECTED PARAMETERS FROM EDIT BOXES TO GLOBAL ARRAY //
    //                                                                  //
    //////////////////////////////////////////////////////////////////////
    
    	CString str;
    
    	CEdit* pGetEdit[512];
    	
    	for(i=0; i<FAD.nExpected; i++)
    	{
    		
    		pGetEdit[i] = (CEdit*) GetDlgItem(i);
    
    		int len = pGetEdit[i]->LineLength();
    		
    		pGetEdit[i]->GetLine(1,str.GetBuffer(len), len);
    
    		vars.vectParmSelected.push_back(str);
    
    	}
    
    	for(i=0; i<FAD.nExpected; i++)
    	{
    		fprintf(out, ">%s<\n", vars.vectParmSelected[i]);
    	}
    fprintfs are just to check the output, the vector will be used for something else. GetDlgItem (i) => the i referes to the ID of the edit boxes, they are created like this:
    Code:
    	CEdit *txtbox[512];
    
    	int x1=350, y=50, x2=450, h=20;
    
    	for (int i = 0; i < FAD.nExpected; i++) 
    	{
    		txtbox[i] = new CEdit();
    		txtbox[i]->Create(WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER, CRect(x1,y,x2,y+h), this, i);
    		y += 22;
    	}

    I'm not even sure if I'm doing it right, I'm pretty sure I'm not.

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Make sure each ID for the edit control is unique.

    Kuphryn

  3. #3
    Registered User
    Join Date
    May 2005
    Location
    Toronto, Canada
    Posts
    257
    Make sure each ID for the edit control is unique.
    Yep, it is. They are created in the loop, take on values of int from 0 to the Loop control variable (Usually 10 in the files I work with).

    Here's th eoutput with missing strings:
    Code:
    >BARO    <
    ><
    ><
    >SG      <
    >S9710L.D<
    >MOPDELTA<
    Last edited by earth_angel; 07-05-2005 at 12:10 PM.

  4. #4
    Work in Progress..... Jaken Veina's Avatar
    Join Date
    Mar 2005
    Location
    Missouri. Go Imos Pizza!
    Posts
    256
    Well, since you start from 0, you'll also need to make sure that none of the IDs are identical to other controls held by that window.
    Code:
    void function(void)
     {
      function();
     }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inserting contents of string into an array
    By Gaming in forum C++ Programming
    Replies: 4
    Last Post: 04-13-2008, 11:31 AM
  2. Merge sort please
    By vasanth in forum C Programming
    Replies: 2
    Last Post: 11-09-2003, 12:09 PM
  3. Copying Texts from Edit Boxes.
    By incognito in forum Windows Programming
    Replies: 1
    Last Post: 04-22-2003, 09:37 PM
  4. Replies: 1
    Last Post: 07-24-2002, 07:33 AM
  5. Password Edit Boxes
    By Unregistered in forum Windows Programming
    Replies: 1
    Last Post: 08-27-2001, 03:40 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21