Results 1 to 2 of 2

Thread: Line Input

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2003
    Location
    Binghamton, New York
    Posts
    11

    Line Input

    I am having trouble with Streamreader and Stream writer. I don't understand them very well. I am trying to do a simple task:
    I want to read an entire file into a text box (which works well using StreaReader (sr.Readto End).

    However, all I want to do is take that file and write it to a textbox one line at a time. After writing one line, I want to do some if- then stuff and then write the next line. I can easily write one line using the sr.steamline but everytime I embed an if-then statement, I get exceptions.


    My goal is just to do this:

    Read a file
    Write one line
    If "shall" is in the line then put the line in a temporary string
    Go to the next line until the document is done.

  2. #2
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    here's a quick example ...
    VB Code:
    1. [Color=Blue]Dim[/COLOR] sReader [Color=Blue]As[/COLOR] [Color=Blue]New[/COLOR] IO.StreamReader([Color=Blue]New[/COLOR] IO.FileStream("C:\test.txt", IO.FileMode.Open))
    2.             [Color=Blue]Dim[/COLOR] strLine [Color=Blue]As[/COLOR] [Color=Blue]String
    3. [/COLOR]            [Color=Blue]While[/COLOR] [Color=Blue]Not[/COLOR] sReader.Peek
    4.                 strLine = sReader.ReadLine [Color=Green]'///[/COLOR] [Color=Green]make[/COLOR] [Color=Green]the[/COLOR] [Color=Green]string[/COLOR] [Color=Green]strLine[/COLOR] [Color=Green]hold[/COLOR] [Color=Green]the[/COLOR] [Color=Green]current[/COLOR] [Color=Green]line[/COLOR] [Color=Green]of[/COLOR] [Color=Green]text[/COLOR] [Color=Green]being[/COLOR] [Color=Green]read[/COLOR] [Color=Green].[/COLOR] [Color=Green]
    5. [/COLOR]                [Color=Blue]If[/COLOR] [Color=Blue]Not[/COLOR] strLine.IndexOf("shall") = -1 [Color=Blue]Then[/COLOR] [Color=Green]'///[/COLOR] [Color=Green]if[/COLOR] [Color=Green]the[/COLOR] [Color=Green]line[/COLOR] [Color=Green]contains[/COLOR] [Color=Green]the[/COLOR] [Color=Green]word[/COLOR] [Color=Green]"[/COLOR] [Color=Green]shall[/COLOR] [Color=Green]"
    6. [/COLOR]                    [Color=Green]'///[/COLOR] [Color=Green]do[/COLOR] [Color=Green]stuff[/COLOR] [Color=Green].[/COLOR] [Color=Green]
    7. [/COLOR]                [Color=Blue]End[/COLOR] [Color=Blue]If
    8. [/COLOR]            [Color=Blue]End[/COLOR] [Color=Blue]While
    9. [/COLOR]            sReader.Close()
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

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