Public Class DJPlayList
' Class Level Private variables
'structure definition
Structure Songs
Public strSongName As String
Public strSongCatagory As String
Public decSongLength As Decimal
End Structure
'declare an empty array
Public invSongItems() As Songs
Private Sub DJPlaylist(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' The DJPlaylist load event reads the song text file and
' fills the ComboBox object with the song items
' Initialize an instance of the StreamReader object and
' declare variables
Dim objReader As IO.StreamReader
Dim strLocationAndNameOfFile As String = "e:\songs.txt"
Dim intCount As Integer = 0
Dim intFill As Integer
Dim strFileErrorMessage As String = _
"The file is not available. Restart when the file is available."
' Verify the file exists
If IO.File.Exists(strLocationAndNameOfFile) Then
objReader = IO.File.OpenText(strLocationAndNameOfFile)
' Read the file line by line until the file is completed
Do While objReader.Peek <> -1
'redimension array to count items and fill the structure
ReDim Preserve invSongItems(intCount)
'use the with construct to avoid having to type invInventoryitems(intCount)
'infront of each variable member
With invSongItems(intCount)
.strSongName = objReader.ReadLine()
.strSongCatagory = objReader.ReadLine()
.decSongLength = Convert.ToDecimal(objReader.ReadLine())
End With
'increase loop counter
intCount += 1
Loop
objReader.Close()
' The ComboBox object is filled with the Inventory IDs
For intFill = 0 To (invSongItems.Length - 1)
Me.cboSonggenre.Items.Add(invSongItems(intFill).strSongCatagory)
Next
Else
MessageBox.Show(strFileErrorMessage, "Error")
Me.Close()
End If
End Sub
Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplayPlayList.Click
Dim intTime As Integer
Dim intCount As Integer
Dim intSeconds As Integer
Dim intTempTime As Integer
Dim intLength As Integer 'length of array
Dim decLength As Decimal
Dim strGendre As String
Dim strOutPut As String
'clear the list box
Me.lstPlayList.Items.Clear()
'do we have a number int the textbox
If (IsNumeric(Me.txtPlaylistTime.Text)) Then
'read length from textbox
decLength = Convert.ToDecimal(Me.txtPlaylistTime.Text)
'convert length to seconds
intSeconds = convertToSeconds(decLength)
'if no item selected list all songs to time length
If Me.cboSonggenre.SelectedIndex = -1 Then
'while still time and more items in array
While intTime < intSeconds And intCount < intLength
intTempTime = convertToSeconds(decSongLength(intCount))
If intSeconds >= intTempTime + intTime Then
intTime += intTempTime
strOutPut = intCount.ToString + ". " + strSongName(intCount) + " " + decSongLength(intCount).ToString
Me.lstPlayList.Items.Add(strOutPut)
End If
intCount += 1
End While
Else
strGendre = Me.cboSonggenre.SelectedItem
While intTime < intSeconds And intCount < intLength
If strGendre = strSongCatagory(intCount).ToUpper Then
intTempTime = convertToSeconds(decSongLength(intCount))
If intSeconds >= intTempTime + intTime Then
intTime += intTempTime
strOutPut = intCount.ToString + ". " + strSongName(intCount) + " " + decSongLength(intCount).ToString
Me.lstPlayList.Items.Add(strOutPut)
End If
End If
intCount += 1
End While
End If
Else
MessageBox.Show("Please enter the length of program", "Data Entry Error")
End If
End Sub
Private Function convertToSeconds(ByVal decLength As Decimal) As Integer
Dim intLength As Integer
Dim intMinutes As Integer
Dim intSeconds As Integer
intMinutes = decLength
intSeconds = (decLength * 100) Mod 100
intLength = intSeconds + intMinutes * 60
Return intLength
End Function
Private Sub mnuDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuDisplay.Click
Dim frmSecond As New displaySongList
Me.Hide()
frmSecond.Show()
End Sub
Private Function MinToSeconds(ByVal strTime As String) As Integer
Dim intMinutes As Integer
Dim intSeconds As Integer
Dim intConvertedTime As Integer
Dim decTime As Decimal
decTime = Convert.ToDecimal(strTime)
intSeconds = Convert.ToInt32(decTime * 100) Mod 100
intMinutes = Convert.ToInt32(decTime)
intConvertedTime = intMinutes * 60 + intSeconds
Return intConvertedTime
End Function
Private Sub ClearToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuClear.Click
Me.txtPlaylistTime.Clear()
Me.cboSonggenre.SelectedIndex = -1
Me.lstPlayList.Items.Clear()
End Sub
Private Sub mnuFileExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnueXit.Click
Me.Close()
End Sub
End Class
EDIT: Code blocks added, please use them in the future =>
This post has been edited by PsychoCoder: 07 May 2008 - 07:18 AM

New Topic/Question
Reply




MultiQuote



|