borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Probobly Easy Question Here...)Next Topic (Registry in VB 4) New Topic New Poll Post Reply
AndreaVB Forum : VB General : TIMER QUESTION!!!
Poster Message
inertiascience
Level: Guest


icon TIMER QUESTION!!!

Hi, Um this is like my um 5th question of the day (I hope the basic-ness of these questions are not getting to ya JL lol) but how do you create a timer? Im looking for some code to create a 10 second thing with a sound playing once the timer runs out.

[Edited by inertiascience on 23-02-2003 at 01:23 AM GMT]

[Edited by inertiascience on 24-02-2003 at 09:51 PM GMT]

23-02-2003 at 07:22 AM
| Quote Reply
vbgen
Level: Moderator

Registered: 10-10-2002
Posts: 876
icon Re: Timer?

what i think you are asking:

create a timer that will run for ten seconds, then play a sound after the ten seconds are over, and not while the ten seconds are running.

if i got that right...


'place a timer control on your form
'set its interval to 10000
'note: 1000 intervals = 1 second
Private Sub Timer1_Timer()
    Beep
    'then, if you want to stop the timer
    'from beeping again..
    Timer1.Enabled = False
End Sub


if you want to add a sound from a file, then
place a windows media player control on your form
access is through the components of the toolbox
right click on the toolbox then select components
search for windows media player control, then check it.
create an instance, then place this in the form's code instead:

Private Sub Form_Load()
    MediaPlayer1.AutoStart = False
End Sub

Private Sub Timer1_Timer()
    MediaPlayer1.FileName = "c:windowsmediathe microsoft sound.wav"
    MediaPlayer1.Play
    'then, if you want to stop the timer
    'from beeping again..
    Timer1.Enabled = False
End Sub


hope it works for you.

____________________________
Been busy trying to take a second degree <--it's not working out...

23-02-2003 at 09:23 AM
View Profile Send Email to User Show All Posts | Quote Reply
inertiascience
Level: Guest

icon Re: Timer?

Ty so much!!!    

24-02-2003 at 04:40 AM
| Quote Reply
inertiascience
Level: Guest

icon Re: Timer?

I have another question!! Um,is there a way to show the timer's interval in a label's caption as its counting down?

25-02-2003 at 01:20 AM
| Quote Reply
yronium
Level: Moderator


Registered: 14-04-2002
Posts: 907
icon Re: TIMER QUESTION!!!

1) Do you mean the Timer1.Interval Property? Assign it to a variable, and show it in Label1.Caption (what useful is it?).

2) Or do you mean the elapsed time running? In this case, you calculate the elapsed time, assign to a variable, and then in the Timer1_Timer event, set the Label1.Caption on this variable. This event occurs each timer interval (in milliseconds), so the label refreshes continuously.

Hope it helps




____________________________
Real Programmer can count up to 1024 on his fingers

25-02-2003 at 09:14 AM
View Profile Send Email to User Show All Posts | Quote Reply
vbgen
Level: Moderator

Registered: 10-10-2002
Posts: 876
icon Re: TIMER QUESTION!!!

if it's by the way i think you mean, then change the code to:

Private Sub Form_Load()
    MediaPlayer1.AutoStart = False
    Dim CountDown As Integer
    CountDown = Timer1.Interval
End Sub

Private Sub Timer1_Timer()
    CountDown = CountDown - 1000
    Label1.Caption = CountDown & "Seconds Left."
    MediaPlayer1.FileName = "c:windowsmediathe microsoft sound.wav"
    MediaPlayer1.Play
    'then, if you want to stop the timer
    'from repeating,
    Timer1.Enabled = False
End Sub


[Edited by vbgen on 25-02-2003 at 09:44 PM GMT]

____________________________
Been busy trying to take a second degree <--it's not working out...

25-02-2003 at 01:41 PM
View Profile Send Email to User Show All Posts | Quote Reply
win_dir
Level: VB Guru

Registered: 04-08-2002
Posts: 390
icon Re: TIMER QUESTION!!!

just thought i'd remind you as you seem to be a noobie that you will need to insert the media player control onto the form if you are using VBgens code(6th post).

you can do that by right clicking on the control toolbar --> right click --> components --> then tick whichever component you want

____________________________
We have a Mustek 5 M/Pix GSm@rt USB Digital Camera
for just £74.03 , offer only on until 30th February!

<AllDuck.com>      

Enquiries/Sales: 0845 430 9862
Fax: 0870 950 4532

25-02-2003 at 04:49 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
inertiascience
Level: Guest

icon Re: TIMER QUESTION!!!

LOL!! Im not *THAT* new to it win_dir   , I thank Vbgen for his assistance!       I had to make some modifications to his code, however, because I was using the newer style Windows Media Player 9 controls.  
I got through it though! :: is ever more extatic::     

26-02-2003 at 12:21 AM
| Quote Reply
AndreaVB Forum : VB General : TIMER QUESTION!!!
Previous Topic (Probobly Easy Question Here...)Next Topic (Registry in VB 4) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder