Click here to Skip to main content
15,884,237 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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

1 solution

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:

C#
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);
     }
 }
}
 
Share this answer
 
v5
Comments
Awesomedudei 21-Apr-11 18:22pm    
Could you please recode it ?

been tryin to make this work for 15 hours ( Serious )
Awesomedudei 21-Apr-11 18:24pm    
Could you please recode it ?

been trying to make this work for 15 hours ( Serious )
Nish Nishant 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900