|
-
Aug 1st, 2017, 08:42 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Counting List Item and Play Alarm for Each Item (Must be exceeded to my given limit!)
Hello friends. I have a program I'm working on today. But I want to tell you about a feature I can not do. First, I will talk about the objects in the program. In total there are 2 lists, 2 buttons and 1 checkbox. The first list, our words are listed. When the first button is clicked, the program lists the second list according to the number of words. If checkbox is checked and the second button is clicked, the program will sound an alarm for a group of words exceeding 10 words. (For example, if there are 10 birds in the second list, the bird sound plays, and if there are 10 cats in the second list, the cat sound plays.) My prototype has this error that, the second list (ie the list of which the word count number are written.) the program only sounds an alarm for the bird. If the dog is replaced instead of the cat after, the alarm does not plays because everything is sequential. (So there was no artificial intelligence, it was only imposition.) I'm adding my project with all alarm sounds and files for better understanding. (I had to delete 2 audio files. Because the size was too much. You already notice.) Please help me, thank you.
My Project File via VBForums: Attachment 150167
*Imagine my first list; (Huh! The place of the words may be mixed. No problem my program can count words.)
Bird
Bird
Bird
Bird
Bird
Bird
Bird
Bird
Bird
Cat
Cat
Cat
Cat
Cat
Cat
Cat
Cat
Cat
Cat
Cat
Dog
Dog
Dog
Dog
Dog
Dog
Dog
Dog
Dog
Dog
Dog
*Imagine my second list;
Bird - 9
Cat - 11
Dog - 10
*In short, I have 10 cats. And now alarm should play. (10 and 10 in the form of multiples. ie 10-20-30-...-250) My prototype does not play sound because in the second list Cat is not first item. Bird is first item of list.
*If you download my project firstly you should add items to list via my add buttons. After then you should calculate words. Finally you can check to checkbox and click last button.
Last edited by erenagar; Aug 1st, 2017 at 10:58 PM.
Reason: I forgot to add the Project.
-
Aug 1st, 2017, 04:08 PM
#2
Thread Starter
Addicted Member
Re: Counting List Item and Play Alarm for Each Item (Must be exceeded to my given lim
I almost for the first time have a question outside the internet. And there is no response please friends...
-
Aug 1st, 2017, 04:49 PM
#3
Re: Counting List Item and Play Alarm for Each Item (Must be exceeded to my given lim
At what point do you want the 'alarm' to sound? When you click the button and if there are 10 cats, 10 dogs or 10 whatevers?
If so, in your button click event, put something like this (seeing as how you know how many of each there are).
Code:
dim x as integer
dim y as integer
for x = 0 to list2.listcount -1
list2.listindex = x
y = instr(list2.text, " - ")
if val(mid(list2.text, y +1) = 10 then
'play your alarm here
msgbox ("You have 10 " & mid(list2.text,1,y-1)
end if
x = x +1
code not tested---might have errors...!!!
-
Aug 1st, 2017, 04:53 PM
#4
Re: Counting List Item and Play Alarm for Each Item (Must be exceeded to my given lim
Now, if you already have the VALUE saved for each item (number of them), you won't need to do the loop like I showed, check EACH value (assuming some sort of variable --- or even an array) and if = 10, play your 'alarm'.
-
Aug 1st, 2017, 05:12 PM
#5
Thread Starter
Addicted Member
Re: Counting List Item and Play Alarm for Each Item (Must be exceeded to my given lim
 Originally Posted by SamOscarBrown
At what point do you want the 'alarm' to sound? When you click the button and if there are 10 cats, 10 dogs or 10 whatevers?
If so, in your button click event, put something like this (seeing as how you know how many of each there are).
Code:
dim x as integer
dim y as integer
for x = 0 to list2.listcount -1
list2.listindex = x
y = instr(list2.text, " - ")
if val(mid(list2.text, y +1) = 10 then
'play your alarm here
msgbox ("You have 10 " & mid(list2.text,1,y-1)
end if
x = x +1
code not tested---might have errors...!!!
In my first text Alarm's mean is only sound. I mean if 10 cats or 20 cats or 300 dogs etc. appears sound will play. If you download my project you can see clearly sir. I will try your code when I go home. But would you be able to review my project file if you are available before me?
-
Aug 1st, 2017, 06:13 PM
#6
Re: Counting List Item and Play Alarm for Each Item (Must be exceeded to my given lim
Replace all your code with the following and try, i hope it works as you want.
vb Code:
Option Explicit Private Const SND_APPLICATION = &H80 ' look for application specific association Private Const SND_ALIAS = &H10000 ' name is a WIN.INI [sounds] entry Private Const SND_ALIAS_ID = &H110000 ' name is a WIN.INI [sounds] entry identifier Private Const SND_ASYNC = &H1 ' play asynchronously Private Const SND_FILENAME = &H20000 ' name is a file name Private Const SND_LOOP = &H8 ' loop the sound until next sndPlaySound Private Const SND_MEMORY = &H4 ' lpszSoundName points to a memory file Private Const SND_NODEFAULT = &H2 ' silence not default, if sound not found Private Const SND_NOSTOP = &H10 ' don't stop any currently playing sound Private Const SND_NOWAIT = &H2000 ' don't wait if the driver is busy Private Const SND_PURGE = &H40 ' purge non-static events for task Private Const SND_RESOURCE = &H40004 ' name is a resource name or atom Private Const SND_SYNC = &H0 ' play synchronously (default) Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long Private Sub Command1_Click() Dim i As Long Dim j As Long List4.Clear For i = 0 To List3.ListCount - 1 For j = 0 To List4.ListCount - 1 If List3.List(i) = List4.List(j) Then List4.ItemData(j) = List4.ItemData(j) + 1 Exit For End If Next j If j = List4.ListCount Then List4.AddItem List3.List(i) List4.ItemData(List4.NewIndex) = 1 End If Next i For j = 0 To List4.ListCount - 1 List4.List(j) = List4.List(j) & " - " & List4.ItemData(j) Next j End Sub Private Sub Command2_Click() ' On Error Resume Next Dim j As Long Dim f() As String If Check1.Value = 1 Then For j = 0 To List4.ListCount - 1 f = Split(List4.List(j), " - ") If f(1) / 10 = Int(f(1) / 10) Then ' play sound only when count is exactly 10, 20, 30, etc..., remove this check if you want to play when count is just greater than 10 If Int(f(1) / 10) >= 1 And Int(f(1) / 10) <= 25 Then If f(0) = "(IP Engelli)" Then PlayWarnSound "ipengelli.wav" ElseIf f(0) = "(Alanlar Boþ)" Then PlayWarnSound "alanlarbos.wav" ElseIf f(0) = "(Þifre Basit)" Then PlayWarnSound "sifrebasit.wav" ElseIf f(0) = "(K.Adý Ayný)" Then PlayWarnSound "kullaniciadiayni.wav" End If End If End If Next End If List4.Clear End Sub Private Sub PlayWarnSound(strFile As String) PlaySound App.Path & "\" & strFile, ByVal 0&, SND_FILENAME Or SND_ASYNC MsgBox "You exceeded the limit. Alarm plays." End Sub Private Sub Command3_Click() List3.AddItem "(IP Engelli)" List3.AddItem "(IP Engelli)" End Sub Private Sub Command4_Click() List3.AddItem "(Alanlar Boþ)" List3.AddItem "(Alanlar Boþ)" End Sub Private Sub Command5_Click() List3.AddItem "(Þifre Basit)" List3.AddItem "(Þifre Basit)" End Sub Private Sub Command6_Click() List3.AddItem "(K.Adý Ayný)" List3.AddItem "(K.Adý Ayný)" End Sub
-
Aug 1st, 2017, 06:20 PM
#7
Re: Counting List Item and Play Alarm for Each Item (Must be exceeded to my given lim
I'm not crazy about downloading zip files....(although I do on occasion, and provide many on this forum). Besides, looks like xy has given you what you need probably.
-
Aug 1st, 2017, 06:44 PM
#8
Thread Starter
Addicted Member
Re: Counting List Item and Play Alarm for Each Item (Must be exceeded to my given lim
 Originally Posted by 4x2y
Replace all your code with the following and try, i hope it works as you want.
vb Code:
Option Explicit Private Const SND_APPLICATION = &H80 ' look for application specific association Private Const SND_ALIAS = &H10000 ' name is a WIN.INI [sounds] entry Private Const SND_ALIAS_ID = &H110000 ' name is a WIN.INI [sounds] entry identifier Private Const SND_ASYNC = &H1 ' play asynchronously Private Const SND_FILENAME = &H20000 ' name is a file name Private Const SND_LOOP = &H8 ' loop the sound until next sndPlaySound Private Const SND_MEMORY = &H4 ' lpszSoundName points to a memory file Private Const SND_NODEFAULT = &H2 ' silence not default, if sound not found Private Const SND_NOSTOP = &H10 ' don't stop any currently playing sound Private Const SND_NOWAIT = &H2000 ' don't wait if the driver is busy Private Const SND_PURGE = &H40 ' purge non-static events for task Private Const SND_RESOURCE = &H40004 ' name is a resource name or atom Private Const SND_SYNC = &H0 ' play synchronously (default) Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long Private Sub Command1_Click() Dim i As Long Dim j As Long List4.Clear For i = 0 To List3.ListCount - 1 For j = 0 To List4.ListCount - 1 If List3.List(i) = List4.List(j) Then List4.ItemData(j) = List4.ItemData(j) + 1 Exit For End If Next j If j = List4.ListCount Then List4.AddItem List3.List(i) List4.ItemData(List4.NewIndex) = 1 End If Next i For j = 0 To List4.ListCount - 1 List4.List(j) = List4.List(j) & " - " & List4.ItemData(j) Next j End Sub Private Sub Command2_Click() ' On Error Resume Next Dim j As Long Dim f() As String If Check1.Value = 1 Then For j = 0 To List4.ListCount - 1 f = Split(List4.List(j), " - ") If f(1) / 10 = Int(f(1) / 10) Then ' play sound only when count is exactly 10, 20, 30, etc..., remove this check if you want to play when count is just greater than 10 If Int(f(1) / 10) >= 1 And Int(f(1) / 10) <= 25 Then If f(0) = "(IP Engelli)" Then PlayWarnSound "ipengelli.wav" ElseIf f(0) = "(Alanlar Boþ)" Then PlayWarnSound "alanlarbos.wav" ElseIf f(0) = "(Þifre Basit)" Then PlayWarnSound "sifrebasit.wav" ElseIf f(0) = "(K.Adý Ayný)" Then PlayWarnSound "kullaniciadiayni.wav" End If End If End If Next End If List4.Clear End Sub Private Sub PlayWarnSound(strFile As String) PlaySound App.Path & "\" & strFile, ByVal 0&, SND_FILENAME Or SND_ASYNC MsgBox "You exceeded the limit. Alarm plays." End Sub Private Sub Command3_Click() List3.AddItem "(IP Engelli)" List3.AddItem "(IP Engelli)" End Sub Private Sub Command4_Click() List3.AddItem "(Alanlar Boþ)" List3.AddItem "(Alanlar Boþ)" End Sub Private Sub Command5_Click() List3.AddItem "(Þifre Basit)" List3.AddItem "(Þifre Basit)" End Sub Private Sub Command6_Click() List3.AddItem "(K.Adý Ayný)" List3.AddItem "(K.Adý Ayný)" End Sub
You're a great person 4x2y! You save code (Almost half.) and you resolve my mistakes. Thanks a lot...
-
Aug 1st, 2017, 09:02 PM
#9
Re: Counting List Item and Play Alarm for Each Item (Must be exceeded to my given lim
If your problem solved then mark this thread as resolved
-
Aug 1st, 2017, 09:53 PM
#10
Re: Counting List Item and Play Alarm for Each Item (Must be exceeded to my given lim
And Rate xy's post (little 6-pointed start in his post) to 'thank him'.
-
Aug 1st, 2017, 10:59 PM
#11
Thread Starter
Addicted Member
Re: Counting List Item and Play Alarm for Each Item (Must be exceeded to my given lim
I handle it my friends, thanks again!
Tags for this Thread
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
|