Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. Option Explicit
  2. Public Const sDir As String = "G://Dir"
  3.  
  4. Public Declare Function sndPlaySound Lib "winmm.dll" _
  5. Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
  6. ByVal uFlags As Long) As Long
  7.  
  8. Function listFiles(ByVal sPath As String) As Variant
  9.  
  10. Dim vaArray As Variant
  11. Dim i As Integer
  12. Dim oFile As Object
  13. Dim oFSO As Object
  14. Dim oFolder As Object
  15. Dim oFiles As Object
  16.  
  17. Set oFSO = CreateObject("Scripting.FileSystemObject")
  18. Set oFolder = oFSO.GetFolder(sPath)
  19. Set oFiles = oFolder.Files
  20.  
  21. If oFiles.Count = 0 Then Exit Function
  22.  
  23. ReDim vaArray(1 To oFiles.Count)
  24. i = 1
  25. For Each oFile In oFiles
  26. vaArray(i) = oFile.Name
  27. i = i + 1
  28. Next
  29.  
  30. listFiles = vaArray
  31. End Function
  32.  
  33. Function playWav(sPath As String)
  34. If Dir(sPath) = "" Then
  35. Exit Function
  36. End If
  37. sndPlaySound sPath, 1
  38. End Function
  39.  
  40. Sub random()
  41. Static dirArray As Variant
  42. Static start As Integer
  43. If start = 0 Then
  44. dirArray = listFiles(sDir)
  45. start = start + 1
  46. End If
  47. Dim p As Integer
  48. Dim random As Integer
  49. random = Int((UBound(dirArray)) * Rnd())
  50. p = 0
  51. Call playWav(sDir & "/" & dirArray(random))
  52. MsgBox (UBound(dirArray))
  53. If UBound(dirArray) > 1 Then
  54. For p = random To UBound(dirArray) - 1
  55. dirArray(p) = dirArray(p + 1)
  56. Next p
  57. ReDim Preserve dirArray(0 To (UBound(dirArray) - 1))
  58. Else
  59. Call playWav(sDir & "/" & dirArray(random))
  60. start = 0
  61. End If
  62.  
  63. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement