Results 1 to 5 of 5

Thread: [RESOLVED] reading and writing to a text file

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2005
    Posts
    64

    Resolved [RESOLVED] reading and writing to a text file

    Can any one help I want to save variable values to a comma seperated txt file but I do not know how to use the file system. I tried using a code sample one of you gave me be it came up withso many error messages I gave up. It would not recognize this for example
    Dim sr As stream ' the word stream
    ' Open the file to read.
    sr = File.OpenText("c:\MyFile.txt") ' the word File
    And so-on it goes

  2. #2
    Frenzied Member Zakary's Avatar
    Join Date
    Mar 2005
    Location
    Canada, Quebec, Montreal
    Posts
    1,654

    Re: reading and writing to a text file

    You may use the StreamWriter instead

    VB Code:
    1. Dim sr As New IO.StreamWriter("c:\MyFile.txt")
    2. sr.WriteLine(Var1 & ";" Var2 &";" ...)
    3. sr.Close()
    Using VS 2010 on Fw4.0

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2005
    Posts
    64

    Re: reading and writing to a text file

    Thanks it works why do they make it s complicated it is one of the most used task there are yet try going to the help system there are no clear examples or anything I am begining to think it would be advantagous to get a good book that explains the simple tasks as well as the more complicated one Do you happen to know one (It must be reasonably priced I'm on a budget.

  4. #4
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    Re: reading and writing to a text file

    Quote Originally Posted by white_grass
    Thanks it works why do they make it s complicated it is one of the most used task there are yet try going to the help system there are no clear examples or anything I am begining to think it would be advantagous to get a good book that explains the simple tasks as well as the more complicated one Do you happen to know one (It must be reasonably priced I'm on a budget.
    What version are you using? I don't think it's any more complicated than it needs to be.. It's very fast, also. But regarding your help file question,

    http://support.microsoft.com/default...b;en-us;315828

    This is word for word what's in the VS 2003 help file (Only reading and writing are separated in the help files, whereas they are one article on MSDN) if I search for "read and write to a text file", or "read from a text file" or "write to a text file" - It's the very first displayed item in the MSDN Search, also.

    MSDN is your friend. Well, actually it's a cold, boring server, but it's really helpful if you put it to use.

    Bill
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Oct 2005
    Posts
    64

    Re: reading and writing to a text file

    that was a very useful tip I will remeber that. The problem I am haveing is that I am self taught and can manipulate VB access to do what I want but this is the first time I have used vb as a stand alone program. I'm slowly getting used to i though. anyway thanks for your helpyet again Im sure you will be hearing from me again sometime
    Jem

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