As a way of getting used to using REALbasic 2006, I decided to make a
To-Do list application. Data for individual to-do list items is stored
in a ToDoListItem class. The ToDoListItems are stored in an array,
pToDoItems. Items are displayed in a listbox. Each to-do item has a
randomly generated itemNumber which is stored in the last column of the
listbox off-screen.
When I want to delete an item, I use the following code in the delete
button Action event:
Sub Action()
.
.
//Display dialog box
.
.
Select Case b //determine which button was pressed.
Case d.ActionButton
pWhichItem = lbToDoList.cell(lbToDoList.ListIndex,5) // get the itemNumber
deleteEntry(pWhichItem) // pass the itemNumber to the delete method
(shown below)
lbToDoList.RemoveRow lbToDoList.ListIndex
Case d.CancelButton
//user pressed Cancel
End select
End Sub
Sub deleteEntry(pItemNumber As string)
dim i,u As Integer
u = UBound(pToDoItems)
for i = u DownTo 0
if pToDoItems(i).pItemNumber = pWhichItem then // pItemNumber = a
property of the ToDoListItem class
pToDoItems.Remove i
fileHasChanged = True
bbTDSave.Enabled = True
Exit
end if
next
End Sub
This works perfectly every time. However, when it comes to deleting
several items, e.g., all items that have been completed, I run into
problems. The code in the ‘delete all completed’ button is shown below:
Sub Action()
dim i,lc As Integer
dim whichID As String
.
.
//display the dialog
.
.
Select Case b //determine which button was pressed.
Case d.ActionButton
lc = lbToDoList.ListCount - 1
for i = lc DownTo 0
if lbToDoList.cell(i,4) = "Completed" then
whichID = lbToDoList.cell(i,5)
deleteEntry(whichID) // pass the itemNumber to the delete method
lbToDoList.RemoveRow i
end if
next
Case d.CancelButton
//user pressed Cancel
End select
End Sub
This time, when I call the delete method from the loop, it does not find
the items at all and nothing is deleted from the array. I have watched
the progress of the method in the debugger, both for a single delete and
a multiple delete, and it seems fine both times. But, it just doesn’t
work with multiple deletes.
I would appreciate any comments and/or help anyone can give me.
TIA
Darryl McGrath
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>