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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

assertion failed in a programm

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
HI,
In one function of my programm, I open a dialog box with 2 lists and 2 buttons.
in the first list, I have the title of the differents opened windows in my programm (MDI application).
When I click on the first button, I would like that the selected item in my first list was transfered in my second list (in this function, the user make a choice of differents files he needs).

I have made this code for the button function

void CMulxDlg::OnEinfugen()
{
for (int i = 0 ; i < m_listBox.GetCount(); i++ )
{
if ((m_listBox.GetSel(i)) != 0)
{
m_listBox2.AddString(aStrings);
m_listBox.DeleteString(i);
aStrings.RemoveAt( i, 1 );
}
}

}

m_listBox : first listbox
m_listBox2 : second listbox
aStrings : a CStringArray with the title of opened windows

When I select all files, I have an assertion failed.
I don't know why
Someone can help me ?
Thanks!
 
I don't where your assertion error is from. But I do find there is logical error in your code. Whenever you delete an item in the listbox, the index of the remaining items is changed so that after one loop, there will be still some items left.

a new sample code is for your reference:
int i = 0;
while(i < m_listbox.GetCount()){
if (m_listBox.GetSel(i) != 0){
m_listBox.DeleteString(i);
}else i++;
}

by the way, you can debug your code to see where the error is from.


 
Thanks Jeffray
With your code, it works.
It's a little difficult for me to make the distinction between your code and my code, but with your code it works
It's the important things.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top