Sample Read and Write Method(s): Difference between revisions

From MediaMonkey Wiki
Jump to navigation Jump to search
No edit summary
 
 
(22 intermediate revisions by one other user not shown)
Line 1: Line 1:
{| align="right"
| __TOC__
|}
==Instructions==
# Copy the sample code into a text editor
# Replace highlighted terms with information from the items page in the Property Summary Table [[ISDBSongData::Title|Title]] e.g.
## Value Name = Title
## Value Type = String
## Field Name = SongTitle
## Database Table = Songs
# Change the SelectMethod = 1 to a number corresponding to the select method required e.g.
## SelectMethod = 2 would use SQLQuery Method
# Comment all lines that DO NOT match the SelectMethod chosen by adding a single quote to the front of the line e.g. If SelectMethod was set as 3 all lines with 'SelectMethod not containing 2 would need to be commented out (or removed)
## ' For iCounter = 0 to objSongList.count - 1                                        'SelectMethod '''4''' SongLists
# Save the file as WikiSample.vbs in ...MediaMonkey\Scripts folder
# Edit the ...MediaMonkey\Scripts\Scripts.ini and add (copy/paste the section between '<-- Start ini code and '<--- End ini code) and save
# Start MM and select menu Tools --> Scripts --> WikiSample
'''Note:''' If Value Type = Object you will need to add the Member Name to the code e.g. ObjectAlbum = objSongData.Album.Member<br>
==Sample Code==
<span style="color: #808080;">'</span>
<span style="color: #808080;">' MediaMonkey Script</span>
<span style="color: #808080;">'</span>
<span style="color: #808080;">' NAME: WikiSample.vbs</span>
<span style="color: #808080;">'</span>
<span style="color: #808080;">' Template Author: MoDementia</span>
<span style="color: #808080;">' Time, DATE :  22:31, 09 April 2008</span>
<span style="color: #808080;">'</span>
<span style="color: #808080;">'Sample of Scripting Code Read and Write Method(s)</span>
<span style="color: #808080;">'A working script to show database results using various selection methods</span>
<span style="color: #808080;">'</span>
<span style="color: #808080;">'MediaMonkey\Scripts\Scripts.ini entry</span>
<span style="color: #808080;">'</span>
<span style="color: #808080;">'<-- Start ini code</span>
<span style="color: #808080;">'[WikiSample]</span>                                                                      '[[Introduction_to_scripting#Format_of_the_Scripts.ini_file|Format of the Scripts.ini file]]
<span style="color: #808080;">'Filename=WikiSample.vbs</span>
<span style="color: #808080;">'Procname=WikiSample</span>
<span style="color: #808080;">'Order=99</span>
<span style="color: #808080;">'DisplayName=WikiSample</span>
<span style="color: #808080;">'Description=Displays the raw database value of the MMWikipage item</span>
<span style="color: #808080;">'Language=VBScript</span>
<span style="color: #808080;">'ScriptType=0</span>
<span style="color: #808080;">'<-- End ini code</span>
  <span style="color: #b1b100;">Sub</span> WikiSample
  <span style="color: #b1b100;">Dim</span> SelectMethod, SampleID, <span style="background:#CCFFCC;">Value Type</span>New<span style="background:#FFCC99;">Value Name</span>
{{#ifeq:{{{3|-}}}|Object| |  <span style="color: #b1b100;">Dim</span> SQLString                                                                    'SelectMethod 3}}
  <span style="color: #b1b100;">Dim</span> objSongList                                                                  'SelectMethod 2
  SelectMethod = <span style="color: #cc66cc;">1</span>
  <span style="color: #808080;">' SelectMethod NowPlaying = 1</span>
  <span style="color: #808080;">' SelectMethod UseSQLQuery = 2</span>
{{#ifeq:{{{3|-}}}|Object| |  <span style="color: #808080;">' SelectMethod UseSQL = 3</span>}}
  <span style="color: #808080;">' SelectMethod SelectedSongs = 4</span>
<span style="color: #808080;">'  SampleID = 13123                                                                  'Usualy Set in another part of the script</span>
<span style="color: #808080;">'Random SampleID Code (Remove if SampleID known)</span>
  <span style="color: #aaaaaa;"> Set iter = SDB.Database.OpenSQL("SELECT DISTINCT Songs.ID FROM Songs ORDER BY RANDOM() Limit 1")
  While Not iter.EOF
    SampleID = iter.StringByIndex(0)
  iter.Next
  Wend</span>
<span style="color: #808080;">'End of random SampleID code</span>
  <span style="background:#CCFFCC;">Value Type</span>New<span style="background:#FFCC99;">Value Name</span> = <span style="color: #ff0000;">"Mamma Mia"</span>
  <span style="color: #b1b100;">Set</span> objSongList = SDB.<span style="color: #66cc66;">NewSongList</span>                                                'SelectMethod 2 and 3 [[ISDBApplication::NewSongList|SDB.NewSongList]]
 
  Select <span style="color: #b1b100;">Case</span> SelectMethod
    <span style="color: #b1b100;">Case</span> <span style="color: #cc66cc;">1</span>
      <span style="color: #b1b100;">Set</span> objSongData = SDB.<span style="color: #66cc66;">Player.CurrentSong</span>                                      '[[ISDBPlayer::CurrentSong|SDB.Player.CurrentSong]]
    <span style="color: #b1b100;">Case</span> <span style="color: #cc66cc;">2</span>
      <span style="color: #b1b100;">Set</span> objSongListiterator = SDB.Database.<span style="color: #66cc66;">QuerySongs(</span><span style="color: #ff0000;">"AND Songs.ID="</span> & SampleID<span style="color: #66cc66;">)</span> '[[ISDBDatabase::QuerySongs|SDB.Database.QuerySongs]]
{{#ifeq:{{{3|-}}}|Object| |    <span style="color: #b1b100;">Case</span> <span style="color: #cc66cc;">3</span>}}
{{#ifeq:{{{3|-}}}|Object| |      SQLString = <span style="color: #ff0000;">"SELECT</span> <span style="background:#CC99FF;">Field Name</span> <span style="color: #ff0000;">FROM</span> <span style="background:#CC99FF;">Database Table</span> <span style="color: #ff0000;">WHERE</span> <span style="background:#CC99FF;">Database Table</span><span style="color: #ff0000;">.ID = "</span> & SampleID}}
{{#ifeq:{{{3|-}}}|Object| |      <span style="color: #b1b100;">Set</span> objSongStringiterator = SDB.Database.<span style="color: #66cc66;">OpenSQL(</span>SQLString<span style="color: #66cc66;">)</span>                    '[[ISDBDatabase::OpenSQL|SDB.Database.OpenSQL]]}}
    <span style="color: #b1b100;">Case</span> <span style="color: #cc66cc;">4</span>
      <span style="color: #b1b100;">Set</span> objSongList = SDB.<span style="color: #66cc66;">SelectedSongList</span>                                        '[[ISDBApplication::SelectedSongList|SDB.SelectedSongList]]
<span style="color: #808080;">'      Set objSongList = SDB.CurrentSongList</span>                                      '[[ISDBApplication::CurrentSongList|SDB.CurrentSongList]]
<span style="color: #808080;">'      Set objSongList = SDB.AllVisibleSongList</span>                                    '[[ISDBApplication::AllVisibleSongList|SDB.AllVisibleSongList]]
    <span style="color: #b1b100;">Case Else</span>
      SDB.<span style="color: #66cc66;">MessageBox</span> <span style="color: #ff0000;">"Incorrect Select Method "</span>, mtError, Array<span style="color: #66cc66;">(</span>mbOK<span style="color: #66cc66;">)</span>              '[[ISDBApplication::MessageBox|SDB.MessageBox]]
      <span style="color: #b1b100;">Exit Sub</span>
  <span style="color: #b1b100;">End</span> Select
 
  For <span style="color: #b1b100;">iCounter</span> = <span style="color: #cc66cc;">0</span> <span style="color: #b1b100;">to</span> objSongList.<span style="color: #b1b100;">count</span> - <span style="color: #cc66cc;">1</span>                                        'SelectMethod 4 [[SDBSongList|SongLists]]
    <span style="color: #b1b100;">While Not</span> objSongListiterator.<span style="color: #b1b100;">EOF</span>                                              'SelectMethod 2 [[SDBDBIterator|Iterator]]
    <span style="color: #b1b100;">While Not</span> objSongStringiterator.<span style="color: #b1b100;">EOF</span>                                              'SelectMethod 3
      <span style="color: #b1b100;">Set</span> objSongData = objSongListiterator.<span style="color: #66cc66;">Item</span>                                    'SelectMethod 2
      objSongList.<span style="color: #66cc66;">Add(</span>objSongData<span style="color: #66cc66;">)</span>                                                  'SelectMethod 2
      <span style="color: #b1b100;">Set</span> objSongData = objSongList.<span style="color: #66cc66;">Item</span><span style="color: #66cc66;">(</span>iCounter<span style="color: #66cc66;">)</span>                                  'SelectMethod 4
      <span style="background:#CCFFCC;">Value Type</span><span style="background:#FFCC99;">Value Name</span> = objSongData.<span style="background:#FFCC99;">Value Name</span>{{#ifeq:{{{3|-}}}|Object|.Member}}                                'SelectMethod 1, 2 and 4
      SDB.<span style="color: #66cc66;">MessageBox</span> <span style="color: #ff0000;">"Value = '"</span> & <span style="background:#CCFFCC;">Value Type</span><span style="background:#FFCC99;">Value Name</span> & <span style="color: #ff0000;">"'"</span>, mtError, <span style="color: #b1b100;">Array</span><span style="color: #66cc66;">(</span>mbOK<span style="color: #66cc66;">)</span> 'SelectMethod 4 (2 and 3)
{{#ifeq:{{{3|-}}}|Object| |      <span style="background:#CCFFCC;">Value Type</span><span style="background:#FFCC99;">Value Name</span> = objSongStringiterator.<span style="color: #66cc66;">StringByIndex(</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">)</span>                  'SelectMethod 3}}
    objSongListiterator.<span style="color: #b1b100;">Next</span>                                                        'SelectMethod 2
    objSongStringiterator.<span style="color: #b1b100;">Next</span>                                                        'SelectMethod 3
    <span style="color: #b1b100;">Wend</span>                                                                            'SelectMethod 2 and 3
  <span style="color: #b1b100;">Next</span>                                                                              'SelectMethod 4
  <span style="color: #b1b100;">Set</span> objSongListiterator=<span style="color: #b1b100;">Nothing</span>                                                  'SelectMethod 2
  <span style="color: #b1b100;">Set</span> objSongStringiterator=<span style="color: #b1b100;">Nothing</span>                                                  'SelectMethod 3
  SDB.<span style="color: #66cc66;">MessageBox</span> <span style="color: #ff0000;">"Value = '"</span> & <span style="background:#CCFFCC;">Value Type</span><span style="background:#FFCC99;">Value Name</span> & <span style="color: #ff0000;">"'"</span>, mtError, <span style="color: #b1b100;">Array</span><span style="color: #66cc66;">(</span>mbOK<span style="color: #66cc66;">)</span>
<span style="color: #808080;">'  objSongData.</span><span style="background:#FFCC99;">Value Name</span>{{#ifeq:{{{3|-}}}|Object|.Member}} = <span style="background:#CCFFCC;">Value Type</span>New<span style="background:#FFCC99;">Value Name</span> 'Commented Out For Safety      'SelectMethod 1, 2 and 4
<span style="color: #808080;">'  objSonglist.UpdateAll</span>                            'Commented Out For Safety      '[[SDBSongData|UpdateAll]]
                          'SelectMethod 1, 2 and 4 Updates db and writes tags (if checked in options)
<span style="color: #b1b100;">End Sub</span>
==Converted Sample Method 2==
<source lang="vb">
<source lang="vb">
'
'
Line 8: Line 115:
' Time, DATE :  22:31, 09 April 2008
' Time, DATE :  22:31, 09 April 2008
'
'
'Sample of Scripting Code for inclusion into MMWiki pages
'Sample of Scripting Code Read and Write Method(s)
'A working script to show database results using various selection methods
'A working script to show database results using various selection methods
'
'
'MediaMonkey\Scripts\Scripts.in entry
'MediaMonkey\Scripts\Scripts.ini entry
'
'
'[WikiSample]                                                             'Format of the Scripts.ini file
'<-- Start ini code
'[WikiSample]                                                                       'Format of the Scripts.ini file
'Filename=WikiSample.vbs
'Filename=WikiSample.vbs
'Procname=WikiSample
'Procname=WikiSample
Line 21: Line 129:
'Language=VBScript
'Language=VBScript
'ScriptType=0
'ScriptType=0
'<-- End ini code


 
Sub WikiSample
Sub WikiSample
 
   Dim SelectMethod, SampleID, StringNewTitle
   Dim SelectMethod, SampleID, StringNewTitle
   Dim SQLString                                                           'SelectMethod 3
'   Dim SQLString                                                                     'SelectMethod 3
   Dim objSongList                                                         'SelectMethod 2
   Dim objSongList                                                                   'SelectMethod 2


   SelectMethod = 1
   SelectMethod = 2
   ' SelectMethod NowPlaying = 1
   ' SelectMethod NowPlaying = 1
   ' SelectMethod UseSQLQuery = 2
   ' SelectMethod UseSQLQuery = 2
   ' SelectMethod UseSQL = 3
   ' SelectMethod UseSQL = 3
   ' SelectMethod SelectedSongs = 4
   ' SelectMethod SelectedSongs = 4
    
   SampleID = 13123
'   SampleID = 13123                                                                  'Usualy Set in another part of the script
'Random SampleID Code (Remove if SampleID known)
   Set iter = SDB.Database.OpenSQL("SELECT DISTINCT Songs.ID FROM Songs ORDER BY RANDOM() Limit 1")
  While Not iter.EOF
    SampleID = iter.StringByIndex(0)
  iter.Next
  Wend
  Set iter=Nothing
'End of random SampleID code
   StringNewTitle = "Mamma Mia"
   StringNewTitle = "Mamma Mia"
   Set objSongList = SDB.NewSongList                                       'SelectMethod 2 and 3 SDB.NewSongList
   Set objSongList = SDB.NewSongList                                                 'SelectMethod 2 and 3 SDB.NewSongList
 
   Select Case SelectMethod
   Select Case SelectMethod
     Case 1
     Case 1
       Set objSongData = SDB.Player.CurrentSong                             'SDB.Player.CurrentSong
       Set objSongData = SDB.Player.CurrentSong                                     'SDB.Player.CurrentSong
     Case 2
     Case 2
       Set objSongListiterator = SDB.Database.QuerySongs("AND Songs.ID=" & SampleID) 'SDB.Database.QuerySongs
       Set objSongListiterator = SDB.Database.QuerySongs("AND Songs.ID=" & SampleID) 'SDB.Database.QuerySongs
     Case 3
     Case 3
       SQLString = "SELECT SongTitle FROM Songs WHERE Songs.ID = " & SampleID
       SQLString = "SELECT SongTitle FROM Songs WHERE Songs.ID = " & SampleID
       Set objSongListiterator = SDB.Database.OpenSQL(SQLString)           'SDB.Database.OpenSQL
       Set objSongStringiterator = SDB.Database.OpenSQL(SQLString)                     'SDB.Database.OpenSQL
     Case 4
     Case 4
       Set objSongList = SDB.SelectedSongList                               'SDB.SelectedSongList
       Set objSongList = SDB.SelectedSongList                                       'SDB.SelectedSongList
'      Set objSongList = SDB.CurrentSongList                             'SDB.CurrentSongList
'      Set objSongList = SDB.CurrentSongList                                       'SDB.CurrentSongList
'      Set objSongList = SDB.AllVisibleSongList                           'SDB.AllVisibleSongList
'      Set objSongList = SDB.AllVisibleSongList                                   'SDB.AllVisibleSongList
     Case Else
     Case Else
       SDB.MessageBox "Incorrect Select Method ", mtError, Array(mbOK)     'SDB.MessageBox
       SDB.MessageBox "Incorrect Select Method ", mtError, Array(mbOK)               'SDB.MessageBox
       Exit Sub
       Exit Sub
   End Select
   End Select
'  For iCounter = 0 to objSongList.count - 1                                        'SelectMethod 4 SongLists
    While Not objSongListiterator.EOF                                              'SelectMethod 2
'    While Not objSongStringiterator.EOF                                              'SelectMethod 3
      Set objSongData = objSongListiterator.Item                                    'SelectMethod 2
      objSongList.Add(objSongData)                                                  'SelectMethod 2
'      Set objSongData = objSongList.Item(iCounter)                                  'SelectMethod 4
      StringTitle = objSongData.Title                                'SelectMethod 1, 2 and 4
      SDB.MessageBox "Value = '" & StringTitle & "'", mtError, Array(mbOK) 'SelectMethod 4 (2 and 3)
'      StringTitle = objSongStringiterator.StringByIndex(0)                  'SelectMethod 3
    objSongListiterator.Next                                                        'SelectMethod 2
'    objSongStringiterator.Next                                                        'SelectMethod 3
    Wend                                                                            'SelectMethod 2 and 3
'  Next                                                                              'SelectMethod 4
  Set objSongListiterator=Nothing                                                  'SelectMethod 2
'  Set objSongStringiterator=Nothing                                                  'SelectMethod 3
    
    
  For iCounter = 0 to objSongList.count - 1                                'SelectMethod 4 SongLists
    While Not objSongListiterator.EOF                                      'SelectMethod 2 and 3 Iterator
      Set objSongData = objSongListiterator.Item                          'SelectMethod 2
      objSongList.Add(objSongData)                                        'SelectMethod 2
      Set objSongData = objSongList.Item(iCounter)                        'SelectMethod 4
      StringTitle = objSongData.Title                                      'SelectMethod 1, 2 and 4
      SDB.MessageBox "Value = '" & StringTitle & "'", mtError, Array(mbOK) 'SelectMethod 4 (2 and 3)
      StringTitle = objSongListiterator.StringByIndex(0)                  'SelectMethod 3
    objSongListiterator.Next                                              'SelectMethod 2 and 3
    Wend                                                                  'SelectMethod 2 and 3
  Next                                                                    'SelectMethod 4
  Set objSongListiterator=Nothing                                          'SelectMethod 2 and 3
   SDB.MessageBox "Value = '" & StringTitle & "'", mtError, Array(mbOK)
   SDB.MessageBox "Value = '" & StringTitle & "'", mtError, Array(mbOK)


'  objSongData.Title = StringNewTitle 'Commented Out For Safety 'SelectMethod 1, 2 and 4
'  objSongData.Title = StringNewTitle 'Commented Out For Safety       'SelectMethod 1, 2 and 4
'  objSonglist.UpdateAll             'Commented Out For Safety           'UpdateAll
'  objSonglist.UpdateAll                           'Commented Out For Safety      'UpdateAll
                        'SelectMethod 1, 2 and 4 Updates db and writes tags (if checked in options)
End Sub
</source>
 
<source lang="vb">
'
' MediaMonkey Script
'
' NAME: WikiSample.vbs
'
' Template Author: MoDementia
' Generated by MMWiki page ISDBSongData::Album
' Time, DATE :  22:31, 09 April 2008
'
'Sample of Scripting Code for inclusion into MMWiki pages
'A working script to show database results using various selection methods
'
'MediaMonkey\Scripts\Scripts.in entry
'
'[WikiSample]                                                            'Format of the Scripts.ini file
'Filename=WikiSample.vbs
'Procname=WikiSample
'Order=99
'DisplayName=WikiSample
'Description=Displays the raw database value of the MMWikipage item
'Language=VBScript
'ScriptType=0
 
 
Sub WikiSample
 
  Dim SelectMethod, SampleID, ObjectNewAlbum
 
  Dim objSongList                                                          'SelectMethod 2
 
  SelectMethod = 1
  ' SelectMethod NowPlaying = 1
  ' SelectMethod UseSQLQuery = 2
 
  ' SelectMethod SelectedSongs = 4
 
  SampleID = 13123
  ObjectNewAlbum = "Mamma Mia"
  Set objSongList = SDB.NewSongList                                        'SelectMethod 2 and 3 SDB.NewSongList
 
  Select Case SelectMethod
    Case 1
      Set objSongData = SDB.Player.CurrentSong                            'SDB.Player.CurrentSong
    Case 2
      Set objSongListiterator = SDB.Database.QuerySongs("AND Songs.ID=" & SampleID) 'SDB.Database.QuerySongs
 
 
 
    Case 4
      Set objSongList = SDB.SelectedSongList                              'SDB.SelectedSongList
'      Set objSongList = SDB.CurrentSongList                              'SDB.CurrentSongList
'       Set objSongList = SDB.AllVisibleSongList                          'SDB.AllVisibleSongList
    Case Else
      SDB.MessageBox "Incorrect Select Method ", mtError, Array(mbOK)      'SDB.MessageBox
      Exit Sub
  End Select
 
  For iCounter = 0 to objSongList.count - 1                                'SelectMethod 4 SongLists
    While Not objSongListiterator.EOF                                      'SelectMethod 2 and 3 Iterator
      Set objSongData = objSongListiterator.Item                          'SelectMethod 2
      objSongList.Add(objSongData)                                        'SelectMethod 2
      Set objSongData = objSongList.Item(iCounter)                        'SelectMethod 4
      ObjectAlbum = objSongData.Album.Member                                      'SelectMethod 1, 2 and 4
      SDB.MessageBox "Value = '" & ObjectAlbum & "'", mtError, Array(mbOK) 'SelectMethod 4 (2 and 3)
 
    objSongListiterator.Next                                              'SelectMethod 2 and 3
    Wend                                                                  'SelectMethod 2 and 3
  Next                                                                    'SelectMethod 4
  Set objSongListiterator=Nothing                                          'SelectMethod 2 and 3
 
  SDB.MessageBox "Value = '" & ObjectAlbum & "'", mtError, Array(mbOK)
 
'  objSongData.Album.Member = ObjectNewAlbum 'Commented Out For Safety 'SelectMethod 1, 2 and 4
'  objSonglist.UpdateAll              'Commented Out For Safety            'UpdateAll
                         'SelectMethod 1, 2 and 4 Updates db and writes tags (if checked in options)
                         'SelectMethod 1, 2 and 4 Updates db and writes tags (if checked in options)
End Sub
End Sub</source>
</source>

Latest revision as of 18:23, 20 April 2008

Instructions

  1. Copy the sample code into a text editor
  2. Replace highlighted terms with information from the items page in the Property Summary Table Title e.g.
    1. Value Name = Title
    2. Value Type = String
    3. Field Name = SongTitle
    4. Database Table = Songs
  3. Change the SelectMethod = 1 to a number corresponding to the select method required e.g.
    1. SelectMethod = 2 would use SQLQuery Method
  4. Comment all lines that DO NOT match the SelectMethod chosen by adding a single quote to the front of the line e.g. If SelectMethod was set as 3 all lines with 'SelectMethod not containing 2 would need to be commented out (or removed)
    1. ' For iCounter = 0 to objSongList.count - 1 'SelectMethod 4 SongLists
  5. Save the file as WikiSample.vbs in ...MediaMonkey\Scripts folder
  6. Edit the ...MediaMonkey\Scripts\Scripts.ini and add (copy/paste the section between '<-- Start ini code and '<--- End ini code) and save
  7. Start MM and select menu Tools --> Scripts --> WikiSample

Note: If Value Type = Object you will need to add the Member Name to the code e.g. ObjectAlbum = objSongData.Album.Member

Sample Code

'
' MediaMonkey Script
'
' NAME: WikiSample.vbs
'
' Template Author: MoDementia
' Time, DATE :  22:31, 09 April 2008
'
'Sample of Scripting Code Read and Write Method(s)
'A working script to show database results using various selection methods
'
'MediaMonkey\Scripts\Scripts.ini entry
'
'<-- Start ini code
'[WikiSample]                                                                       'Format of the Scripts.ini file
'Filename=WikiSample.vbs
'Procname=WikiSample
'Order=99
'DisplayName=WikiSample
'Description=Displays the raw database value of the MMWikipage item
'Language=VBScript
'ScriptType=0
'<-- End ini code

 Sub WikiSample
  Dim SelectMethod, SampleID, Value TypeNewValue Name

Dim SQLString 'SelectMethod 3

  Dim objSongList                                                                   'SelectMethod 2

  SelectMethod = 1
  ' SelectMethod NowPlaying = 1
  ' SelectMethod UseSQLQuery = 2

' SelectMethod UseSQL = 3

  ' SelectMethod SelectedSongs = 4

'   SampleID = 13123                                                                  'Usualy Set in another part of the script
'Random SampleID Code (Remove if SampleID known)
  Set iter = SDB.Database.OpenSQL("SELECT DISTINCT Songs.ID FROM Songs ORDER BY RANDOM() Limit 1")
  While Not iter.EOF
    SampleID = iter.StringByIndex(0)
  iter.Next
  Wend
'End of random SampleID code
  Value TypeNewValue Name = "Mamma Mia"
  Set objSongList = SDB.NewSongList                                                 'SelectMethod 2 and 3 SDB.NewSongList
  
  Select Case SelectMethod
    Case 1
      Set objSongData = SDB.Player.CurrentSong                                      'SDB.Player.CurrentSong
    Case 2
      Set objSongListiterator = SDB.Database.QuerySongs("AND Songs.ID=" & SampleID) 'SDB.Database.QuerySongs

Case 3 SQLString = "SELECT Field Name FROM Database Table WHERE Database Table.ID = " & SampleID Set objSongStringiterator = SDB.Database.OpenSQL(SQLString) 'SDB.Database.OpenSQL

    Case 4
      Set objSongList = SDB.SelectedSongList                                        'SDB.SelectedSongList
'       Set objSongList = SDB.CurrentSongList                                       'SDB.CurrentSongList
'       Set objSongList = SDB.AllVisibleSongList                                    'SDB.AllVisibleSongList
    Case Else
      SDB.MessageBox "Incorrect Select Method ", mtError, Array(mbOK)               'SDB.MessageBox
      Exit Sub
  End Select
  
  For iCounter = 0 to objSongList.count - 1                                         'SelectMethod 4 SongLists
    While Not objSongListiterator.EOF                                               'SelectMethod 2 Iterator
    While Not objSongStringiterator.EOF                                               'SelectMethod 3
      Set objSongData = objSongListiterator.Item                                    'SelectMethod 2
      objSongList.Add(objSongData)                                                  'SelectMethod 2
      Set objSongData = objSongList.Item(iCounter)                                  'SelectMethod 4
      Value TypeValue Name = objSongData.Value Name                                 'SelectMethod 1, 2 and 4
      SDB.MessageBox "Value = '" & Value TypeValue Name & "'", mtError, Array(mbOK) 'SelectMethod 4 (2 and 3)

Value TypeValue Name = objSongStringiterator.StringByIndex(0) 'SelectMethod 3

    objSongListiterator.Next                                                        'SelectMethod 2
    objSongStringiterator.Next                                                        'SelectMethod 3
    Wend                                                                            'SelectMethod 2 and 3
  Next                                                                              'SelectMethod 4
  Set objSongListiterator=Nothing                                                   'SelectMethod 2
  Set objSongStringiterator=Nothing                                                   'SelectMethod 3

  SDB.MessageBox "Value = '" & Value TypeValue Name & "'", mtError, Array(mbOK)

'  objSongData.Value Name = Value TypeNewValue Name 'Commented Out For Safety       'SelectMethod 1, 2 and 4
'  objSonglist.UpdateAll                            'Commented Out For Safety       'UpdateAll
                         'SelectMethod 1, 2 and 4 Updates db and writes tags (if checked in options)
End Sub

Converted Sample Method 2

'
' MediaMonkey Script
'
' NAME: WikiSample.vbs
'
' Template Author: MoDementia
' Time, DATE :  22:31, 09 April 2008
'
'Sample of Scripting Code Read and Write Method(s)
'A working script to show database results using various selection methods
'
'MediaMonkey\Scripts\Scripts.ini entry
'
'<-- Start ini code
'[WikiSample]                                                                       'Format of the Scripts.ini file
'Filename=WikiSample.vbs
'Procname=WikiSample
'Order=99
'DisplayName=WikiSample
'Description=Displays the raw database value of the MMWikipage item
'Language=VBScript
'ScriptType=0
'<-- End ini code

 Sub WikiSample
  Dim SelectMethod, SampleID, StringNewTitle
'   Dim SQLString                                                                     'SelectMethod 3
  Dim objSongList                                                                   'SelectMethod 2

  SelectMethod = 2
  ' SelectMethod NowPlaying = 1
  ' SelectMethod UseSQLQuery = 2
  ' SelectMethod UseSQL = 3
  ' SelectMethod SelectedSongs = 4
 
'   SampleID = 13123                                                                   'Usualy Set in another part of the script
'Random SampleID Code (Remove if SampleID known)
  Set iter = SDB.Database.OpenSQL("SELECT DISTINCT Songs.ID FROM Songs ORDER BY RANDOM() Limit 1")
  While Not iter.EOF
    SampleID = iter.StringByIndex(0)
  iter.Next
  Wend
  Set iter=Nothing
'End of random SampleID code
  StringNewTitle = "Mamma Mia"
  Set objSongList = SDB.NewSongList                                                 'SelectMethod 2 and 3 SDB.NewSongList
 
  Select Case SelectMethod
    Case 1
      Set objSongData = SDB.Player.CurrentSong                                      'SDB.Player.CurrentSong
    Case 2
      Set objSongListiterator = SDB.Database.QuerySongs("AND Songs.ID=" & SampleID) 'SDB.Database.QuerySongs
    Case 3
      SQLString = "SELECT SongTitle FROM Songs WHERE Songs.ID = " & SampleID
      Set objSongStringiterator = SDB.Database.OpenSQL(SQLString)                     'SDB.Database.OpenSQL
    Case 4
      Set objSongList = SDB.SelectedSongList                                        'SDB.SelectedSongList
'       Set objSongList = SDB.CurrentSongList                                       'SDB.CurrentSongList
'       Set objSongList = SDB.AllVisibleSongList                                    'SDB.AllVisibleSongList
    Case Else
      SDB.MessageBox "Incorrect Select Method ", mtError, Array(mbOK)               'SDB.MessageBox
      Exit Sub
  End Select
 
'   For iCounter = 0 to objSongList.count - 1                                         'SelectMethod 4 SongLists
    While Not objSongListiterator.EOF                                               'SelectMethod 2
'     While Not objSongStringiterator.EOF                                               'SelectMethod 3
      Set objSongData = objSongListiterator.Item                                    'SelectMethod 2
      objSongList.Add(objSongData)                                                  'SelectMethod 2
'       Set objSongData = objSongList.Item(iCounter)                                  'SelectMethod 4
      StringTitle = objSongData.Title                                 'SelectMethod 1, 2 and 4
      SDB.MessageBox "Value = '" & StringTitle & "'", mtError, Array(mbOK) 'SelectMethod 4 (2 and 3)
'       StringTitle = objSongStringiterator.StringByIndex(0)                   'SelectMethod 3
    objSongListiterator.Next                                                        'SelectMethod 2
'     objSongStringiterator.Next                                                        'SelectMethod 3
    Wend                                                                            'SelectMethod 2 and 3
'   Next                                                                              'SelectMethod 4
  Set objSongListiterator=Nothing                                                   'SelectMethod 2
'   Set objSongStringiterator=Nothing                                                   'SelectMethod 3
  
  SDB.MessageBox "Value = '" & StringTitle & "'", mtError, Array(mbOK)

'  objSongData.Title = StringNewTitle 'Commented Out For Safety       'SelectMethod 1, 2 and 4
'  objSonglist.UpdateAll                            'Commented Out For Safety       'UpdateAll
                         'SelectMethod 1, 2 and 4 Updates db and writes tags (if checked in options)
End Sub