CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Oct 2001
    Location
    South Africa
    Posts
    4

    Reading from Sequential file

    I want to write from a sequential file into a string, then from that string into another seq file. My problem is that it reads only the first line of the file or until it reaches a comma (,) replacing the string each time.








  2. #2
    Join Date
    Jul 2001
    Location
    Mumbai,India
    Posts
    382

    Re: Reading from Sequential file

    Can you post the code?

    Regards,
    The Beret.


  3. #3
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868

    Re: Reading from Sequential file

    The FileSystemObject's TextStream class's ReadLine method reads until it finds LF or CRLF pair... will that work?


  4. #4
    Join Date
    Oct 2001
    Location
    South Africa
    Posts
    4

    Re: Reading from Sequential file

    Thanks for replies.
    I have added the code I use, but this does not work, because it reads the delimmeters(vbcrlf, commas, etc)in the file thus overwriting the string each time. Is there another way?
    PS. I want to manipulate the string, using the Mid$-function afterwards.Later more on that!
    Thanks qingbob

    Dim MyString as string

    private Sub ReadString()

    open "c:\TextFile.txt" for input as #1

    While Not EOF(1)

    input #1,MyString

    Wend

    Close #1
    End Sub






  5. #5
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Reading from Sequential file

    Try to use
    Line Input #1,MyString

    instead of
    input #1,MyString

    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  6. #6
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: Reading from Sequential file

    If you are looking to read an entire fiel into a variable complete with control characters, try this sample
    Start a new project. add a command Button
    Paste this code into the generral declartations section of the form.
    Run the program and click the button

    option Explicit

    private Sub Command1_Click()

    Dim a, strB
    a = "C:\Autoexec.bat"
    Open a for binary as #1
    strB = input(FileLen(a), #1)
    Close
    Cls
    print strB

    End Sub




    John G

  7. #7
    Join Date
    Oct 2001
    Location
    South Africa
    Posts
    4

    Re: Reading from Sequential file

    Hi there

    line input #1 - reads one line at a time, ignoring commas , but not newlines ,so it still overwrites the string, leaving the value
    of the string equal to the last line of the textfile. I can read it into a string array, but
    its gonna make my actual task much more complex.
    (Lets use a TextFile which is a paragraph).

    Thanks
    qingbob



  8. #8
    Join Date
    Oct 2001
    Location
    South Africa
    Posts
    4

    Re: Reading from Sequential file

    Hi John G

    The code you posted works perfectly!

    Thanks
    qingbob


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

Featured