Results 1 to 4 of 4

Thread: [RESOLVED] Streamwiter/Reader

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2003
    Posts
    22

    Resolved [RESOLVED] Streamwiter/Reader

    Hi,

    I have a project where numerical data which is entered into text and combo boxes forms the string 'values' and needs to be written to a sales file and then read from this file to produce a sales report at the same time when the 'Store' buton is clicked at the bottom of the form. I'm trying to use the Streamwriter and StreamReader classes to achieve this. The MSDN help is confusing me - does anyone know of some good online reference material for these classes? Any help would be appreciated.

  2. #2
    Addicted Member techwizz's Avatar
    Join Date
    Apr 2005
    Location
    U.S.A.
    Posts
    246

    Re: Streamwiter/Reader

    Here is a good example.

    Its free...
    http://yourcodes.com/index/modules.p...download&cid=8

    Its called .txt writer.

    Look at that source code.

  3. #3
    Frenzied Member dinosaur_uk's Avatar
    Join Date
    Sep 2004
    Location
    Jurassic Park
    Posts
    1,098

    Re: Streamwiter/Reader

    To Read Files

    At the top of your file
    VB Code:
    1. Imports System.IO

    then in the event
    VB Code:
    1. Dim sr as StreamReader
    2. sr = io.file.OpenText(filepath)
    3. Dim al as New ArrayList
    4.  
    5. Do While sr.peek <> -1
    6. al.add(sr.readline)
    7. Loop
    8.  
    9. sr.DiscardBufferedData
    10. sr.close

    to write the values back
    VB Code:
    1. Dim sw as StreamWriter
    2. If IO.file.exists(filepath) = False Then
    3. sw = io.file.CreateText(filepath) 'If you want to create a text
    4. Else
    5. sw = io.file.AppendText(filepath)
    6. Endif
    7.  
    8. sw.writeline("Blah blah blah")
    9.  
    10. sw.flush
    11. sw.close
    12. sw = nothing
    If you find my thread helpful, please remember to rate me

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Aug 2003
    Posts
    22

    Smile

    Thanks a lot for your help - it's proven really useful!

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