Message box with sound in loop
Message box with sound in loop
Message box with sound in loop
Message box with sound in loop
Message box with sound in loop
Message box with sound in loop Message box with sound in loop Message box with sound in loop Message box with sound in loop Message box with sound in loop Message box with sound in loop Message box with sound in loop Message box with sound in loop
Message box with sound in loop Message box with sound in loop
Message box with sound in loop
Go Back  Xtreme Visual Basic Talk > > > Message box with sound in loop


Reply
 
Thread Tools Display Modes
  #1  
Old 07-25-2015, 01:02 AM
brybamo brybamo is offline
Newcomer
 
Join Date: Jul 2015
Posts: 14
Default Message box with sound in loop


Hello all,

I need help with a message box in my timer (actually there are two timers that are doing the same), its basically a countdown, when labels get to 0 and 1, the message box is activated with a sound, like an alarm.

What i´m looking to do is, when the message box it´s activated, to play the sound in a loop until you click "OK".

Can someone help me with the code?

Quote:
Private Sub Timer1_Tick_1(sender As Object, e As EventArgs) Handles Break.Tick

Label17.Text = Val(Label17.Text) - Val(1)

If Label17.Text = 0 Then
Label16.Text = Val(Label16.Text) - Val(1)
Label17.Text = 59

End If

If Label16.Text = 0 And Label17.Text = 1 Then
Break.Enabled = False
My.Computer.Audio.Play(My.Resources.Break, AudioPlayMode.Background)
MsgBox("Break is over")
Label17.Text = "00"
Label16.Text = 15

End If
Thank you in advance!
Reply With Quote
  #2  
Old 07-25-2015, 03:40 AM
brybamo brybamo is offline
Newcomer
 
Join Date: Jul 2015
Posts: 14
Default

I have another question about this timer, when the countdown gets to numbers from 1 to 9, they will show like this:

10:9
2:7

I would like these numbers to show with two digits, for example:

10:09
02:07

Is there any way i ca nmake it happen?
Reply With Quote
  #3  
Old 07-27-2015, 05:26 PM
Cerian Knight's Avatar
Cerian KnightMessage box with sound in loop Cerian Knight is offline
Polymath (in disciplina)

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 4,191
Default

With regard to the first post, look at using 'PlayMode.BackgroundLoop':
https://msdn.microsoft.com/en-us/lib...VS.100%29.aspx

With regard to the second post, look at using a 'User Defined Numeric Format' ("00" or "mm:ss"):
https://msdn.microsoft.com/en-us/lib...=vs.90%29.aspx
__________________
I got all the answers wrong on the GLAT, apparently even #9 (where I put a period in the middle of the box and labeled it 'singularity ripe for rapid inflation').
Reply With Quote
  #4  
Old 07-29-2015, 02:28 AM
brybamo brybamo is offline
Newcomer
 
Join Date: Jul 2015
Posts: 14
Default

Quote:
Originally Posted by Cerian Knight View Post
With regard to the first post, look at using 'PlayMode.BackgroundLoop':
https://msdn.microsoft.com/en-us/lib...VS.100%29.aspx

With regard to the second post, look at using a 'User Defined Numeric Format' ("00" or "mm:ss"):
https://msdn.microsoft.com/en-us/lib...=vs.90%29.aspx

thank you, i was able to make the message box play sound in a loop and stop it with the click.. but i stil ldont get it the User defined numeric format in "00".. Can someone provide an example of this please?

Lets say that i want all numbers in Label1 show in "00" format..
Reply With Quote
  #5  
Old 07-29-2015, 09:01 AM
Cerian Knight's Avatar
Cerian KnightMessage box with sound in loop Cerian Knight is offline
Polymath (in disciplina)

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 4,191
Default

Like this:
Code:
        Dim A As Integer = 1
        Label1.Text = Format(A, "00")
__________________
I got all the answers wrong on the GLAT, apparently even #9 (where I put a period in the middle of the box and labeled it 'singularity ripe for rapid inflation').
Reply With Quote
  #6  
Old 07-29-2015, 10:25 PM
brybamo brybamo is offline
Newcomer
 
Join Date: Jul 2015
Posts: 14
Default

