speakers_86
Registered User.
- Local time
- Today, 09:04
- Joined
- May 17, 2007
- Messages
- 1,919
I have code that works, but when I try to simplify it, it doesn't. I mostly made this myself, but I did have some kind of reference I was looking at. Could somone tell me why?
The first question is what should those variables be declared as? Objects?
My next question is that why does that work, but this doesn't?
I have tried that, and even using some other variations with variables, but it never works. Why does the code above work but this does not?
The third question is about setting variables to Nothing. What things do we need to set to nothing? I know recordsets get set to nothing when done, but what of other types of variables?
Code:
Private Sub CreatePlaylist()
Set objapp = CreateObject("iTunes.Application")
Set colSources = objapp.sources
Set objSource = colSources.ItemByName("Library")
Set colPlaylists = objSource.Playlists
Set objplaylist = colPlaylists.ItemByName("Muse Playlist")
Set objLibrary = objapp.LibraryPlaylist
Set coltracks = objLibrary.Tracks
'Create Playlist
Set objplaylist = objapp.CreatePlaylist("Muse Playlist")
'Add first track and start playing
Set objsong = coltracks.ItemByName("Some Song Name")
objplaylist.AddTrack (objsong)
'Play playlist
iTunes.LibrarySource.Playlists.ItemByName("Muse Playlist").PlayFirstTrack
End Sub
The first question is what should those variables be declared as? Objects?
My next question is that why does that work, but this doesn't?
Code:
CreateObject("itunes.application").sources.ItemByName("Library").Playlists.ItemByName("Muse Playlist").AddTrack (objsong)
I have tried that, and even using some other variations with variables, but it never works. Why does the code above work but this does not?
The third question is about setting variables to Nothing. What things do we need to set to nothing? I know recordsets get set to nothing when done, but what of other types of variables?