Link to home
Create AccountLog in
Avatar of mwin76
mwin76

asked on

DJ Play List

I'm developing a program that has a text file music playlist. I'm having some trouble with my code, I want the user to enter numbers in a textbox called event length, which tell the program how long the event will last.  Once the numbers are enter in the textbox, the program searches the text file and display the songs on a listbox, based on the total event length input.

This is what i have so far

Public Shared _intSizeOfArray As Integer = 51
    Public Shared _strSortedSongList(_intSizeOfArray) As String
    Private _strMusicGenre(_intSizeOfArray) As String
    Private _decLengthOfSong(_intSizeOfArray) As Decimal

    Private Sub frmDJPlayList_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        ' The frmDJPlayList load event reads the songs.txt file and
        ' fills the ComboBox object with the genre types.

        ' Initialize an instance of the StreamReader object and declare variables
        Dim objReader As IO.StreamReader
        Dim strLocationAndNameOfFile As String = "C:\songs.txt"
        Dim intCount As Integer = 0
        Dim strFileErrorMessage As String = _
        "The file is not available. Restart when file is available."

        ' Verify the file exists
        If IO.File.Exists(strLocationAndNameOfFile) Then


            objReader = IO.File.OpenText(strLocationAndNameOfFile)

            ' Read file line by line until completed
            Do While objReader.Peek <> -1
                _strSortedSongList(intCount) = objReader.ReadLine()
                _strMusicGenre(intCount) = objReader.ReadLine()
                _decLengthOfSong(intCount) = Convert.ToDecimal(objReader.ReadLine())
                intCount += 1
            Loop
            objReader.Close()

            cboMusicGenres.Items.Add(_strMusicGenre)


        End If
    End Sub

    Private Sub btnDisplayPlayList_Click(sender As System.Object, e As System.EventArgs) Handles btnDisplayPlayList.Click
        ' The btnDisplayPlayList click event calls the Event Lenth Sub procedures.

        ' Declare variables
        Dim intSelectedGenre As Integer
        Dim strMissingSelection As String = "Missing Selection"
        Dim strEventLengthError As String = "Enter a Event Lenth"
        Dim strSelectGenreOfMusicError As String = "Select a Genre of Music"


        ' If the ComboBox is called, enter the PlayList procedure.

        If cboMusicGenres.SelectedIndex >= 0 Then
            intSelectedGenre = cboMusicGenres.SelectedIndex
            lstPlayList.Items.Add(intSelectedGenre)
        Else
            MsgBox(strSelectGenreOfMusicError, , strMissingSelection)
        End If

        ' (intSelectedGenre)
        'Else
        MsgBox(strSelectGenreOfMusicError, , strEventLengthError)
        ' End If
        Eventtotal = (txtEvent.Text * _decLengthOfSong)
        lstPlayList.Items.Add(_decLengthOfSong)


        Me.lstPlayList.Visible = True
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

You didn't really indicate the troubles that you are having...
Avatar of mwin76
mwin76

ASKER

The 1st issue I'm having is trying to get a combo box to fill with 5 five genre of music from my songs.txt file and have the song list of each genre populate to a listbox.

The 2nd issue I'm having is that the program also wants the user to enter numbers in a textbox called txtEvent, which tell the program how long the event will last.  Once the numbers are enter in the textbox, the program searches the songs.txt file and displays the songs on a listbox, based on the total event length input. I can't seem to get this formulated correctly, it's due tomorrow.
My first suggestion would be to use a generics list--List(Of T), instead of an array.  The list object can vary in size dynamically, rather than using a static array that needs to be resized.

Example:

Dim genres As New List(Of String)

genres.Add("Rock")
genres.Add("Blues")
genres.Add("Country")
genres.Add("Pop")

Open in new window


You can fill a list with values from your file, also.
Avatar of mwin76

ASKER

Using an array is a requirement for this project.
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account