Quote:
Originally Posted by Cerian Knight View Post
Like this:
Code:
        Dim A As Integer = 1
        Label1.Text = Format(A, "00")
cool, its working, so i need to do the same for each number from 1 to 9?

In this case, its a counter that will decrease 1 value to the label, so how can i make this work with the timer?

Its basically a timer of 15mins, once it reaches 00 and 01 in the Min and Secs labels it will trigger the alarm with the message box.
Attached Images
File Type: png 2015-07-29 22_22_02-GSD Ticket Notes - Sony.png (1.9 KB, 2 views)
Reply With Quote
  #7  
Old 07-30-2015, 12:38 PM
passel's Avatar
passelMessage box with sound in loop passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

A countdown in the timer is not always the most accurate way to go.
You should capture the time at the start.
You can add 15 minutes, or 60 minutes to the current time to indicate when you want the alarm to go off, and subtract the current time from the alarm time to see how much time is left.
You can use the standard time formatting strings to update the labels rather than create them yourself.

Code:
  Dim AlarmTime As DateTime

'Sixty minute Countdown.
  Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
    Timer1.Interval = 500 'update the label about twice a second
    AlarmTime = Now + TimeSpan.FromMinutes(60) ' set the alarm for 60 minutes from now
    Timer1.Enabled = True  'start updating the label and monitoring the alarm time
  End Sub

  Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    Dim deltaTime As TimeSpan = AlarmTime - Now  'How much time left
    If deltaTime.Milliseconds > 0 Then           'If more time before the alarm
      Label1.Text = deltaTime.ToString("mm\:ss") '  Show how much time remains

    Else 'Times up
      Timer1.Stop()
      Label1.Text = "Sound the alarm"
    End If
  End Sub
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #8  
Old 07-31-2015, 04:57 AM
brybamo brybamo is offline
Newcomer
 
Join Date: Jul 2015
Posts: 14
Default

Thank you passel, thats exactly what i was looking for...

I have a question, i have made some changes to the code, i added a MsgBox with a sound loop when the timer ends, when i click the "OK" button on the msgbox, it should automatically start the countdown again, without the need of clicking the start button again, but it´s not resetting the timer once the countdown finishes. What em i doing wrong?

Here´s the code:
Code:
    Private Sub Button4_Click_2(sender As Object, e As EventArgs) Handles Button4.Click


        VHDtmr.Interval = 100 'update the label about twice a second
        AlarmTime = Now + TimeSpan.FromMinutes(105) 
        VHDtmr.Enabled = True  'start updating the label and monitoring the alarm time


    End Sub


Private Sub VHDtmr_Tick(sender As Object, e As EventArgs) Handles VHDtmr.Tick


        Dim deltaTime As TimeSpan = AlarmTime - Now  'How much time left
        If deltaTime.Milliseconds > 0 Then           'If more time before the alarm
            Label22.Text = deltaTime.ToString("hh\:mm\:ss") '  Show how much time remains


        End If


        If Label22.Text = "00:00:00" Then    ' Trigger 
            VHDtmr.Enabled = False
            My.Computer.Audio.Play(My.Resources.VHDreminder, AudioPlayMode.BackgroundLoop)

            VHDalarm = MsgBox("VHD Reminder", vbOKOnly)
            Label22.Text = "01:45:00"

        End If

        If VHDalarm = vbOK Then

            VHDtmr.Enabled = True    ' For some reason, the timer doesn't start again, i also noticed it doesn't stop, if i put
'the the timer to 1 min, and the trigger of the MsgBox alarm to 50 secs, it will stop but then continue where it was left.
            My.Computer.Audio.Stop()
            

        End If



    End Sub

Last edited by Cerian Knight; 07-31-2015 at 03:37 PM. Reason: Changed quote tags to [code]...[/code] tags and added comment wrap
Reply With Quote
  #9  
Old 07-31-2015, 03:42 PM
Cerian Knight's Avatar
Cerian KnightMessage box with sound in loop Cerian Knight is offline
Polymath (in disciplina)

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 4,191
Default

After your stop the audio, try resetting the AlarmTime again by replicating the original code:
Code:
My.Computer.Audio.Stop()
AlarmTime = Now + TimeSpan.FromMinutes(105)
__________________
I got all the answers wrong on the GLAT, apparently even #9 (where I put a period in the middle of the box and labeled it 'singularity ripe for rapid inflation').

