0

プレイリストを作成してそこから音楽を再生できるプログラムを作成しています。リストボックスとボタンの横に次のコードがあります。

Dim MusicFiles() As String
Public ListOfMusicFiles As New Dictionary(Of String, String)

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
        MusicFiles = OpenFileDialog1.FileNames
    End If
    Try
        For Each Item In MusicFiles
            Dim ItemSplit() = Item.Split("\"c)
            Dim ItemLast As String = ItemSplit(ItemSplit.Count - 1)
            ItemLast = ItemLast.Remove(ItemLast.Count - 4, 4)
            ListOfMusicFiles.Add(ItemLast, Item)
        Next

    Catch ex As Exception

    End Try
End Sub

上記のコードは、目的の音楽ファイルの名前を入力しますが、これをどこかに保存する必要があります。.txt ファイルを作成する必要があり、おそらく最初の行に音楽ファイルの名前があり、2 行目に場所があります。したがって、2 行を読み取り、それらを

listofmusicfiles

(私が作成した辞書)

次に、ファイルをリストボックスにインポートできます。どんな助けでも大歓迎です。アプリケーションはまだ開発プロセスにあるので、それを行うためのまったく別の方法、またはより簡単で効率的な方法があれば、それは素晴らしいことです:)

4

2 に答える 2

0

最後の質問に答えるには、「それを行うためのまったく異なる方法、またはより簡単で効率的な方法があれば、それは素晴らしいことです」と、データセットを使用してください。

    'You only need to define your data once
    Dim ds As New DataSet 'I like saving datasets to file as opposed to datatables. Plus you get the advantage of have muliple tables if you need.
    Dim dt As New DataTable 'The table will hold you data, you can have multiple tables for storing different types of data
    'Add what ever columns you what to the table
    dt.Columns.Add(New DataColumn("FileName", GetType(String)))
    dt.Columns.Add(New DataColumn("FileLocation", GetType(String)))
    'Add the table to the dataset
    ds.Tables.Add(dt)

    'Now you can add records to your table
    Dim DR As DataRow
    DR = dt.NewRow 'This builds a new record with the schema from your table, but you still have to fill in the data
    'fill in the data columns you wanted
    DR("FileName") = "..Your file name here.."
    DR("FileLocation") = "..Your location here.."
    'Now add the new row to your table
    dt.Rows.Add(DR)


    'Then, whenever you want, you can save to your HD like this:
    ds.WriteXml("Your File Name", XmlWriteMode.WriteSchema) 'XmlWriteMode.WriteSchema IS IMPORTANT

    'And can can read from the HD like this
    ds.ReadXml("Your File Name")
于 2013-10-18T19:21:54.550 に答える