# [SOLVED] sound in visual studio express 2010



## tech5563 (Jun 7, 2011)

i have tried from the simple method of playing a sound to the most complex and yet still i get no sound from my form. i have made a basic dart score board program and all works fine i just wanted to add some sound to those high scores as follows:-

Public Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim sp As Media.SoundPlayer = New Media.SoundPlayer("C:\Users\Alan\documents\visual studio 2010\Projects\dart2\dart2\180.WAV")
Dim theNumber1 As Integer = Convert.ToInt32(Me.TextBox3.Text)
If TextBox1.Text = " " Then
TextBox1.Text = 0
End If
If TextBox1.Text = "180" Then
sp.PlaySync()
' Process.Start("C:\Users\Alan\documents\visual studio 2010\Projects\dart2\dart2\UTOPIA.WAV")
End If

now when i type in 180 as a score everything appears to play ie: the WAV file lasts approx 4 secs and theres a delay of 4 secs when 180 is entered, also on my volume control in windows you see the green bar go up as if audio is being played. but nothing is heard from the speakers(the WAV can be heard if played directly). or if i PROCESS the sound it pops up wmp and plays.

if anyone has any ideas i would be very gratefull


----------



## Ninjaboi (Dec 27, 2010)

*Re: sound in visual studio express 2010*

Hello tech5563!

Try taking a look at this link here:

SoundPlayer Class (System.Media)

Particularly look at the example code on that page. You seem to have everything correct as far as I can tell ( perhaps it'd be better if you lowercased the 'WAV' to 'wav'. Ex.: C:\Users\Alan\documents\visual studio 2010\Projects\dart2\dart2\180.*wav*". ).

I don't use Visual Basic though, so I'd be little help with the syntax.


----------



## tech5563 (Jun 7, 2011)

*Re: sound in visual studio express 2010*

Dim score As String = TextBox1.Text
If TextBox1.Text = score Then
AxWindowsMediaPlayer1.URL = "c:\Sounds\" & score & ".wav"
EndIf
used url and its now working fine thankyou for that link i have saved it for use 
on future projects thanyou


----------



## Ninjaboi (Dec 27, 2010)

*Re: sound in visual studio express 2010*

Your welcome, glad the link helped you :smile:.


----------

