Reading a file and populating a listbox
Posted: Thu Aug 19, 2010 9:02 pm
Hello,
I am making a music program that has a custom file extension(mspf), and here I go.
I am trying to add songs to a playlist, and save the playlist. When I open the playlist I saved, the listbox says -1. That is it. When I save the playlist, it saves the directories of the songs. When I open the playlist, I want it to show the things I saved. Here is my code:
Open Playlist:
Private Sub AddSongToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddSongToolStripMenuItem.Click
Dim OFD As New OpenFileDialog
OFD.Title = "Add Song"
OFD.FileName = ""
OFD.Filter = "MP3 Files(*.mp3)|*.mp3|WAV Files(*.wav)|*.wav"
If OFD.ShowDialog = Windows.Forms.DialogResult.OK Then
RichTextBox1.Text = RichTextBox1.Text + vbNewLine & OFD.FileName
Music.Items.Remove(Music.Items.Count)
Music.Items.Add(RichTextBox1.Text)
End If
End Sub
Please help, this is a project I am working on, and I am trying to get it done. +rep to whoever answers first! cooll;
~GoodGuy17
I am making a music program that has a custom file extension(mspf), and here I go.
I am trying to add songs to a playlist, and save the playlist. When I open the playlist I saved, the listbox says -1. That is it. When I save the playlist, it saves the directories of the songs. When I open the playlist, I want it to show the things I saved. Here is my code:
Open Playlist:
Code: Select all
Save Playlist:
Private Sub OpenPlaylistToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenPlaylistToolStripMenuItem.Click
Dim OFD As New OpenFileDialog
OFD.Filter = "Music Studio Playlist Files(*.mspf)|*.mspf"
OFD.FileName = ""
OFD.Title = "Open Playlist"
If OFD.ShowDialog() = Windows.Forms.DialogResult.OK Then
Dim Reader As New System.IO.StreamReader(OFD.FileName)
RichTextBox1.Text = Reader.Read
Music.Items.Add(RichTextBox1.Text)
ToolStripStatusLabel1.Text = "Opened: " & OFD.FileName
End If
End Sub
Code: Select all
Add Song:Private Sub SavePlaylistToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SavePlaylistToolStripMenuItem.Click
Dim SFD As New SaveFileDialog
SFD.Title = "Save Playlist"
SFD.Filter = "Music Studio Playlist Files(*.mspf)|*.mspf"
SFD.FileName = ""
If SFD.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim Writer As New System.IO.StreamWriter(SFD.FileName)
For i As Integer = 0 To RichTextBox1.Lines.Count
Writer.WriteLine(RichTextBox1.Text)
Next
End If
End Sub
Private Sub AddSongToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddSongToolStripMenuItem.Click
Dim OFD As New OpenFileDialog
OFD.Title = "Add Song"
OFD.FileName = ""
OFD.Filter = "MP3 Files(*.mp3)|*.mp3|WAV Files(*.wav)|*.wav"
If OFD.ShowDialog = Windows.Forms.DialogResult.OK Then
RichTextBox1.Text = RichTextBox1.Text + vbNewLine & OFD.FileName
Music.Items.Remove(Music.Items.Count)
Music.Items.Add(RichTextBox1.Text)
End If
End Sub
Please help, this is a project I am working on, and I am trying to get it done. +rep to whoever answers first! cooll;
~GoodGuy17