Last edited by Cerian Knight; 07-31-2015 at 03:48 PM.
Reply With Quote
  #10  
Old 07-31-2015, 10:32 PM
brybamo brybamo is offline
Newcomer
 
Join Date: Jul 2015
Posts: 14
Default

Quote:
Originally Posted by Cerian Knight View Post
After your stop the audio, try resetting the AlarmTime again by replicating the original code:
Code:
My.Computer.Audio.Stop()
AlarmTime = Now + TimeSpan.FromMinutes(105)


If i do this (im testing the timer with 1 minute):

Quote:
If VHDalarm = vbOK Then

My.Computer.Audio.Stop()
AlarmTime = Now + TimeSpan.FromMinutes(1) 'The timer gets to 00:00:00, the msgbox is triggered, when i click "OK", the timer stays in 00:00:00.. if i try to click "Start" again, timer does NOT start, stays at 00:00:59


End If
If i add "VHDtmr.Enabled = True" before the End If, same thing will happen, then the alarm gets like glitched and it doesn't start, even by stopping and starting again.

Last edited by brybamo; 07-31-2015 at 11:49 PM.
Reply With Quote
  #11  
Old 08-01-2015, 05:05 AM
brybamo brybamo is offline
Newcomer
 
Join Date: Jul 2015
Posts: 14
Default

Quote:
Originally Posted by passel View Post
A countdown in the timer is not always the most accurate way to go.
You should capture the time at the start.
You can add 15 minutes, or 60 minutes to the current time to indicate when you want the alarm to go off, and subtract the current time from the alarm time to see how much time is left.
You can use the standard time formatting strings to update the labels rather than create them yourself.

Code:
  Dim AlarmTime As DateTime

'Sixty minute Countdown.
  Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
    Timer1.Interval = 500 'update the label about twice a second
    AlarmTime = Now + TimeSpan.FromMinutes(60) ' set the alarm for 60 minutes from now
    Timer1.Enabled = True  'start updating the label and monitoring the alarm time
  End Sub

  Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    Dim deltaTime As TimeSpan = AlarmTime - Now  'How much time left
    If deltaTime.Milliseconds > 0 Then           'If more time before the alarm
      Label1.Text = deltaTime.ToString("mm\:ss") '  Show how much time remains

    Else 'Times up
      Timer1.Stop()
      Label1.Text = "Sound the alarm"
    End If
  End Sub
What changes can i make if i would like the timer to add minutes starting at 00:00 instead of a countdown?
Reply With Quote
  #12  
Old 08-02-2015, 02:39 AM
passel's Avatar
passelMessage box with sound in loop passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

I assume you mean to display the time counting up to the alarm time.
Without changing the rest of the logic, I would
1. Add a StartTime variable and
2. set it to Now when you set the alarm.
3. Then you can do the difference between Now and the StartTime to get elapsed time, and display it.
Code:
  Dim AlarmTime As DateTime
  Dim StartTime As DateTime

'Sixty minute Countdown time, displaying elapsed time.
  Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
    Timer1.Interval = 500 'update the label about twice a second
    StartTime = Now    'save start time for elapsed time display
    AlarmTime = StartTime + TimeSpan.FromMinutes(60) ' set the alarm for 60 minutes from now
    Timer1.Enabled = True  'start updating the label and monitoring the alarm time
  End Sub

  Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    Dim deltaTime As TimeSpan = AlarmTime - Now  'How much time left
    Dim elapsedTime as TimeSpan = Now - StartTime  'How much time has passed

    If deltaTime.Milliseconds > 0 Then           'If more time before the alarm
    '  Label1.Text = deltaTime.ToString("mm\:ss") '  Show how much time remains
      Label1.Text = elapsedTime.ToString("mm\:ss")
    Else 'Times up
      Timer1.Stop()
      Label1.Text = "Sound the alarm"
    End If
  End Sub
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #13  
Old 08-02-2015, 05:13 AM
brybamo brybamo is offline
Newcomer
 
Join Date: Jul 2015
Posts: 14
Default

