|
-
Dec 15th, 2011, 06:06 AM
#1
Re: Can I Call a Class from my main form?
It doesn't matter what you call the parameter in the PlaySound method. Since you have you're wave files as resources in your app I thought resourceName was a fitting name. But you need to use it, what you have is this:
Code:
Private Sub PlaySound(ByVal C As String)
My.Computer.Audio.Play(My.Resources.C, AudioPlayMode.Background)
End Sub
That will play the C resource regardless what you pass in since you don't use the string you're passing in: My.Resources.C is only referring to the C resource. My.Resources.ResourceManager.GetStream is used so you can pass in a string with the name of the resource. So for your code to work you should use:
Code:
Private Sub PlaySound(ByVal C As String)
My.Computer.Audio.Play(My.Resources.ResourceManager.GetStream(C), AudioPlayMode.Background)
End Sub
However now the name doesn't make sense. Since you could just as well call PlaySound like this:So why is the argument named C in this case when you ask it to play the "D"? If you like you can do this:
Code:
Private Sub PlaySound(ByVal tone As String)
My.Computer.Audio.Play(My.Resources.ResourceManager.GetStream(tone), AudioPlayMode.Background)
End Sub
Just name the parameter whatever you like that fits.
Last edited by Joacim Andersson; Dec 15th, 2011 at 06:11 AM.
-
Dec 15th, 2011, 11:03 AM
#2
Thread Starter
New Member
Re: Can I Call a Class from my main form?
 Originally Posted by Joacim Andersson
It doesn't matter what you call the parameter in the PlaySound method. Since you have you're wave files as resources in your app I thought resourceName was a fitting name. But you need to use it, what you have is this:
Code:
Private Sub PlaySound(ByVal C As String)
My.Computer.Audio.Play(My.Resources.C, AudioPlayMode.Background)
End Sub
That will play the C resource regardless what you pass in since you don't use the string you're passing in: My.Resources.C is only referring to the C resource. My.Resources.ResourceManager.GetStream is used so you can pass in a string with the name of the resource. So for your code to work you should use:
Code:
Private Sub PlaySound(ByVal C As String)
My.Computer.Audio.Play(My.Resources.ResourceManager.GetStream(C), AudioPlayMode.Background)
End Sub
However now the name doesn't make sense. Since you could just as well call PlaySound like this: So why is the argument named C in this case when you ask it to play the "D"? If you like you can do this:
Code:
Private Sub PlaySound(ByVal tone As String)
My.Computer.Audio.Play(My.Resources.ResourceManager.GetStream(tone), AudioPlayMode.Background)
End Sub
Just name the parameter whatever you like that fits.
I suppose that the argument is named C because I want it to play the key of C? In my first post on this thread I said that I was trying to get just C to work first, not D.
I changed it back to GetStream and it fails to play C.wav when I click cButton.
Was the second part of the code correct?
Code:
Private Sub PlaySound(ByVal C As String)
My.Computer.Audio.Play(My.Resources.ResourceManager.GetStream(C), AudioPlayMode.Background)
End Sub
Private Sub cButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
PlaySound(CType(sender, Button).Tag.ToString)
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|