Difference between revisions of "Talk:ISDBSongList::Delete"

From MediaMonkey Wiki
Jump to navigation Jump to search
 
Line 2: Line 2:
  
 
If I try to delete a track within a loop, the loop does not get the updated .count and it will go out of bounds..
 
If I try to delete a track within a loop, the loop does not get the updated .count and it will go out of bounds..
 
+
<source lang="vb">
example:
 
 
 
 
For x = 0 to sdbsonglist.count-1
 
For x = 0 to sdbsonglist.count-1
 
  if sdbsonglist.item(x).rating < 50 then
 
  if sdbsonglist.item(x).rating < 50 then
Line 10: Line 8:
 
  end if
 
  end if
 
Next
 
Next
 
+
</source>
 
that is a realistic situation when you are checking a track list for certain criteria (ie rating etc) and you want to remove a track without creating a new secondary songlist object.
 
that is a realistic situation when you are checking a track list for certain criteria (ie rating etc) and you want to remove a track without creating a new secondary songlist object.
 
--[[User:Teknojnky|Teknojnky]] 23:03, 4 February 2008 (EST)
 
--[[User:Teknojnky|Teknojnky]] 23:03, 4 February 2008 (EST)
 +
 +
 +
: The (probably easiest) trick to do that is counting backwards, from SDBSongList.Count - 1 to 0, and with step -1. See the example:
 +
<source lang="vb">
 +
For x = SDBSongList.Count - 1 To 0 Step -1
 +
    If SDBSongList.Item(x).Rating < 50 Then
 +
        SDBSongList.Delete(x)
 +
    End If
 +
Next
 +
</source>
 +
: -- [[User:Steegy|Steegy]] 15:18, 15 April 2008 (EDT)

Latest revision as of 19:18, 15 April 2008

What is the best way to use this method?

If I try to delete a track within a loop, the loop does not get the updated .count and it will go out of bounds..

For x = 0 to sdbsonglist.count-1
 if sdbsonglist.item(x).rating < 50 then
   sdbsonglist.delete(x)
 end if
Next

that is a realistic situation when you are checking a track list for certain criteria (ie rating etc) and you want to remove a track without creating a new secondary songlist object. --Teknojnky 23:03, 4 February 2008 (EST)


The (probably easiest) trick to do that is counting backwards, from SDBSongList.Count - 1 to 0, and with step -1. See the example:
For x = SDBSongList.Count - 1 To 0 Step -1
    If SDBSongList.Item(x).Rating < 50 Then
        SDBSongList.Delete(x)
    End If
Next
-- Steegy 15:18, 15 April 2008 (EDT)