Visual Basic - Writing to a File

Bilow -  
 Bilow -
Hello,

I am a beginner in Visual Basic and I would like to know how to save data (a name for example) to a text file.

Thank you in advance for your help.
Configuration: Windows Vista Internet Explorer 7.0

6 answers

  1. progggg Posted messages 336 Status Member 23
     
    Under Microsoft Visual Basic?
    --
    The brain's performance is such that nowadays almost everyone has one (pearls of the bac).
    0
  2. Bilow
     
    Hi progggg,

    Yes, under Microsoft Visual Basic 2008 (c).
    Does the editor software (IDE) change anything in the code?
    0
  3. le neurone isolé
     
    Hello

    There is a good chance that even the old methods are still operational:

    open "file.txt" for output as #3 ' the # is optional
    print #3, "georges"
    close #3
    (c) 1979 - mathusalem

    * the number (here 3) is chosen by you. It's the file handle (basic handle, of course)
    * the mode (here output) defines the authorized operations. You can use input to read the file, append to add data at the end, but not input/output because you can't read & write simultaneously in a text file (that's reserved for files with direct access)

    more info => <F1>
    0
  4. Bilow
     
    Hello,

    thank you for responding so quickly :)
    but... that doesn't work.

    The compiler displays a lot of errors, such as "open is undeclared."

    Thank you for your help.
    0
  5. Polux31 Posted messages 7219 Status Member 1 204
     
    Hello,

    The isolated neuron would need to do an update ... ^^

    Sub writeFile() Dim fp As Short Dim path As String fp = FreeFile path = "D:\file_Test.txt" FileOpen(fp, path, OpenMode.Append) PrintLine(fp, " Hello ") FileClose(fp) End Sub


    There you go ...

    ;o)
    --
    “What we conceive well is clearly stated, And the words to say it come easily.”
    Nicolas Boileau
    0
  6. Bilow
     
    Hello Polux31,

    Thank you, it works!

    Are there possibilities to write in a specific place?
    For example: Write at the beginning of the file, or at the end, etc.

    For those who are interested, I noticed that Print() simply writes the text, Printline() writes the text and goes to the next line.

    Best regards,
    Bilow.
    0