Quote:
Originally Posted by passel View Post
I assume you mean to display the time counting up to the alarm time.
Without changing the rest of the logic, I would
1. Add a StartTime variable and
2. set it to Now when you set the alarm.
3. Then you can do the difference between Now and the StartTime to get elapsed time, and display it.
Code:
  Dim AlarmTime As DateTime
  Dim StartTime As DateTime

'Sixty minute Countdown time, displaying elapsed time.
  Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
    Timer1.Interval = 500 'update the label about twice a second
    StartTime = Now    'save start time for elapsed time display
    AlarmTime = StartTime + TimeSpan.FromMinutes(60) ' set the alarm for 60 minutes from now
    Timer1.Enabled = True  'start updating the label and monitoring the alarm time
  End Sub

  Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    Dim deltaTime As TimeSpan = AlarmTime - Now  'How much time left
    Dim elapsedTime as TimeSpan = Now - StartTime  'How much time has passed

    If deltaTime.Milliseconds > 0 Then           'If more time before the alarm
    '  Label1.Text = deltaTime.ToString("mm\:ss") '  Show how much time remains
      Label1.Text = elapsedTime.ToString("mm\:ss")
    Else 'Times up
      Timer1.Stop()
      Label1.Text = "Sound the alarm"
    End If
  End Sub

Cool, i got it now...


How can i go about to restart the timer once i click "OK" in the msgbox automatically. Without having to click the "Start" button again.

I have this code, but is not staring the timer again.


Quote:
Private Sub VHDtmr_Tick(sender As Object, e As EventArgs) Handles VHDtmr.Tick


Dim deltaTime As TimeSpan = AlarmTime - Now 'How much time left
If deltaTime.Milliseconds > 0 Then 'If more time before the alarm
Label22.Text = deltaTime.ToString("hh\:mm\:ss") ' Show how much time remains


End If


If Label22.Text = "00:00:00" Then ' Trigger
VHDtmr.Enabled = False
My.Computer.Audio.Play(My.Resources.VHDreminder, AudioPlayMode.BackgroundLoop)

VHDalarm = MsgBox("VHD Reminder", vbOKOnly)
Label22.Text = "01:45:00"

End If

If VHDalarm = vbOK Then

VHDtmr.Enabled = True ' For some reason, the timer doesn't start again, i also noticed it doesn't stop, if i put
'the the timer to 1 min, and the trigger of the MsgBox alarm to 50 secs, it will stop but then continue where it was left.
My.Computer.Audio.Stop()


End If
Reply With Quote
  #14  
Old 08-02-2015, 09:51 PM
passel's Avatar
passelMessage box with sound in loop passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

Cerian Knight already mentioned (and show a code snippet) in post #9, you need to set the AlarmTime again.

When you set AlarmTime to Now + some interval, you are setting it to the current time (and date actually) plus some interval, so if it is 3:00 and you add 15 minutes it will go off at 3:15.
If you want it to automatically go off again 15 minutes later (3:30), you have to set the AlarmTme to 3:30 by adding 15 minutes to Now again.

If you want it to go off every 15 minutes, set the AlarmTime and StartTime before showing the message box.
If you want it to go off 15 minutes after they hit OK, then set them after showing the message box.
Code:
  If VHDalarm = vbOK Then
    VHDtmr.Enabled = True 
    My.Computer.Audio.Stop()
    StartTime = Now
    AlarmTime = StartTime + TimeSpan.FromSeconds(60)
  End If
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.

Last edited by passel; 08-02-2015 at 09:57 PM.
Reply With Quote
  #15  
Old 08-05-2015, 12:24 AM
brybamo brybamo is offline
Newcomer
 
Join Date: Jul 2015
Posts: 14
Default

Attached is an example of what i am working on, there are a few timers on there, the only timer that is counting up to the alarm time is the "HOLD/MUTE Timer", all the others are countdowns to 00:00 and 3 alarms, please ignore the alarms.

I have this code for the "VHD´s Reminder", i need the timer to go off every 01:45:00, when it reaches 00:00:00, the timer gets disabled, the msgbox is triggered, once the msgbox comes up and the user clicks "OK", i need the timer enabled again and countdown to start again from 01:45:00 automatically, without the need of clicking the "Start" button again.

