-
Nov 22nd, 2022, 07:09 AM
#1
Thread Starter
New Member
BC30456 'Computer' is not a member of [Solution / Project name].My
I'm using Visual Studio 2019 - Windows Form App - Visual basic - This is my code:
Public Sub PlayBackgroundSoundFile()
My.Computer.Audio.Play("C':\Sound.wav")
End Sub
I've used this Sub previously in other projects and it's worked fine but I've just created a new Solution / Project and I get this error message:
BC30456 'Computer' is not a member of [Solution / Project name].My
It seems such a simple issue but I can't fix it
-
Nov 22nd, 2022, 08:34 AM
#2
Re: BC30456 'Computer' is not a member of [Solution / Project name].My
First things first, you have posted in the CodeBank forum, which is for sharing working code samples, not asking questions. I have notified the mods and they will move the thread. Please do not create a duplicate thread.
-
Nov 22nd, 2022, 08:38 AM
#3
Re: BC30456 'Computer' is not a member of [Solution / Project name].My
As for the issue, which .NET version are you targeting? I'm guessing it's .NET 5.
-
Nov 22nd, 2022, 09:10 AM
#4
Re: BC30456 'Computer' is not a member of [Solution / Project name].My
Welcome to VBForums! 
I have moved this thread from our "CodeBank - Visual Basic .NET" forum to our "Visual Basic .NET" forum
-
Nov 22nd, 2022, 11:59 AM
#5
Thread Starter
New Member
Re: BC30456 'Computer' is not a member of [Solution / Project name].My
First: Sorry I posted my question in the wrong forum and thanks for moving it for me.
Second: Sorry, I don't know which .NET version I'm targeting how do I tell? And which one should I be targeting? I'm just writing a very simple little Windows app.
-
Nov 22nd, 2022, 05:17 PM
#6
Re: BC30456 'Computer' is not a member of [Solution / Project name].My
You would have selected the .NET version when creating the solution/project. To find out after the fact, open up the project's properties (Project > [Name] Properties) and under the Application tab, tell us what it says under Target framework.
-
Nov 22nd, 2022, 07:42 PM
#7
Re: BC30456 'Computer' is not a member of [Solution / Project name].My
I suspect what's happened is that you have targeted .NET 5. I'm not sure but I don't think that all the My features had been reimplemented in .NET 5. If you upgrade to VS 2022 and target .NET 6 or 7 then I think you should be OK with that code. I don't think that you can target anything later than .NET 5 in VS 2019 but I could be wrong. The alternative is to target .NET Framework rather than .NET Core (.NET 5 and later are based on .NET Core). When you create a new project, all the project templates that target .NET Framework specifically say so in the name. If you want to target .NET Framework, it's a good idea to type "framework" in the filter box in the New Project dialogue to exclude other projects and ensure you don't select the wrong one.
-
Nov 23rd, 2022, 10:53 AM
#8
Thread Starter
New Member
Re: BC30456 'Computer' is not a member of [Solution / Project name].My
Thanks for really helpful replies.
I checked as you told me and found the target framework I had invoked was .NET Core 3.1
The earlier project that was working ok used .NET Framework 4.5
I have now changed my new project to use .NET Framework 4.7.2 - And it now works perfectly!
I need to read up and understand what .NET Core and Framework is all about!!!
Just one more thing, instead of using My.Computer.Audio.Play("C':\Sound.wav") I should really move Sound.wav to 'Resources' so that it installs when I publish the project. Any help with this would be gratefully received.
Thanks again for all your help.
-
Nov 24th, 2022, 10:06 PM
#9
Re: BC30456 'Computer' is not a member of [Solution / Project name].My
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Nov 24th, 2022, 10:41 PM
#10
Re: BC30456 'Computer' is not a member of [Solution / Project name].My
You can also use the SoundPlayer class, which has no dependency on the VB My namespace.
-
Nov 25th, 2022, 04:26 PM
#11
Thread Starter
New Member
Re: BC30456 'Computer' is not a member of [Solution / Project name].My
Now got all working how I want, and also read up about .NET Core and Framework, so it's been a great learning curve.
Thanks again, and signing off
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
|