by Edgar » Tue Aug 24, 2021 5:07 pm
I spent the whole day trying to pull myself up by my bootstraps and figured out almost all of it…
Code: Select all
' A script that edits the Artist of selected tracks and also assigns the album artist
Dim NameTextField, UI, MainWindow
Set UI = SDB.UI
Set MainWindow = UI.NewForm
Set NameTextField = UI.NewEdit (MainWindow)
Sub EditArtists
Const mmAnchorRight = 4
Const mmAnchorBottom = 8
Const mmAlignBottom = 2
Dim Footer, OKButton, CancelButton, list, item, dialogWidth
dialogWidth = 500
Set list = SDB.CurrentSongList
Set item = list.Item(0)
MainWindow.Common.SetRect 500, 300, dialogWidth, 200
MainWindow.Common.MinWidth = 200
MainWindow.Common.MinHeight = 200
MainWindow.Caption = SDB.Localize("Enter a new artist name")
MainWindow.StayOnTop = True
NameTextField.Text = item.ArtistName
NameTextField.Common.SetRect 5, 5, (dialogWidth - 50), 40
SDB.MessageBox "at entry x_" & NameTextField.Text & "_x", 2, Array(4)
Set Footer = UI.NewPanel(MainWindow)
Footer.Common.Align = mmAlignBottom
Footer.Common.Height = 35
Set CancelButton = UI.NewButton(Footer)
CancelButton.Caption = SDB.Localize("&Cancel")
CancelButton.Common.SetRect dialogWidth - 106, 5, 85, 25
CancelButton.Common.Anchors = mmAnchorRight + mmAnchorBottom
CancelButton.Cancel = True
CancelButton.UseScript = Script.ScriptPath
CancelButton.OnClickFunc = "OnCancel"
Set OKButton = UI.NewButton(Footer)
OKButton.Caption = SDB.Localize("&OK")
OKButton.Common.SetRect dialogWidth - 306, 5, 85, 25
OKButton.Common.Anchors = mmAnchorRight + mmAnchorBottom
OKButton.Cancel = False
OKButton.UseScript = Script.ScriptPath
OKButton.OnClickFunc = "OnOK"
SDB.ProcessMessages
MainWindow.SavePositionName = "EditArtistNameWindow"
MainWindow.Common.Visible = True
SDB.Objects("EditArtistName") = MainWindow
SDB.ProcessMessages
End Sub
Sub OnCancel(Btn)
SDB.Objects("EditArtistName") = Nothing
End Sub
Sub OnOK(Btn)
SDB.MessageBox "on okay x_" & NameTextField.Text & "_x", 2, Array(4)
Dim pList, pItem, increment, amount
Set pList = SDB.CurrentSongList
amount = pList.count - 1
For increment = 0 To amount
Set pItem = pList.Item(increment)
pItem.ArtistName = NameTextField.Text
pItem.AlbumArtistName = NameTextField.Text
Next
pList.UpdateAll
SDB.Objects("EditArtistName") = Nothing
End Sub
Everything is working except that the artist name and album artist name fields are being set to an empty string instead of to the content of the edit box. It feels almost as if the edit box and its content has been destroyed by the time I get into the on okay button handler. I have made the text box a global variable but the OnOK function might be creating a local variable and masking the global variable.
There are two MessageBox statements, almost identical, the first is within the entry function, the second is in the OnOK function. Each has a trivial preface (so that it's easy to tell where the message is coming from) followed by the contents of the text box (wrapped in "x_"/"_x" so that it is easy to tell that the string is empty). In the OnOK function the string is empty.
I spent the whole day trying to pull myself up by my bootstraps and figured out almost all of it…
[code]
' A script that edits the Artist of selected tracks and also assigns the album artist
Dim NameTextField, UI, MainWindow
Set UI = SDB.UI
Set MainWindow = UI.NewForm
Set NameTextField = UI.NewEdit (MainWindow)
Sub EditArtists
Const mmAnchorRight = 4
Const mmAnchorBottom = 8
Const mmAlignBottom = 2
Dim Footer, OKButton, CancelButton, list, item, dialogWidth
dialogWidth = 500
Set list = SDB.CurrentSongList
Set item = list.Item(0)
MainWindow.Common.SetRect 500, 300, dialogWidth, 200
MainWindow.Common.MinWidth = 200
MainWindow.Common.MinHeight = 200
MainWindow.Caption = SDB.Localize("Enter a new artist name")
MainWindow.StayOnTop = True
NameTextField.Text = item.ArtistName
NameTextField.Common.SetRect 5, 5, (dialogWidth - 50), 40
SDB.MessageBox "at entry x_" & NameTextField.Text & "_x", 2, Array(4)
Set Footer = UI.NewPanel(MainWindow)
Footer.Common.Align = mmAlignBottom
Footer.Common.Height = 35
Set CancelButton = UI.NewButton(Footer)
CancelButton.Caption = SDB.Localize("&Cancel")
CancelButton.Common.SetRect dialogWidth - 106, 5, 85, 25
CancelButton.Common.Anchors = mmAnchorRight + mmAnchorBottom
CancelButton.Cancel = True
CancelButton.UseScript = Script.ScriptPath
CancelButton.OnClickFunc = "OnCancel"
Set OKButton = UI.NewButton(Footer)
OKButton.Caption = SDB.Localize("&OK")
OKButton.Common.SetRect dialogWidth - 306, 5, 85, 25
OKButton.Common.Anchors = mmAnchorRight + mmAnchorBottom
OKButton.Cancel = False
OKButton.UseScript = Script.ScriptPath
OKButton.OnClickFunc = "OnOK"
SDB.ProcessMessages
MainWindow.SavePositionName = "EditArtistNameWindow"
MainWindow.Common.Visible = True
SDB.Objects("EditArtistName") = MainWindow
SDB.ProcessMessages
End Sub
Sub OnCancel(Btn)
SDB.Objects("EditArtistName") = Nothing
End Sub
Sub OnOK(Btn)
SDB.MessageBox "on okay x_" & NameTextField.Text & "_x", 2, Array(4)
Dim pList, pItem, increment, amount
Set pList = SDB.CurrentSongList
amount = pList.count - 1
For increment = 0 To amount
Set pItem = pList.Item(increment)
pItem.ArtistName = NameTextField.Text
pItem.AlbumArtistName = NameTextField.Text
Next
pList.UpdateAll
SDB.Objects("EditArtistName") = Nothing
End Sub
[/code]
Everything is working except that the artist name and album artist name fields are being set to an empty string instead of to the content of the edit box. It feels almost as if the edit box and its content has been destroyed by the time I get into the on okay button handler. I have made the text box a global variable but the OnOK function might be creating a local variable and masking the global variable.
There are two MessageBox statements, almost identical, the first is within the entry function, the second is in the OnOK function. Each has a trivial preface (so that it's easy to tell where the message is coming from) followed by the contents of the text box (wrapped in "x_"/"_x" so that it is easy to tell that the string is empty). In the OnOK function the string is empty.