What is happening with this code is that when it gets to 00:00:00, i hit "OK" in the msgbox, the timer sets to 00:00:09 (im testing with setting the alarmtime to 10s), but the countdown does not start, it stays at 00:00:09. If i hit "Stop" button, the timer gets disabled and if i hit "Start" button again, it wont start from 5s again, stays at 00:00:09.

Here's the code i have for this timer and buttons:

Quote:
Dim AlarmTime As DateTime
Dim VHDalarm As MsgBoxResult


Private Sub Button4_Click_2(sender As Object, e As EventArgs) Handles Button4.Click


VHDtmr.Interval = 100 'update the label about twice a second
VHDtmr.Enabled = True 'start updating the label and monitoring the alarm time
AlarmTime = Now + TimeSpan.FromSeconds(5)

End Sub


Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click

Label22.Text = "01:45:00"
VHDtmr.Enabled = False 'Stop the timer

End Sub


Private Sub VHDtmr_Tick(sender As Object, e As EventArgs) Handles VHDtmr.Tick


Dim deltaTime As TimeSpan = AlarmTime - Now 'How much time left
If deltaTime.Milliseconds > 0 Then 'If more time before the alarm
Label22.Text = deltaTime.ToString("hh\:mm\:ss") ' Show how much time remains
End If

If Label22.Text = "00:00:00" Then
VHDtmr.Enabled = False
My.Computer.Audio.Play(My.Resources.VHDreminder, AudioPlayMode.BackgroundLoop)
VHDalarm = MsgBox("VHD Reminder", vbOKOnly)

End If

If VHDalarm = vbOK Then

VHDtmr.Enabled = True
My.Computer.Audio.Stop()
AlarmTime = Now + TimeSpan.FromSeconds(10)

End If
Attached Images
File Type: png 2015-08-05 00_13_32-GSD Ticket Notes - Sony.png (13.2 KB, 6 views)
Reply With Quote
  #16  
Old 08-06-2015, 10:17 PM
brybamo brybamo is offline
Newcomer
 
Join Date: Jul 2015
Posts: 14
Default

Quote:
Originally Posted by passel View Post
Cerian Knight already mentioned (and show a code snippet) in post #9, you need to set the AlarmTime again.

When you set AlarmTime to Now + some interval, you are setting it to the current time (and date actually) plus some interval, so if it is 3:00 and you add 15 minutes it will go off at 3:15.
If you want it to automatically go off again 15 minutes later (3:30), you have to set the AlarmTme to 3:30 by adding 15 minutes to Now again.

If you want it to go off every 15 minutes, set the AlarmTime and StartTime before showing the message box.
If you want it to go off 15 minutes after they hit OK, then set them after showing the message box.
Code:
  If VHDalarm = vbOK Then
    VHDtmr.Enabled = True 
    My.Computer.Audio.Stop()
    StartTime = Now
    AlarmTime = StartTime + TimeSpan.FromSeconds(60)
  End If

I finally got it, thank you very much for the help...


Quote:
If Label22.Text = "00:00:00" Then

VHDtmr.Enabled = False
My.Computer.Audio.Play(My.Resources.VHDreminder, AudioPlayMode.BackgroundLoop)
AlarmTime = Now + TimeSpan.FromSeconds(10)
VHDalarm = MsgBox("VHD Reminder", vbOKOnly)

End If


If VHDalarm = vbOK Then
VHDtmr.Enabled = True
My.Computer.Audio.Stop()
Reply With Quote
  #17  
Old 10-19-2015, 03:26 AM
samuelozano2015 samuelozano2015 is offline
Newcomer
 
Join Date: Oct 2015
Posts: 1
Default

Quote:
Originally Posted by Cerian Knight View Post
Like this:
Code:
        Dim A As Integer = 1
        Label1.Text = Format(A, "00")
Thank you so much for this. I have tried and also worked on my end. ;-)
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Message box with sound in loop
Message box with sound in loop
Message box with sound in loop Message box with sound in loop
Message box with sound in loop
Message box with sound in loop
Message box with sound in loop Message box with sound in loop Message box with sound in loop Message box with sound in loop Message box with sound in loop Message box with sound in loop Message box with sound in loop
Message box with sound in loop
Message box with sound in loop
 
Message box with sound in loop
Message box with sound in loop
 
-->