Results 1 to 4 of 4

Thread: Error when removing items from playlist

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2005
    Location
    Chicago
    Posts
    202

    Error when removing items from playlist

    The code below works fine if you are deleting something other than lowest item on the listbox. If you do, then you get an error saying "Specified argument was out of the range of valid values. Parameter name: '1' is not a valid value for 'value'."

    VB Code:
    1. On Error GoTo TheError
    2.         Dim index As Integer
    3.         If playlist.Items.Count < 1 Then
    4.             MsgBox("A track must be in the playlist in order to use the remove function!", MsgBoxStyle.Exclamation, "Error")
    5.         Else
    6.             playlistPath.SelectedIndex = playlist.SelectedIndex
    7.             If MP3.MP3Playing = False Then
    8.                 index = playlistPath.SelectedIndex
    9.                 If playlistPath.SelectedItem = MP3.MP3File Then
    10.                     MP3.MP3Stop()
    11.                     tmrTrack.Enabled = False
    12.                     lblPaused.Visible = False
    13.                     Me.startTime = Date.Now
    14.                     Me.tmrTrack.Stop()
    15.                     etime.Text = "-:--"
    16.                     rtime.Text = "-:--"
    17.                     ttime.Text = "-:--"
    18.                     WP.Text = ""
    19.                     trkSeek.Value = 0
    20.                     playlistPath.Items.Remove(playlistPath.SelectedItem)
    21.                     playlist.Items.Remove(playlist.SelectedItem)
    22.                     lblPaused.Visible = False
    23.                     btnPause.Enabled = False
    24.                     mnuPause.Enabled = False
    25.                     btnPause.Enabled = False
    26.                     mnuPause.Enabled = False
    27.                     btnPause.Visible = True
    28.                     mnuPause.Visible = True
    29.                     btnResume.Enabled = False
    30.                     mnuResume.Enabled = False
    31.                     btnResume.Visible = False
    32.                     mnuResume.Visible = False
    33.                     btnStop.Enabled = False
    34.                     mnuStop.Enabled = False
    35.                     playlist.SelectedIndex = index
    36.                     playlist.Update()
    37.                     playlistPath.Update()
    38.                 ElseIf playlistPath.SelectedItem <> MP3.MP3File Then
    39.                     index = playlistPath.SelectedIndex
    40.                     playlistPath.SelectedIndex = playlist.SelectedIndex
    41.                     playlistPath.Items.Remove(playlistPath.SelectedItem)
    42.                     playlist.Items.Remove(playlist.SelectedItem)
    43.                     playlist.SelectedIndex = index
    44.                     playlist.Update()
    45.                     playlistPath.Update()
    46.                 End If
    47.             Else
    48.                 index = playlistPath.SelectedIndex
    49.                 playlistPath.SelectedItem = playlist.SelectedItem
    50.                 playlistPath.Items.Remove(playlistPath.SelectedItem)
    51.                 playlist.Items.Remove(playlist.SelectedItem)
    52.                 playlist.Update()
    53.                 playlistPath.Update()
    54.                 playlist.SelectedIndex = index
    55.             End If
    56.         End If
    57.         Exit Sub
    58. TheError: MsgBox(Err.Description, , " Error")
    A programmer is a person who fixes a problem you did not know you had in a way that you cannot understand.

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: Error when removing items from playlist

    Ouch, old style error handling.

    Which line throws the error?

    I've would guess it is one of the playlist.SelectedIndex=index ones.
    After all, just before those you call Remove. Once that has been called, that statement may not work quite as you'd like.
    My usual boring signature: Nothing

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Error when removing items from playlist

    I agree with Shaggy that you should try to learn to use structured exception handling ASAP. With reagrds to your error, I'm quite sure that if you set a breakpoint and Watch your variables, specifically index and playList.Items.Count, you'll find the problem pretty quickly.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jul 2005
    Location
    Chicago
    Posts
    202

    Re: Error when removing items from playlist

    Fixed it:

    VB Code:
    1. On Error GoTo TheError
    2.         Dim index As Integer
    3.  
    4.         If playlist.Items.Count < 1 Then
    5.             MsgBox("A track must be in the playlist in order to use the remove function!", MsgBoxStyle.Exclamation, "Error")
    6.         Else
    7.             playlistPath.SelectedIndex = playlist.SelectedIndex
    8.             If MP3.MP3Playing = False Then
    9.                 index = playlistPath.SelectedIndex
    10.                 If playlistPath.SelectedItem = MP3.MP3File Then
    11.  
    12.                     MP3.MP3Stop()
    13.                     tmrTrack.Enabled = False
    14.                     lblPaused.Visible = False
    15.                     Me.startTime = Date.Now
    16.                     Me.tmrTrack.Stop()
    17.                     etime.Text = "-:--"
    18.                     rtime.Text = "-:--"
    19.                     ttime.Text = "-:--"
    20.                     WP.Text = ""
    21.                     trkSeek.Value = 0
    22.                     playlistPath.Items.Remove(playlistPath.SelectedItem)
    23.                     playlist.Items.Remove(playlist.SelectedItem)
    24.                     lblPaused.Visible = False
    25.                     btnPause.Enabled = False
    26.                     mnuPause.Enabled = False
    27.                     btnPause.Enabled = False
    28.                     mnuPause.Enabled = False
    29.                     btnPause.Visible = True
    30.                     mnuPause.Visible = True
    31.                     btnResume.Enabled = False
    32.                     mnuResume.Enabled = False
    33.                     btnResume.Visible = False
    34.                     mnuResume.Visible = False
    35.                     btnStop.Enabled = False
    36.                     mnuStop.Enabled = False
    37.                     If index < playlist.Items.Count Then
    38.                         playlist.SelectedIndex = index
    39.                     ElseIf playlist.SelectedIndex = playlist.Items.Count Then
    40.                         playlist.SelectedIndex = index - 1
    41.                     End If
    42.                     playlist.Update()
    43.                     playlistPath.Update()
    44.                 ElseIf playlistPath.SelectedItem <> MP3.MP3File Then
    45.                     playlistPath.SelectedIndex = index
    46.                     playlistPath.SelectedIndex = playlist.SelectedIndex
    47.                     playlistPath.Items.Remove(playlistPath.SelectedItem)
    48.                     playlist.Items.Remove(playlist.SelectedItem)
    49.                     If index < playlist.Items.Count Then
    50.                         playlist.SelectedIndex = index
    51.                     ElseIf index = playlist.Items.Count Then
    52.                         playlist.SelectedIndex = index - 1
    53.                     End If
    54.                     playlist.Update()
    55.                     playlistPath.Update()
    56.                 End If
    57.             Else
    58.                 index = playlistPath.SelectedIndex
    59.                 playlistPath.SelectedItem = playlist.SelectedItem
    60.                 playlistPath.Items.Remove(playlistPath.SelectedItem)
    61.                 playlist.Items.Remove(playlist.SelectedItem)
    62.                 playlist.Update()
    63.                 playlistPath.Update()
    64.                 playlist.SelectedIndex = index
    65.             End If
    66.         End If
    67.         Exit Sub
    68. TheError: MsgBox(Err.Description, , " Error")
    A programmer is a person who fixes a problem you did not know you had in a way that you cannot understand.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width