Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
Hey there im trying to make this work , can someone please help me.
 
What i want is that when the timer reaches 275 it should play "RedBuffwarning.wav"
And when it reaches 299 it should play "Redbuff(1).wav"
 
<pre lang="cs">
private void timer5_Tick(object sender, EventArgs e)
     {
         barlizard.Increment(1);
         if (barlizard.Value == 275)
         {
             try
             {
                 var MySoundPlayer1 = new SoundPlayer("sounds\\RedBuffwarning.wav");
                 MySoundPlayer1.Play();
             }
             catch (Exception MyError1)
             {
                 MessageBox.Show("Wrong Somewhere: " + MyError1.Message);
             }
         }
         else
         {
             try
             {
                 var MySoundPlayer = new SoundPlayer("sounds\\RedBuff(1).wav");
                 MySoundPlayer.Play();
                 if (barlizard.Value == 299)
                     barlizard.Value = 0;
                 timer5.Stop();
             }
             catch (Exception MyError)
             {
                 MessageBox.Show("An error has occurred: " + MyError.Message);
             }
         }
     }
     private void buttonlizard_Click(object sender, EventArgs e)
     {
         timer5.Start();
     }
Posted 21-Apr-11 12:02pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Well you seem to be stopping the server on the first call - Value will be 1, you hit the else-block, play that other wave and then stop the timer. That does not go with what you mentioned in your post.
 
Check value for 275, play the first wave. Check for 299, play the second wave and then stop the timer. That's what you need to do there.
 
[Update]
----------
 
In response to your comment, here's an untested (for obvious reasons) code snippet that should do what you are trying to do:
 
private void timer5_Tick(object sender, EventArgs e)
{
 barlizard.Increment(1);
 
 if (barlizard.Value == 275)
 {
     try
     {
         var MySoundPlayer1 = new SoundPlayer("sounds\\RedBuffwarning.wav");
         MySoundPlayer1.Play();
     }
     catch (Exception MyError1)
     {
         MessageBox.Show("Wrong Somewhere: " + MyError1.Message);
     }
 }
 else if (barlizard.Value == 299)
 {
     try
     {
         barlizard.Value = 0;
         timer5.Stop();
 
         var MySoundPlayer = new SoundPlayer("sounds\\RedBuff(1).wav");
         MySoundPlayer.Play();
     }
     catch (Exception MyError)
     {
         MessageBox.Show("An error has occurred: " + MyError.Message);
     }
 }
}
  Permalink  
v5
Comments
Awesomedudei at 21-Apr-11 18:22pm
   
Could you please recode it ?
 
been tryin to make this work for 15 hours ( Serious )
Awesomedudei at 21-Apr-11 18:24pm
   
Could you please recode it ?
 
been trying to make this work for 15 hours ( Serious )
Nishant Sivakumar at 21-Apr-11 18:35pm
   
Check my updated answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 290
1 Jochen Arndt 150
2 Kornfeld Eliyahu Peter 149
3 PIEBALDconsult 110
4 Richard MacCutchan 105
0 OriginalGriff 6,080
1 DamithSL 4,648
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,624
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 21 Apr 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100