Results 1 to 11 of 11

Thread: Error using My.Computer

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2012
    Posts
    75

    Error using My.Computer

    With a Console Application with target framework .NET Framework 4.8 a statement of the form

    Code:
    My.Computer.FileSystem.WriteAllText(...)
    works fine. But with one with target framework .NET 7.0 I get an error

    Code:
    { } Namespace xx.My
    	
    BC30456 'Computer' is not a member of xx.My
    (where xx is the name of the Application).

    What do I need to do to fix this? Thanks!
    Last edited by dday9; Sep 11th, 2023 at 09:17 AM.

  2. #2
    Fanatic Member
    Join Date
    Jun 2019
    Posts
    545

    Re: Error using My.Computer

    Just forget all those My.* helpers and use the real classes. For your case it is System.IO.File.WriteAllText().

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2012
    Posts
    75

    Re: Error using My.Computer

    Thanks. Yes that works. However I now have another problem. I believe the following statement works under .NET Framework 4.8:

    Code:
    My.Computer.Keyboard.SendKeys("x{ENTER}", True)
    The Microsoft documentation* says that SendKeys is a class in the System.Windows.Forms namespace, but this namespace doesn't appear to exist under .NET 7.0. Is SendKeys still supported? How do I access it?


    * https://learn.microsoft.com/en-us/do...owsdesktop-7.0)
    Last edited by dday9; Sep 11th, 2023 at 09:17 AM.

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,372

    Re: Error using My.Computer

    There’s a SendKeys.Send(String) Method in System.Windows.Forms.dll, but you wouldn’t want to use that in a .Net. Core application

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    109,991

    Re: Error using My.Computer

    Quote Originally Posted by coffent View Post
    The Microsoft documentation* says that SendKeys is a class in the System.Windows.Forms namespace, but this namespace doesn't appear to exist under .NET 7.0. Is SendKeys still supported? How do I access it?
    Of course the namespace exists but you're creating a Console application, so why would the required assembly be referenced? It shouldn't be a surprise that the System.Windows.Forms namespace contains types intended to be used in Windows Forms applications. Using SendKeys in a Console app is extremely dodgy as they are not GUI apps, so assuming a GUI is inappropriate.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    109,991

    Re: Error using My.Computer

    Quote Originally Posted by coffent View Post
    With a Console Application with target framework .NET Framework 4.8 a statement of the form

    My.Computer.FileSystem.WriteAllText(...)

    works fine. But with one with target framework .NET 7.0 I get an error

    { } Namespace xx.My

    BC30456 'Computer' is not a member of xx.My

    (where xx is the name of the Application).

    What do I need to do to fix this? Thanks!
    .NET Core (.NET 5 and later are based on .NET Core) has been built from the ground up so anything it includes has been implemented from scratch. Most of what was available in .NET Framework has been reimplemented in .NET Core but not everything. VB support was initially poor in .NET Core and it was VB-specific functionality like the My namespace that held it up. The My namespace exists but doesn't include all the functionality that it did in .NET Framework. My does make some things easier but there's a lot of things that are really just duplication and this is one of them. That WriteAllText method has no real advantage over System.IO.File.WriteAllText so there seems little reason to use a VB-specific method when you use the same methods as a C# developer in so many other places. If you're going to use My at all then then really ought to use it everywhere you can or else you're making your code inconsistent. Personally, I might use it on a few occasions where it adds genuine value by simplifying some task but there are few examples of this.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Feb 2012
    Posts
    75

    Re: Error using My.Computer

    Thanks paul and jmcilhinney for your helpful responses. I'll have to rethink how I want to do this (as a very amateur programmer).

  8. #8
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,501

    Re: Error using My.Computer

    I get you're trying to write to a file and send some keys, but could you explain what it is you're actually trying to accomplish? I.e. what does the application you're writing do?

    Answering that might help us help you better.
    "Code is like humor. When you have to explain it, it’s bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  9. #9
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,687

    Re: Error using My.Computer

    Quote Originally Posted by coffent View Post
    Thanks. Yes that works. However I now have another problem. I believe the following statement works under .NET Framework 4.8:

    Code:
    My.Computer.Keyboard.SendKeys("x{ENTER}", True)
    The Microsoft documentation* says that SendKeys is a class in the System.Windows.Forms namespace, but this namespace doesn't appear to exist under .NET 7.0. Is SendKeys still supported? How do I access it?


    * https://learn.microsoft.com/en-us/do...owsdesktop-7.0)
    If this is a console app why aren't you using Console.Write or Console.WriteLine?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  10. #10
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,385

    Re: Error using My.Computer

    Well, for starters it isn't the same thing. Secondly, because it's not the same thing. And thirdly, I have no idea since as pointed out by JMC, sendKeys from a console app doesn't make much sense.


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  11. #11
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,687

    Re: Error using My.Computer

    Quote Originally Posted by techgnome View Post
    Well, for starters it isn't the same thing. Secondly, because it's not the same thing. And thirdly, I have no idea since as pointed out by JMC, sendKeys from a console app doesn't make much sense.


    -tg
    So I was addressing the latter thinking that the OP was just writing to the Console.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width