I found some code on the internet and have chopped and changed it around but for the life of me I cannot understand why the use of a variable will not work. The code randomly selects an mp3 file and goes on to play it.
The variable is to get the running time of the mp3 file.
if I don't use a variable it works fine but I need to use a variable
Dim fd 'file duration of song
Dim filetoplay ' the mp3 file to play
Global spt As String
' play music for pre determined time
Do Until Sheet1.TextBox2.Value > Sheet1.TextBox1.Value
If Sheet1.CheckBox1.Value = True Then ' shutdown laptop
Call shutdown 'shut down laptop
Dim fs, f1, fc, s
Dim counter ' used to just lay 10 randon songs used with do until and loop
Dim a ' amount of time to pause for while song plays
'other wise next song play immediately
counter = 0
Do Until counter = 10 ' just allows 10 files to be randomly selected
' could remove the Do until loop
Set fs = CreateObject("scripting.filesystemobject")
Set f = fs.GetFolder("C:\users\Dirk pitt\Documents\Dads Music")
i = CInt((Rnd() * f.Files.Count) + 1)
j = 1
For Each fi In f.Files
If j = i Then
ftp = fi.Name 'fi, randomly selected song
filetoplay = """C:\path" & ftp
Shell "C:\path\wmplayer /play /close " & filetoplay
counter = counter + 1
j = j + 1
'this is where is fails. if I unrem dim ftp, ' Range("a1").Value = FileInfo("C:\path", ftp, 27)
and rem Range("a1").Value = FileInfo("C:\path\mp3", "4 Non Blondes - What's Up.mp3", 27)
I get the word length returned as the value, why?
if I then unrem 'ftp = "4 Non Blondes - What's Up.mp3"
it works fine
Public Sub RecursiveDir(ByVal currdir As String)
'ftp = "4 Non Blondes - What's Up.mp3"
Range("a1").Value = FileInfo("C:\path\mp3", "4 Non Blondes - What's Up.mp3", 27)
' Range("a1").Value = FileInfo("C:\path", ftp, 27)
Function FileInfo(path, filename, item) As Variant
' this gets the file duration
Dim objShell As IShellDispatch4
Dim objFolder As Folder3
Dim objFolderItem As FolderItem2
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(path)
Set objFolderItem = objFolder.ParseName(filename)
FileInfo = objFolder.GetDetailsOf(objFolderItem, item)
Set objShell = Nothing
Set objFolder = Nothing
Set objFolderItem = Nothing
please can you explain why using the variable ftp wont work?
spent hours trying to work out why.