Skip navigation

Saving A Playlist. [updated!, some mistake’s cause of the

wordpress page editor]

Skill Acquired = 5 of 10.

Intro:

This tutorial shows you how to open and save a playlist (Listbox) using 2 Listboxes. For this tutorial i’ll make a Media Player. Using 1 listbox to Show the Songname only and storing the Full path of the song in listbox2.

[Please notice that Listbox1 will be visible, Listbox2 NOT]

So First i have to add the windows media player control in the toolbar, drag it into your project. Change the name to: “WinPlayer1”. Add some personal prefrences and we are ready to code.
The WinPlayer1’s Volume is 50 so i want 100 do this by adding this code:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Winplayer1.settings.Volume = 100
End Sub

Now add the Add button, Code:

Private Sub Button1_Click() Handles Button1.Click
Dim Openfile As New OpenFileDialog
Dim SafeName As String
With OpenFile
.Filter = “Mp3 Files |*.mp3” .FileName = Nothing
End With
OpenFile.ShowDialog SafeName = OpenFile.SafreFileName.replace(“.mp3”,“”)
Listbox1.items.add(OpenFile.SafeName)
Listbox2.items.add(OpenFile.Filename)
End Sub

Now the Remove Button:

Private Sub Button2_Click() Handles Button2.Click
Dim Selected As Integer
Selected = Listbox1.items.SelectedIndex Listbox1.items.removeAt(Selected) Listbox2.items.removeAt(Selected)
End Sub

Now the Save Playlist Button:

Private Sub Button3_Click() Handles Button3.Click
Dim SaveFile As New SaveFileDialog()
With SaveFile
.Filter = “MyPlayer Playlist Files |*.MyPlay” .FileName = Nothing
End With
SaveFile.ShowDialog()
Dim WriteFile As New System.IO.StreamWriter(SaveFile.FileName)
Dim Count as Integer = Listbox1.items.count – val(1)
For i as Integer = 0 to Count
WriteFile.Write(Listbox1.Items.Item(i) & “;”) ‘the “;” is used to separate the items
WriteFile.Write(Listbox2.Items.Item(i) & “;”)
Next
WriteFile.Close()
End Sub

Now to Open Playlist Button: (This is a little bit harder, because we have to separate the items and put them in the right place)

Private Sub Button4_Click() Handles Button4.Click
Dim OpenFile As New OpenFileDialog
With OpenFile
.Filter = “MyPlayer Playlist Files |*.MyPlay” .FileName = Nothing
End With
Dim ReadFile As New System.IO.StreamReader(OpenFile.FileName)
Dim Playlist As String = ReadFile.ReadToEnd
Dim SplittedFase() = Playlist.Split(“;”)
Dim Count As Integer = SplittedFase.Count – val(1)
Dim i As Integer = 0
Do Untill i = Count
Listbox1.items.add(SplittedFase(i))
i += val(1)
Listbox2.items.add(SplittedFase(i))
i += val(1)
Loop ReadFile.Close
End Sub

Now the Listbox Double Click Event, This example will only show a Message, But this is the way how to bound those listboxes together:

Private Sub Listbox1_DoubleClick() Handles Listbox1.DoubleClick
Dim SelectedItem As Integer = Listbox1.SelectedIndex()
Msgbox(Listbox2.Items.Item(SelectedItem),MsgBoxStyle.Information, “Made By Jnbjabnk”)
End Sub

That was it for this one, Please Message me at Jnbjabnk@Gmail.com for any bugs/Errors. Also Visit My Channel for Video Tutorial About Programming (With Voice :D). Thanks!

Advertisements

