Results 1 to 11 of 11

Thread: [RESOLVED] Counting List Item and Play Alarm for Each Item (Must be exceeded to my given limit!)

  1. #1

    Thread Starter
    Addicted Member erenagar's Avatar
    Join Date
    Jul 2014
    Posts
    154

    Resolved [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.

  2. #2

    Thread Starter
    Addicted Member erenagar's Avatar
    Join Date
    Jul 2014
    Posts
    154

    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...

  3. #3
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,622

    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...!!!

  4. #4
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,622

    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'.

  5. #5

    Thread Starter
    Addicted Member erenagar's Avatar
    Join Date
    Jul 2014
    Posts
    154

    Re: Counting List Item and Play Alarm for Each Item (Must be exceeded to my given lim

    Quote Originally Posted by SamOscarBrown View Post
    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?

  6. #6
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    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:
    1. Option Explicit
    2.  
    3. Private Const SND_APPLICATION = &H80         '  look for application specific association
    4. Private Const SND_ALIAS = &H10000     '  name is a WIN.INI [sounds] entry
    5. Private Const SND_ALIAS_ID = &H110000    '  name is a WIN.INI [sounds] entry identifier
    6. Private Const SND_ASYNC = &H1         '  play asynchronously
    7. Private Const SND_FILENAME = &H20000     '  name is a file name
    8. Private Const SND_LOOP = &H8         '  loop the sound until next sndPlaySound
    9. Private Const SND_MEMORY = &H4         '  lpszSoundName points to a memory file
    10. Private Const SND_NODEFAULT = &H2         '  silence not default, if sound not found
    11. Private Const SND_NOSTOP = &H10        '  don't stop any currently playing sound
    12. Private Const SND_NOWAIT = &H2000      '  don't wait if the driver is busy
    13. Private Const SND_PURGE = &H40               '  purge non-static events for task
    14. Private Const SND_RESOURCE = &H40004     '  name is a resource name or atom
    15. Private Const SND_SYNC = &H0         '  play synchronously (default)
    16. Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
    17.  
    18. Private Sub Command1_Click()
    19.     Dim i As Long
    20.     Dim j As Long
    21.    
    22.     List4.Clear
    23.     For i = 0 To List3.ListCount - 1
    24.         For j = 0 To List4.ListCount - 1
    25.             If List3.List(i) = List4.List(j) Then
    26.                 List4.ItemData(j) = List4.ItemData(j) + 1
    27.                 Exit For
    28.             End If
    29.         Next j
    30.         If j = List4.ListCount Then
    31.             List4.AddItem List3.List(i)
    32.             List4.ItemData(List4.NewIndex) = 1
    33.         End If
    34.     Next i
    35.    
    36.     For j = 0 To List4.ListCount - 1
    37.         List4.List(j) = List4.List(j) & " - " & List4.ItemData(j)
    38.     Next j
    39. End Sub
    40.  
    41.  
    42. Private Sub Command2_Click()
    43. '    On Error Resume Next
    44.     Dim j As Long
    45.     Dim f() As String
    46.     If Check1.Value = 1 Then
    47.         For j = 0 To List4.ListCount - 1
    48.             f = Split(List4.List(j), " - ")
    49.             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
    50.                 If Int(f(1) / 10) >= 1 And Int(f(1) / 10) <= 25 Then
    51.                     If f(0) = "(IP Engelli)" Then
    52.                         PlayWarnSound "ipengelli.wav"
    53.                     ElseIf f(0) = "(Alanlar Boþ)" Then
    54.                         PlayWarnSound "alanlarbos.wav"
    55.                     ElseIf f(0) = "(Þifre Basit)" Then
    56.                         PlayWarnSound "sifrebasit.wav"
    57.                     ElseIf f(0) = "(K.Adý Ayný)" Then
    58.                         PlayWarnSound "kullaniciadiayni.wav"
    59.                     End If
    60.                 End If
    61.             End If
    62.         Next
    63.     End If
    64.     List4.Clear
    65. End Sub
    66.  
    67. Private Sub PlayWarnSound(strFile As String)
    68.     PlaySound App.Path & "\" & strFile, ByVal 0&, SND_FILENAME Or SND_ASYNC
    69.     MsgBox "You exceeded the limit. Alarm plays."
    70. End Sub
    71.  
    72. Private Sub Command3_Click()
    73.     List3.AddItem "(IP Engelli)"
    74.     List3.AddItem "(IP Engelli)"
    75. End Sub
    76.  
    77. Private Sub Command4_Click()
    78.     List3.AddItem "(Alanlar Boþ)"
    79.     List3.AddItem "(Alanlar Boþ)"
    80. End Sub
    81.  
    82. Private Sub Command5_Click()
    83.     List3.AddItem "(Þifre Basit)"
    84.     List3.AddItem "(Þifre Basit)"
    85. End Sub
    86.  
    87. Private Sub Command6_Click()
    88.     List3.AddItem "(K.Adý Ayný)"
    89.     List3.AddItem "(K.Adý Ayný)"
    90. End Sub



  7. #7
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,622

    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.

  8. #8

    Thread Starter
    Addicted Member erenagar's Avatar
    Join Date
    Jul 2014
    Posts
    154

    Re: Counting List Item and Play Alarm for Each Item (Must be exceeded to my given lim

    Quote Originally Posted by 4x2y View Post
    Replace all your code with the following and try, i hope it works as you want.
    vb Code:
    1. Option Explicit
    2.  
    3. Private Const SND_APPLICATION = &H80         '  look for application specific association
    4. Private Const SND_ALIAS = &H10000     '  name is a WIN.INI [sounds] entry
    5. Private Const SND_ALIAS_ID = &H110000    '  name is a WIN.INI [sounds] entry identifier
    6. Private Const SND_ASYNC = &H1         '  play asynchronously
    7. Private Const SND_FILENAME = &H20000     '  name is a file name
    8. Private Const SND_LOOP = &H8         '  loop the sound until next sndPlaySound
    9. Private Const SND_MEMORY = &H4         '  lpszSoundName points to a memory file
    10. Private Const SND_NODEFAULT = &H2         '  silence not default, if sound not found
    11. Private Const SND_NOSTOP = &H10        '  don't stop any currently playing sound
    12. Private Const SND_NOWAIT = &H2000      '  don't wait if the driver is busy
    13. Private Const SND_PURGE = &H40               '  purge non-static events for task
    14. Private Const SND_RESOURCE = &H40004     '  name is a resource name or atom
    15. Private Const SND_SYNC = &H0         '  play synchronously (default)
    16. Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
    17.  
    18. Private Sub Command1_Click()
    19.     Dim i As Long
    20.     Dim j As Long
    21.    
    22.     List4.Clear
    23.     For i = 0 To List3.ListCount - 1
    24.         For j = 0 To List4.ListCount - 1
    25.             If List3.List(i) = List4.List(j) Then
    26.                 List4.ItemData(j) = List4.ItemData(j) + 1
    27.                 Exit For
    28.             End If
    29.         Next j
    30.         If j = List4.ListCount Then
    31.             List4.AddItem List3.List(i)
    32.             List4.ItemData(List4.NewIndex) = 1
    33.         End If
    34.     Next i
    35.    
    36.     For j = 0 To List4.ListCount - 1
    37.         List4.List(j) = List4.List(j) & " - " & List4.ItemData(j)
    38.     Next j
    39. End Sub
    40.  
    41.  
    42. Private Sub Command2_Click()
    43. '    On Error Resume Next
    44.     Dim j As Long
    45.     Dim f() As String
    46.     If Check1.Value = 1 Then
    47.         For j = 0 To List4.ListCount - 1
    48.             f = Split(List4.List(j), " - ")
    49.             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
    50.                 If Int(f(1) / 10) >= 1 And Int(f(1) / 10) <= 25 Then
    51.                     If f(0) = "(IP Engelli)" Then
    52.                         PlayWarnSound "ipengelli.wav"
    53.                     ElseIf f(0) = "(Alanlar Boþ)" Then
    54.                         PlayWarnSound "alanlarbos.wav"
    55.                     ElseIf f(0) = "(Þifre Basit)" Then
    56.                         PlayWarnSound "sifrebasit.wav"
    57.                     ElseIf f(0) = "(K.Adý Ayný)" Then
    58.                         PlayWarnSound "kullaniciadiayni.wav"
    59.                     End If
    60.                 End If
    61.             End If
    62.         Next
    63.     End If
    64.     List4.Clear
    65. End Sub
    66.  
    67. Private Sub PlayWarnSound(strFile As String)
    68.     PlaySound App.Path & "\" & strFile, ByVal 0&, SND_FILENAME Or SND_ASYNC
    69.     MsgBox "You exceeded the limit. Alarm plays."
    70. End Sub
    71.  
    72. Private Sub Command3_Click()
    73.     List3.AddItem "(IP Engelli)"
    74.     List3.AddItem "(IP Engelli)"
    75. End Sub
    76.  
    77. Private Sub Command4_Click()
    78.     List3.AddItem "(Alanlar Boþ)"
    79.     List3.AddItem "(Alanlar Boþ)"
    80. End Sub
    81.  
    82. Private Sub Command5_Click()
    83.     List3.AddItem "(Þifre Basit)"
    84.     List3.AddItem "(Þifre Basit)"
    85. End Sub
    86.  
    87. Private Sub Command6_Click()
    88.     List3.AddItem "(K.Adý Ayný)"
    89.     List3.AddItem "(K.Adý Ayný)"
    90. End Sub
    You're a great person 4x2y! You save code (Almost half.) and you resolve my mistakes. Thanks a lot...

  9. #9
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    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



  10. #10
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,622

    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'.

  11. #11

    Thread Starter
    Addicted Member erenagar's Avatar
    Join Date
    Jul 2014
    Posts
    154

    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
  •  



Click Here to Expand Forum to Full Width