Dim CurrSong As String 'this is where the current song will be stored, it will be used in comparisons later on, and so is important.
Private Sub Command1_Click()
If Command1.Caption = "Start Logging Songs" Then 'checks to see the caption of the command button
Command1.Caption = "Stop Logging Songs" 'changes the command buttons caption suitably
Timer1.Enabled = True 'enables the simple timer that will be used to log songs
Else:
Timer1.Enabled = False 'turns the timer off
Command1.Caption = "Start Logging Songs" 'changes the command buttons caption
End If
End Sub
Private Sub Command2_Click()
On Error GoTo SAVE_ERROR 'error trapping
Dim intX As Integer
CD.Filter = "Text File (*.txt)|*.txt" 'set the output of the common dialog control to text files
CD.ShowSave 'shows the common dialogs save menu
Open CD.FileName For Output As #2
For intX = 0 To List1.ListCount - 1 'loops through the listbox adding all the items to file
Print #2, List1.List(intX)
Next
Close #2
Exit Sub
SAVE_ERROR:
MsgBox Err.Num & " " & Err.Description, vbOKOnly, "" 'tells the end user what the error was
End Sub
Private Sub Command3_Click()
List1.Clear 'clears the log of songs
End Sub
Private Sub Form_Load()
Call Update 'Calling the update function straight away ensures the program id up-to-date with the currently playing song.
End Sub
Function Update()
Label1.Caption = getWinampWindow 'calls the module to gain the currently playing songs title
End Function
Private Sub Timer1_Timer()
Timer1.Enabled = False 'turns the timer off, just incase processing this Sub takes longer than expected.
Label1.Caption = getWinampWindow 'updates the Label to display the currently playing song.
CurrSong = getWinampWindow 'updates the currently playing song string via the module
If Left(CurrSong, 9) = "[Opening]" Then CurrSong = Right(CurrSong, Len(CurrSong) - 10) 'strips the [opening] tag that may exist on the song if Winamp is struggling to open a particular file
If List1.ListCount > 0 Then List1.ListIndex = 0
If CurrSong = List1.Text Then 'if the same song is still playing as the last update then skip anything from now, and do not re-add the song to the log
Else:
List1.AddItem CurrSong, 0 'adds the currently playing song to the top of the list
End If
Timer1.Enabled = True 'turns the timer back on, so the process can be repeated again.
End Sub