Results 1 to 5 of 5

Thread: text file writing

  1. #1

    Thread Starter
    Hyperactive Member Grunt's Avatar
    Join Date
    Oct 2004
    Location
    Las Vegas
    Posts
    499

    text file writing

    how come this is not working?

    Code:
    Dim bookname As String = "\books.txt"
            Dim objFileStream As New FileStream(Application.StartupPath & bookname, FileMode.Create, FileAccess.Write)
            Dim Addbook As New StreamWriter(objFileStream)
            txtName.Text = Names
            txtAddress.Text = Address
            Addbook.WriteLine(Names & Address)
            Addbook.Close()
    it creates the file, but does not write anything

  2. #2

    Thread Starter
    Hyperactive Member Grunt's Avatar
    Join Date
    Oct 2004
    Location
    Las Vegas
    Posts
    499
    nevermind. Got it.

    Code:
       Dim bookname As String = "\books.txt"
            Dim objFileStream As New FileStream(Application.StartupPath & bookname, FileMode.Create, FileAccess.Write)
            Dim Addbook As New StreamWriter(objFileStream)
            Addbook.Write(txtName.Text)
            Addbook.Close()

  3. #3
    Addicted Member
    Join Date
    Sep 2004
    Location
    Brooklyn
    Posts
    147
    txtName.Text = Names
    txtAddress.Text = Address
    Do you mean:

    Names = txtName.Text
    Address = txtAddress.Text

    Or do you declare Names and Address somewhere else?

    When I did this it worked perfectly:

    Addbook.WriteLine(txtName.Text & txtAddress.Text)

    By the way you probably want to put a & " " & or a & VBCrLf in there ...

  4. #4

    Thread Starter
    Hyperactive Member Grunt's Avatar
    Join Date
    Oct 2004
    Location
    Las Vegas
    Posts
    499
    curious as to what this means?

    "VBCrLf"

  5. #5
    Addicted Member
    Join Date
    Sep 2004
    Location
    Brooklyn
    Posts
    147
    That's a constant, it adds a Carriage Return/Line Feed - starts a new line, in other words.

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