none
Please assist me in VB disc write. RRS feed

  • Question

  • I need your help, I have tons of data and do not know how to write it to a hard drive.

    VS 2017 - Community: Visual Basic

    The documentation says to "My.Computer.FileSystem.WriteAllText("C:\TestFolder1\test.txt",
    "This is new text to be added.",True)"

    but I only have "My.InternalXMLHelper"

    My VB does not have "My.Computer" anything.

    I am using "ConsoleApp.sln -- do I need a different foundation?

    Thanks,

    Dave


    • Edited by DaveFash_ Friday, January 12, 2018 3:12 PM
    Friday, January 12, 2018 3:12 PM

All replies

  • I need your help, I have tons of data and do not know how to write it to a hard drive.

    VS 2017 - Community: Visual Basic

    The documentation says to "My.Computer.FileSystem.WriteAllText("C:\TestFolder1\test.txt",
    "This is new text to be added.",True)"

    but I only have "My.InternalXMLHelper"

    My VB does not have "My.Computer" anything.

    I am using "ConsoleApp.sln -- do I need a different foundation?

    Thanks,

    Dave


    Hi

    There are MANY different ways to deal with loading/saving data depending on your needs.

    Here is an example showing 2 methods. (comment out one or the other if you want to try this example out) This is in a Windows Form Project.

    Option Strict On
    Option Explicit On
    Public Class Form1
      ' defining the path here allows it
      ' to be used in several places. Adjust
      ' it to suit your needs.
      Dim myPath As String = My.Computer.FileSystem.SpecialDirectories.Desktop & "\TestFile.txt"
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
    	My.Computer.FileSystem.WriteAllText(myPath, "This is new text to be added.", True)
    
    	' OR for saving a series of whole lines
    	' (say) in a collection such as an 
    	' array of strings etc
    
    	IO.File.WriteAllLines(myPath, {"This is the first line.", "SecondLine"})
    
      End Sub
    End Class


    Regards Les, Livingston, Scotland



    • Edited by leshay Friday, January 12, 2018 3:45 PM
    • Proposed as answer by Cor Ligthert Friday, January 12, 2018 5:44 PM
    Friday, January 12, 2018 3:43 PM
  • Dave,

    I think you're better to defer to System.IO for this.

    What are you trying to write to disk and where are you trying to write it to?


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Friday, January 12, 2018 4:44 PM
  • I used the IOFile option and it worked!!

    THank you SOOO much.

    The My.Computer is dead on my version of VB

    APPRECIATE IT!!

    Friday, January 12, 2018 4:51 PM

  • The My.Computer is dead on my version of VB

    APPRECIATE IT!!

    It may be missing an Imports statement.

    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Friday, January 12, 2018 4:56 PM
  • Or framework 1.x ;-)

    Success Cor


    Friday, January 12, 2018 5:43 PM
  • Hi DaveFash,

    If you solved your issue now, please remember to close your thread by marking the helpful post as answer, it is beneficial to other community members who face the same issue.

    Thanks for your understanding.

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, January 15, 2018 6:03 AM
    Moderator
  • Hi DaveFash,

    If you solved your issue now, please remember to close your thread by marking the helpful post as answer, it is beneficial to other community members who face the same issue.

    Thanks for your understanding.

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Hi Cherr,

    How is the weather in Shanghai, or have you another thing to discuss OT like this in the forum?

    Maybe you are ordered to do that, but if the mission of Wicresoft is to drop this message 10000 times in the forums, then maybe they can ask to put that in top of the forum to avoid mixing up questions with this kind of thrash. 


    Success Cor


    Monday, January 15, 2018 8:57 AM