20 Comments

    • nothingworks
    • Posted 11 January, 2009 at 6:01 pm
    • Permalink

    dude NOTHING working on this tut, all of it comes errors…

  1. When in Vista, run as admin, else you’ll get errors, this has been tested and debugged so it works

    • no, nothing works
    • Posted 1 February, 2009 at 6:55 pm
    • Permalink

    No i have tried it before, it doesn’t work as all…

    • Vicente
    • Posted 9 March, 2009 at 3:40 am
    • Permalink

    hi, i was wondering if you know how can i add all the files that are in a directory, including the files that are in subdirectories to the listbox.. if you know can you send the code in my email?
    thanks in advance

  2. Hey,,, why u only made 1 tut?? heh

    • Liam
    • Posted 16 May, 2009 at 12:43 pm
    • Permalink

    I managed to fix the errors, but when I debug, it works well except the Save Playlist code.

    I uploaded the code I fixed as a text file here:http://www.mediafire.com/?0om10ljykmm

    WordPress screwed the position of the codes. That’s why I uploaded it as a Text File.

    • TYDIRocks
    • Posted 24 May, 2009 at 2:44 am
    • Permalink

    Dude nothing in this tutorial works… Plz fix your code bc it does not work

    • Alex Bouma
    • Posted 30 July, 2009 at 8:30 pm
    • Permalink

    Can u help me ?
    I get loads of errors
    Add my msn : alexbouma12@hotmail.com

    • Jnbjabnk
    • Posted 30 July, 2009 at 10:44 pm
    • Permalink

    Check my youtube channel (http://youtube.com/jnbjabnk ) for a full video tutorial, even showing it working…

    • Alex Bouma
    • Posted 31 July, 2009 at 5:58 pm
    • Permalink

    I know but that are the old codes.
    this line is not working for me :
    OpenFile.ShowDialog SafeName = OpenFile.SafreFileName.replace(“.mp3″,“”)

    • Andrecito77
    • Posted 16 August, 2009 at 5:05 am
    • Permalink

    This worked PERFECTLY!!! It may not work for some people because of the color of the words!
    Some words disappear because they turned black!
    Here is the code again just in case:

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Winplayer1.settings.Volume = 100
    End Sub

    ‘Now add the Add button, Code:

    Private Sub Button1_Click() Handles Button1.Click
    Dim Openfile As New OpenFileDialog
    Dim SafeName As String
    With OpenFile
    .Filter = “Mp3 Files |*.mp3″ .FileName = Nothing
    End With
    OpenFile.ShowDialog SafeName = OpenFile.SafreFileName.replace(“.mp3″,“”)
    Listbox1.items.add(OpenFile.SafeName)
    Listbox2.items.add(OpenFile.Filename)
    End Sub

    ‘Now the Remove Button:

    Private Sub Button2_Click() Handles Button2.Click
    Dim Selected As Integer
    Selected = Listbox1.items.SelectedIndex Listbox1.items.removeAt(Selected) Listbox2.items.removeAt(Selected)
    End Sub
    Now the Save Playlist Button:

    Private Sub Button3_Click() Handles Button3.Click
    Dim SaveFile As New SaveFileDialog()
    With SaveFile
    .Filter = “MyPlayer Playlist Files |*.MyPlay” .FileName = Nothing
    End With
    SaveFile.ShowDialog()
    Dim WriteFile As New System.IO.StreamWriter(SaveFile.FileName)
    Dim Count as Integer = Listbox1.items.count – val(1)
    For i as Integer = 0 to Count
    WriteFile.Write(Listbox1.Items.Item(i) & “;”) ‘the “;” is used to separate the items
    WriteFile.Write(Listbox2.Items.Item(i) & “;”)
    Next
    WriteFile.Close()
    End Sub
    Now to Open Playlist Button: (This is a little bit harder, because we have to separate the items and put them in the right place)

    Private Sub Button4_Click() Handles Button4.Click
    Dim OpenFile As New OpenFileDialog
    With OpenFile
    .Filter = “MyPlayer Playlist Files |*.MyPlay” .FileName = Nothing
    End With
    Dim ReadFile As New System.IO.StreamReader(OpenFile.FileName)
    Dim Playlist As String = ReadFile.ReadToEnd
    Dim SplittedFase() = Playlist.Split(“;”)
    Dim Count As Integer = SplittedFase.Count – val(1)
    Dim i As Integer = 0
    Do Untill i = Count
    Listbox1.items.add(SplittedFase(i))
    i += val(1)
    Listbox2.items.add(SplittedFase(i))
    i += val(1)
    Loop ReadFile.Close
    End Sub
    Now the Listbox Double Click Event, This example will only show a Message, But this is the way how to bound those listboxes together:

    Private Sub Listbox1_DoubleClick()Handles_Listbox1.DoubleClick
    Dim SelectedItem As Integer = Listbox1.SelectedIndex()
    Msgbox(Listbox2.Items.Item(SelectedItem),MsgBoxStyle.Information, “Made By Jnbjabnk”)
    End Sub

    There you go! If you are reading this tutorial you probably know that you need to make some code into 1 line! I hope so!

    • Jahoovi
    • Posted 12 September, 2009 at 4:09 am
    • Permalink

    notice how all the people who try to make this only copy and paste and complain? Learn to code b4 you complain about other peoples code! Fuck Off

  3. Epic Fail Guys A new Forum is coming !!

    http://www.overdose.gr for Hacks programs and more Visual BAsic generally

  4. Epic Fail Guys A new Forum is coming !!

    http://www.overdose.gr for Hacks programs and more Visual BAsic generally !

    • Darren
    • Posted 14 February, 2010 at 12:21 am
    • Permalink

    dude this is good except for these errors with count in the save and open playlist and loop.readfile.close

    thanks 😉

    • Tonito1
    • Posted 20 March, 2010 at 3:55 pm
    • Permalink

    Gratz Man! Nice
    Work for me!
    Thanks For Help!;)
    Keep going!

    • naske
    • Posted 6 November, 2010 at 2:41 pm
    • Permalink

    Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
    Dim OpenFile As New OpenFileDialog
    OpenFile.Filter = “Awesomelist |*.awe”

    OpenFile.FileName = (“”)
    OpenFile.ShowDialog()
    End With
    Dim ReadFile As New System.IO.StreamReader(OpenFile.FileName)

    Dim Playlist As String = ReadFile.ReadToEnd
    Dim SplittedFase() = Playlist.Split(“;”)
    Dim Count As Integer = SplittedFase.Count – Val(1)
    Dim i As Integer = 0

    Do Until (i = Count)
    ListBox1.Items.Add(SplittedFase(i))
    i += Val(1)
    ListBox2.Items.Add(SplittedFase(i))
    i += Val(1)
    Loop
    ReadFile.Close()

    End Sub

    This should do the trick

    • rui ferreira
    • Posted 22 February, 2016 at 12:09 pm
    • Permalink

    hello man can you help me ?

    when i write your code appears those errors :
    Error 1 ‘FileName’ is not a member of ‘String’. C:\Users\aluno\Desktop\FINAL MESMO\Form2.vb 50 23 WindowsApplication1

    Error 2 ‘Loop’ cannot have a condition if matching ‘Do’ has one. C:\Users\aluno\Desktop\FINAL MESMO\Form2.vb 62 13 WindowsApplication1

    do you know why those errors appears ? pls help me man you my only chance

    • Notrek
    • Posted 8 August, 2016 at 9:15 pm
    • Permalink

    //This one is for Save

    Private Sub PictureBox4_Click(sender As Object, e As EventArgs) Handles PictureBox4.Click
    Dim SaveFile As New SaveFileDialog()
    With SaveFile.Filter = “MyPlaylist File |*.MPF”
    End With
    SaveFile.ShowDialog()
    Dim WriteFile As New System.IO.StreamWriter(SaveFile.FileName)
    Dim Count As Integer = ListBox1.Items.Count – Val(1)
    For i As Integer = 0 To Count
    WriteFile.Write(ListBox1.Items.Item(i) & “;”) ‘the “;” is used to separate the items

    Next
    WriteFile.Close()
    End Sub

    //And this one is for Load Playlist

    Private Sub PictureBox5_Click(sender As Object, e As EventArgs) Handles PictureBox5.Click
    Dim OpenFile As New OpenFileDialog()
    With OpenFile.Filter = “MyPlaylist File |*.MPF”
    End With
    OpenFile.ShowDialog()
    Dim ReadFile As New System.IO.StreamReader(OpenFile.FileName)
    Dim Playlist As String = ReadFile.ReadToEnd
    Dim SplittedFase() = Playlist.Split(“;”)
    Dim Count As Integer = SplittedFase.Count – Val(1)
    Dim i As Integer = 0
    Do Until i = Count
    ListBox1.Items.Add(SplittedFase(i))
    i += Val(1)
    Loop
    ReadFile.Close
    End Sub

    I use them on Visual Studio 2015. I fix them and now my app don`t have any problems with it 🙂

    • Notrek
    • Posted 8 August, 2016 at 10:04 pm
    • Permalink

    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    IF YOU HAVE SOME ERRORS OR ANYTHING THAT BROKE YOUR APP IN DEBUG-MODE JUST USE THIS CODE
    I FIX ALL OF THE ERRORS THAT POPUP…

    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    //This one is for Save
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    Dim SaveFile As New SaveFileDialog()
    With SaveFile.Filter = “MyPlaylist File |*.MPF”
    End With
    If SaveFile.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
    Dim WriteFile As New IO.StreamWriter(SaveFile.FileName.ToString)
    Dim Count As Integer = ListBox1.Items.Count – Val(1)

    For i As Integer = 0 To Count
    WriteFile.Write(ListBox1.Items.Item(i) & “;”) ‘the “;” is used to separate the items

    Next
    WriteFile.Close()
    End If
    End Sub

    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    //And this one is for Load Playlist
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    Dim OpenFile As New OpenFileDialog()
    With OpenFile.Filter = “MyPlaylist File |*.MPF”
    End With
    If OpenFile.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
    Dim ReadFile As New IO.StreamReader(OpenFile.FileName.ToString)
    Dim Playlist As String = ReadFile.ReadToEnd
    Dim SplittedFase() = Playlist.Split(“;”)
    Dim Count As Integer = SplittedFase.Count – Val(1)
    Dim i As Integer = 0
    Do Until i = Count
    ListBox1.Items.Add(SplittedFase(i))
    i += Val(1)
    Loop
    ReadFile.Close()
    End If
    End Sub

    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: