Page 1 of 1

VBScript Scripting object question

Posted: Fri Jun 05, 2020 10:03 am
by ianbradbury67
hoping this is a simple question - my coding is a bit rusty!
I've written a script to trim redundant characters from the end of (for example) the album name. I want to make it generic so I can pass in the field I want to trim.
So far I've got:

Code: Select all

' Get list of selected tracks from MediaMonkey
	Set list = SDB.SelectedSongList 
	If list.count=0 Then 
		Set list = SDB.AllVisibleSongList 
	End If  

	If pField = "Title" Then
		tmp = list.item(0).Title
		If pField = "Album" Then
			tmp = list.item(0).AlbumName
			If pField = "Artist" Then
				tmp = list.item(0).ArtistName
				MsgBox "Invalid field name: " & pField, vbOKOnly + vbExclamation
				Exit Sub
			End If
		End If
	End If
But rather than the convoluted nested if statement (or a replacement case statement) I'd like to pick the field dynamically. Something like:
tmp = list.item(0).field(pField)

So I can use pField to pick the relevant field to edit?

Re: VBScript Scripting object question

Posted: Sun Jun 07, 2020 7:40 pm
by Peke
Why don't you use Simple Dropdown selection of desired field or even table/group selection of fields to trim?

It would be easier to maintain and debug.