by Frodo56us » Fri Feb 20, 2004 3:14 pm
I've looked at those, but I must be too dense to make a lot of sense out of them. I am totally new to writing scripts.
I've created two seperate vbscripts, one for exporting all my songs to HTML which works fine. However the one for the Artist/Albums doesn't work. Really these are just edited versions of the HTML section of the original. Here is the offending script:
Option Explicit ' report undefined variables, ...
' function for quoting strings
Function QStr( astr)
QStr = chr(34) & astr & chr(34)
End Function
Dim list ' list of albums to be exported
Dim res ' results of dialogs calls
Dim fullfile ' fully specified output file name
Dim fso ' FileSystemObject
' SDB variable is connected to MediaMonkey application object
Sub InitExport( ext, filter, iniDirValue)
fullfile = ""
' Get a list of albums to be exported
Set list = SDB.SelectedSongList.Albums
If list.count=0 Then
Set list = SDB.AllVisibleSongList.Albums
End If
If list.count=0 Then
res = SDB.MessageBox( "Select Albums to be exported, please.", mtError, Array(mbOk))
Exit Sub
End If
' Open inifile and get last used directory
Dim iniF
Set iniF = SDB.IniFile
' Create common dialog and ask where to save the file
Dim dlg
Set dlg = SDB.CommonDialog
dlg.DefaultExt=ext
dlg.Filter=filter
dlg.Flags=cdlOFNOverwritePrompt + cdlOFNHideReadOnly
dlg.InitDir = iniF.StringValue( "Scripts", iniDirValue)
dlg.ShowSave
if Not dlg.Ok Then
Exit Sub ' if cancel was pressed, exit
End If
' Get the selected filename
fullfile = dlg.FileName
' Connect to the FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")
' Write selected directory to the ini file
iniF.StringValue( "Scripts", iniDirValue) = fullfile
End Sub
Sub FinishExport( ok)
On Error Resume Next
' remove the output file if terminated
if not Ok then
fso.DeleteFile( fullfile)
end if
' Notify user that it was successful
if ok then
res = SDB.MessageBox( "Export was completed successfully.", mtInformation, Array(mbOk))
else
res = SDB.MessageBox( "Export was terminated.", mtInformation, Array(mbOk))
end if
End Sub
Sub HTMLAlbumList
' initialize export
Call InitExport( ".htm", "HTML (*.htm)|*.htm|All files (*.*)|*.*", _
"LastExportHTMLDir")
if fullfile="" then
Exit Sub
end if
' Create the output file
Dim fout
Set fout = fso.CreateTextFile( fullfile, True)
' Write header line
fout.WriteLine "<html>"
fout.WriteLine "<head><title>MediaMonkey Track List</title>"
' Code to format the document
fout.WriteLine "<STYLE TYPE=text/css>"
fout.WriteLine "body{font-family:'Verdana',sans-serif; background-color:#FFFFFF; font-size:9pt; color:#000000;}"
fout.WriteLine "H1{font-family:'Verdana',sans-serif; font-size:13pt; font-weight:bold; color:#AAAAAA; text-aligh:left}"
fout.WriteLine "P{font-family:'Verdana',sans-serif; font-size:9pt; color:#000000;}"
fout.WriteLine "TH{font-family:'Verdana',sans-serif; font-size:10pt; font-weight:bold; color:#000000; border-color:#000000; border-style: solid; border-left-width:0px; border-right-width:0px; border-top-width:0px; border-bottom-width:3px;}"
fout.WriteLine "TD{font-family:'Verdana',sans-serif; font-size:9pt; color:#000000; border-color:#000000; border-style: solid; border-left-width:0px; border-right-width:0px; border-top-width:0px; border-bottom-width:1px;}"
fout.Writeline "TD.dark{background-color:#EEEEEE}"
fout.WriteLine "</STYLE>"
fout.WriteLine "</head><body>"
fout.WriteLine "<a href='http://www.mediamonkey.com'><H1>MediaMonkey Track List</H1></a>"
' Headers of table
fout.WriteLine "<TABLE CELLPADDING=4 CELLSPACING=0>"
fout.WriteLine "<tr>"
fout.WriteLine " <th ID=dark>#</th>"
fout.WriteLine " <th>Artist</th>"
fout.WriteLine " <th ID=dark>Album</th>"
fout.WriteLine "</tr>"
' Use progress to notify user about the current action
Dim Progress
Set Progress = SDB.Progress
Progress.Text = "Exporting to a HTML file..."
' Iterate through the list and export all songs
Progress.MaxValue = list.count
Dim i, itm
for i=0 to list.count-1
Set itm = list.Item(i)
' Add space to empty fields, so table is displayed correctly (Cell borders do not show up for empty cells)
Dim artistname
artistname = itm.ArtistName
if artistname="" then
artistname = "&"
end if
Dim albumname
albumname = itm.AlbumName
if albumname="" then
albumname = "&"
end if
' Body of the table
fout.WriteLine "<tr><td align=right class=dark>"&i+1 _
&"</TD><TD>"&artistname _
&"</td><td class=dark>"&albumname _
&"</td></tr>"
Progress.Value = i+1
if Progress.Terminate then
Exit For
end if
next
' Write some code to finish html document
fout.WriteLine "</table><p/><table width=100%><tr>"
fout.WriteLine "<td style='border-bottom-width:0px'><B>Total Tracks: </B>"&i&"</td> <td align=Right style='border-bottom-width:0px'>Generated by <a href='http://www.mediamonkey.com'>MediaMonkey</a></td>"
fout.WriteLine "</tr></table></body></html>"
' Close the output file and finish
fout.Close
' Was it successfull?
Dim ok
if Progress.Terminate then
ok = False
else
ok = True
end if
' hide progress
Set Progress = Nothing
FinishExport( ok)
End Sub
Which gives me the following error:
Error #438 - Microsoft VBScript Runtime Error
Object doesn't support this property or method: 'itm.artistname'
File "C:\Program Files\MediaMonkey\Scripts\HTMLAlbumList.vbs",
Line: 122, Column: 4
Think anyone more knowledgable than me can take a look at my code and see what I am doing wrong?
Frodo
I've looked at those, but I must be too dense to make a lot of sense out of them. I am totally new to writing scripts.
I've created two seperate vbscripts, one for exporting all my songs to HTML which works fine. However the one for the Artist/Albums doesn't work. Really these are just edited versions of the HTML section of the original. Here is the offending script:
[color=red]Option Explicit ' report undefined variables, ...
' function for quoting strings
Function QStr( astr)
QStr = chr(34) & astr & chr(34)
End Function
Dim list ' list of albums to be exported
Dim res ' results of dialogs calls
Dim fullfile ' fully specified output file name
Dim fso ' FileSystemObject
' SDB variable is connected to MediaMonkey application object
Sub InitExport( ext, filter, iniDirValue)
fullfile = ""
' Get a list of albums to be exported
Set list = SDB.SelectedSongList.Albums
If list.count=0 Then
Set list = SDB.AllVisibleSongList.Albums
End If
If list.count=0 Then
res = SDB.MessageBox( "Select Albums to be exported, please.", mtError, Array(mbOk))
Exit Sub
End If
' Open inifile and get last used directory
Dim iniF
Set iniF = SDB.IniFile
' Create common dialog and ask where to save the file
Dim dlg
Set dlg = SDB.CommonDialog
dlg.DefaultExt=ext
dlg.Filter=filter
dlg.Flags=cdlOFNOverwritePrompt + cdlOFNHideReadOnly
dlg.InitDir = iniF.StringValue( "Scripts", iniDirValue)
dlg.ShowSave
if Not dlg.Ok Then
Exit Sub ' if cancel was pressed, exit
End If
' Get the selected filename
fullfile = dlg.FileName
' Connect to the FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")
' Write selected directory to the ini file
iniF.StringValue( "Scripts", iniDirValue) = fullfile
End Sub
Sub FinishExport( ok)
On Error Resume Next
' remove the output file if terminated
if not Ok then
fso.DeleteFile( fullfile)
end if
' Notify user that it was successful
if ok then
res = SDB.MessageBox( "Export was completed successfully.", mtInformation, Array(mbOk))
else
res = SDB.MessageBox( "Export was terminated.", mtInformation, Array(mbOk))
end if
End Sub
Sub HTMLAlbumList
' initialize export
Call InitExport( ".htm", "HTML (*.htm)|*.htm|All files (*.*)|*.*", _
"LastExportHTMLDir")
if fullfile="" then
Exit Sub
end if
' Create the output file
Dim fout
Set fout = fso.CreateTextFile( fullfile, True)
' Write header line
fout.WriteLine "<html>"
fout.WriteLine "<head><title>MediaMonkey Track List</title>"
' Code to format the document
fout.WriteLine "<STYLE TYPE=text/css>"
fout.WriteLine "body{font-family:'Verdana',sans-serif; background-color:#FFFFFF; font-size:9pt; color:#000000;}"
fout.WriteLine "H1{font-family:'Verdana',sans-serif; font-size:13pt; font-weight:bold; color:#AAAAAA; text-aligh:left}"
fout.WriteLine "P{font-family:'Verdana',sans-serif; font-size:9pt; color:#000000;}"
fout.WriteLine "TH{font-family:'Verdana',sans-serif; font-size:10pt; font-weight:bold; color:#000000; border-color:#000000; border-style: solid; border-left-width:0px; border-right-width:0px; border-top-width:0px; border-bottom-width:3px;}"
fout.WriteLine "TD{font-family:'Verdana',sans-serif; font-size:9pt; color:#000000; border-color:#000000; border-style: solid; border-left-width:0px; border-right-width:0px; border-top-width:0px; border-bottom-width:1px;}"
fout.Writeline "TD.dark{background-color:#EEEEEE}"
fout.WriteLine "</STYLE>"
fout.WriteLine "</head><body>"
fout.WriteLine "<a href='http://www.mediamonkey.com'><H1>MediaMonkey Track List</H1></a>"
' Headers of table
fout.WriteLine "<TABLE CELLPADDING=4 CELLSPACING=0>"
fout.WriteLine "<tr>"
fout.WriteLine " <th ID=dark>#</th>"
fout.WriteLine " <th>Artist</th>"
fout.WriteLine " <th ID=dark>Album</th>"
fout.WriteLine "</tr>"
' Use progress to notify user about the current action
Dim Progress
Set Progress = SDB.Progress
Progress.Text = "Exporting to a HTML file..."
' Iterate through the list and export all songs
Progress.MaxValue = list.count
Dim i, itm
for i=0 to list.count-1
Set itm = list.Item(i)
' Add space to empty fields, so table is displayed correctly (Cell borders do not show up for empty cells)
Dim artistname
artistname = itm.ArtistName
if artistname="" then
artistname = "&"
end if
Dim albumname
albumname = itm.AlbumName
if albumname="" then
albumname = "&"
end if
' Body of the table
fout.WriteLine "<tr><td align=right class=dark>"&i+1 _
&"</TD><TD>"&artistname _
&"</td><td class=dark>"&albumname _
&"</td></tr>"
Progress.Value = i+1
if Progress.Terminate then
Exit For
end if
next
' Write some code to finish html document
fout.WriteLine "</table><p/><table width=100%><tr>"
fout.WriteLine "<td style='border-bottom-width:0px'><B>Total Tracks: </B>"&i&"</td> <td align=Right style='border-bottom-width:0px'>Generated by <a href='http://www.mediamonkey.com'>MediaMonkey</a></td>"
fout.WriteLine "</tr></table></body></html>"
' Close the output file and finish
fout.Close
' Was it successfull?
Dim ok
if Progress.Terminate then
ok = False
else
ok = True
end if
' hide progress
Set Progress = Nothing
FinishExport( ok)
End Sub [/color]
Which gives me the following error:
[color=olive]Error #438 - Microsoft VBScript Runtime Error
Object doesn't support this property or method: 'itm.artistname'
File "C:\Program Files\MediaMonkey\Scripts\HTMLAlbumList.vbs",
Line: 122, Column: 4[/color]
Think anyone more knowledgable than me can take a look at my code and see what I am doing wrong?
Frodo