Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit
- Public Const sDir As String = "G://Dir"
- Public Declare Function sndPlaySound Lib "winmm.dll" _
- Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
- ByVal uFlags As Long) As Long
- Function listFiles(ByVal sPath As String) As Variant
- Dim vaArray As Variant
- Dim i As Integer
- Dim oFile As Object
- Dim oFSO As Object
- Dim oFolder As Object
- Dim oFiles As Object
- Set oFSO = CreateObject("Scripting.FileSystemObject")
- Set oFolder = oFSO.GetFolder(sPath)
- Set oFiles = oFolder.Files
- If oFiles.Count = 0 Then Exit Function
- ReDim vaArray(1 To oFiles.Count)
- i = 1
- For Each oFile In oFiles
- vaArray(i) = oFile.Name
- i = i + 1
- Next
- listFiles = vaArray
- End Function
- Function playWav(sPath As String)
- If Dir(sPath) = "" Then
- Exit Function
- End If
- sndPlaySound sPath, 1
- End Function
- Sub random()
- Static dirArray As Variant
- Static start As Integer
- If start = 0 Then
- dirArray = listFiles(sDir)
- start = start + 1
- End If
- Dim p As Integer
- Dim random As Integer
- random = Int((UBound(dirArray)) * Rnd())
- p = 0
- Call playWav(sDir & "/" & dirArray(random))
- MsgBox (UBound(dirArray))
- If UBound(dirArray) > 1 Then
- For p = random To UBound(dirArray) - 1
- dirArray(p) = dirArray(p + 1)
- Next p
- ReDim Preserve dirArray(0 To (UBound(dirArray) - 1))
- Else
- Call playWav(sDir & "/" & dirArray(random))
- start = 0
- End If
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement