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
'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
please can you explain why using the variable ftp wont work?
spent hours trying to work out why.
thank you
smiler44
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
Code:
Dim fd 'file duration of song
Dim filetoplay ' the mp3 file to play
Global spt As String
Sub start()
' play music for pre determined time
Do Until Sheet1.TextBox2.Value > Sheet1.TextBox1.Value
Call randomlyselectsong
Loop
If Sheet1.CheckBox1.Value = True Then ' shutdown laptop
Call shutdown 'shut down laptop
End If
End Sub
Code:
Dim fs, f1, fc, s
Dim ftp
Sub randomlyselectsong()
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")
Randomize
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
Call RecursiveDir(Directory)
filetoplay = """C:\path" & ftp
Shell "C:\path\wmplayer /play /close " & filetoplay
counter = counter + 1
pause (a)
End If
j = j + 1
Next
Loop
End Sub
'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
Code:
Public Sub RecursiveDir(ByVal currdir As String)
'Dim ftp
'ftp = "4 Non Blondes - What's Up.mp3"
Range("A1").Select
Range("a1").Value = FileInfo("C:\path\mp3", "4 Non Blondes - What's Up.mp3", 27)
' Range("a1").Value = FileInfo("C:\path", ftp, 27)
End Sub
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
End Function
please can you explain why using the variable ftp wont work?
spent hours trying to work out why.
thank you
smiler44
Last edited by a moderator: