|
-
Mar 23rd, 2008, 02:23 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] List Box Array and Sounds
Hello... Currently I have an array of 8 listboxes in VB6. Each item in my listbox plays a wav sound from a large file on my desktop called "Sounds".
I am using the sndPlaySound API.
The code I have to link everything up is:
Private Sub List1_Click(Index As Integer)
Const sSoundFolder = "C:\Users\Chris\Desktop\Sounds\"
Dim sToneFile As String
Dim x%
If List1(n).ListIndex < 0 Then Exit Sub
sToneFile = sSoundFolder & List1(n).List(List1(n).ListIndex) & ".wav"
x% = sndPlaySound(sToneFile, SND_ASYNC Or SND_NODEFAULT)
End Sub
My items are entered like this:
List1(0).AddItem "Home 1"
List1(0).AddItem "Home 2"
List1(0).AddItem "Home 3"
...
List1(1).AddItem "Office 1"
List1(1).AddItem "Office 2"
...
List1(2).AddItem "School 1"
List1(2).AddItem "School 2"
List1(2).AddItem "School 3"
...
I now need to go into my desktop "Sounds" file on my desktop and organize things better. I will create folders inside the "Sounds" file called "Home", "Office", "School", and so on. I will move all wav files to their relative folders.
How can I update my code so that when a new listbox is active in my program the array will go to the different folders?
To link List1(0) with: "C:\Users\Chris\Desktop\Sounds\Home\"
To link List1(1) with: "C:\Users\Chris\Desktop\Sounds\Office\"
To link List1(2) with: "C:\Users\Chris\Desktop\Sounds\School\"
... ... ... all the way to List1(7)
Thanks for your help.
-
Mar 23rd, 2008, 04:14 PM
#2
Re: List Box Array and Sounds
Please use [ Code ] tags with your code, that will make it easier to read.
Move Const sSoundFolder to the Declaration part of the Form,
also declare an array of 8 elements sSubFolders()
Code:
Option Explicit
Const sSoundFolder = "C:\Users\Chris\Desktop\Sounds\"
Dim sSubFolders(0 to 7) As String
Dim n As Integer
Private Form_Load()
Dim i As Integer
Dim FileName as String
Dim WavName as String
'-- make sure all 8 sub folders are correct
sSubFolders(0) = "Home\"
sSubFolders(1) = "Office\"
sSubFolders(2) = "School\"
sSubFolders(3) = "Home2\"
sSubFolders(4) = "Home3\"
sSubFolders(5) = "Home4\"
sSubFolders(6) = "Home5\"
sSubFolders(7) = "Home6\"
'-- use this loop to add all filenames into 8 lists,
'-- you don't need to know what they are, Dir() function can find them.
For i = 0 to 7
FileName = Dir(sSoundFolder & sSubFolders(i) & "*.wav")'-- find first wav file
Do While Len(FileName)
WavName = Left(FileName, Len(FileName) - 4) '-- filename without ext.
List1(i).AddItem WavName
FileName = Dir() '-- find next wav file in the same sub folder
Loop
Next
End Sub
Code:
Private Sub List1_Click(Index As Integer)
Dim sToneFile As String
Dim x%
n = Index '-- don't forget this
If List1(n).ListIndex < 0 Then Exit Sub
sToneFile = sSoundFolder & sSubFolders(n) & List1(n).List(List1(n).ListIndex) & ".wav"
x% = sndPlaySound(sToneFile, SND_ASYNC Or SND_NODEFAULT)
End Sub
Last edited by anhn; Mar 23rd, 2008 at 09:52 PM.
-
Mar 23rd, 2008, 06:51 PM
#3
Thread Starter
Fanatic Member
Re: List Box Array and Sounds
I have that entered and I am getting a "complile error: type mismatch", and VB highlights the first &
I also changed it to sSubFolders ... I added the 's' because the declaration has an 's'.
For i = 0 To 7
FileName = Dir(sSoundFolder & sSubFolders & "*.wav")
Do While Len(FileName)
WavName = Left(FileName, Len(FileName) - 4)
List1(i).AddItem WavName
FileName = Dir() '-- find next wav file in the same sub folder
Loop
... I see that you have written that this code will find the first .wav.
In my program, I have a begin button:
List1(n).ListIndex = 2
It goes to the second item in the listbox and starts there. Will this interfere with that?
I even have a replay command:
-
Mar 23rd, 2008, 06:53 PM
#4
Thread Starter
Fanatic Member
Re: List Box Array and Sounds
Replay:
Call List1_Click(n)
Just curious. Thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|