Hello all, especially Steegy,
Thanks for the script. I find it quite useful, but there was this annoying behavior: it would show the title and artist of the first song that had to be rated and it would not update afterwards.
I made some small modifications to the GetForm function (commented all he changes). Here it is - just swap it out with the current 'GetForm' with the help of a text editor to try it.
- Code: Select all
Function GetForm
Set GetForm = SDB.Objects("RatePlayedSong_Form")
' Initialize the two variables here because they will be used in both sides of the conditional
Dim lblTit
Dim lblArt
If GetForm Is Nothing Then
Dim bheight : bheight = 23
Dim bwidth : bwidth = 35
Set GetForm = SDB.UI.NewForm
GetForm.Common.SetRect 100, 100, 360, 190
GetForm.BorderStyle = 3 ' Resizable
GetForm.FormPosition = 4 ' Screen Center
GetForm.SavePositionName = "RatePlayedSong_Form"
GetForm.Caption = "Rate Previously Played Song"
Set SDB.Objects("RatePlayedSong_Form") = GetForm
Set lblTit = SDB.UI.NewLabel(GetForm)
lblTit.Caption = "Title: " & PreviousSong.Title
lblTit.Common.Left = 10
lblTit.Common.Top = 14
' Initialize a new named label object, so we can refer to it later
Set SDB.Objects("RatePlayedSong_Form_lblTit") = lblTit
Set lblArt = SDB.UI.NewLabel(GetForm)
lblArt.Caption = "Artist: " & PreviousSong.ArtistName
lblArt.Common.Left = 10
lblArt.Common.Top = lblTit.Common.Top + lblTit.Common.Height +7
' same as above
Set SDB.Objects("RatePlayedSong_Form_lblArt") = lblArt
Dim i, btnPcnt
For i = 0 To 10
Set btnPcnt = SDB.UI.NewButton(GetForm)
btnPcnt.Caption = BtnCapt(i)
btnPcnt.Common.MinHeight = i
btnPcnt.Common.Height = bheight
btnPcnt.Common.Width = bwidth
btnPcnt.Common.Top = lblArt.Common.Top + lblArt.Common.Height + 10 + (i MOD 2)*bheight
btnPcnt.Common.Left = 50 + i*(bwidth - bwidth/2 + 5)
Script.RegisterEvent btnPcnt.Common, "OnClick", "RateButton_OnClick"
Next
Dim btnOk : Set btnOk = SDB.UI.NewButton(GetForm)
btnOk.Caption = "OK"
btnOk.Common.SetRect GetForm.Common.Width/2 - 155, lblArt.Common.Top + lblArt.Common.Height + 10 + 2*bheight + 10 + 5, 150, bheight
btnOk.Default = True
btnOk.ModalResult = 1
Dim btnCancel : Set btnCancel = SDB.UI.NewButton(GetForm)
btnCancel.Caption = "Cancel Changes"
btnCancel.Common.SetRect GetForm.Common.Width/2 + 5, BtnOK.Common.Top, 150, bheight
btnCancel.Cancel = True
btnCancel.ModalResult = 2
Else
' this bit is for when the form appears for not the first time
' capture the named label objects in lblTit and lblArt and update their content
Set lblTit = SDB.Objects("RatePlayedSong_Form_lblTit")
lblTit.Caption = "Title: " & PreviousSong.Title
Set lblArt = SDB.Objects("RatePlayedSong_Form_lblArt")
lblArt.Caption = "Artist: " & PreviousSong.ArtistName
End If
End Function