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).
With the other button, the user can cancel his choice ( the selected item in the second list
is transfered in the first list)

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

I have made this code with Jeffray's help for the first button function

void CMulxDlg::OnEinfugen()
{
int i = 0;
int j = 0;
while(i < m_listBox.GetCount())
{
if (m_listBox.GetSel(i) != 0)
{
j = i;
m_listBox2.AddString(aStrings);
m_listBox.DeleteString(i);
aStrings.RemoveAt( i, 1 );
i++;
}
else
i++;
}
aStrings2.Add(aStrings[j]); /* assertion failed cause of this line */
}

and this code for the second button function

void CMulxDlg::OnEntfernen()
{
int i = 0;
while(i < m_listBox2.GetCount())
{
if (m_listBox2.GetSel(i) != 0)
{
m_listBox.AddString(aStrings2);
m_listBox2.DeleteString(i);
aStrings2.RemoveAt( i, 1 );
i++;
}
else
i++;
}
}


When I select three files, I have an assertion failed.
I don't know why
I changeg my code but I have often assertion failed
Maybe my CStringArray aren't good initialized
Someone can help me ?
Thanks!
 
In your while statement you are doing a GetCount() this is going to change every time round the loop, since you are deleting the items the count will go down by one when you remove an item.

The same is going to apply when you cancel.

You might want to consider using a doubleclick to move the items from list to list. It's a lot easier to control.

HTH
William
Software Engineer
ICQ No. 56047340
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top