Results 1 to 11 of 11

Thread: Reading lines from files..

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2002
    Location
    Staffordshire
    Posts
    82
    It depends on how the files are going to stored. Random access, Sequential Files??
    Line Input or Input could be used.

  2. #2
    Frenzied Member ae_jester's Avatar
    Join Date
    Jun 2001
    Location
    Kitchener Ontario Canada Earth
    Posts
    1,545
    VB Code:
    1. Dim strLine As String
    2.     Open "C:\Temp\test.txt" For Input As #1
    3.     Do While Not EOF(1)
    4.         Line Input #1, strLine
    5.         txtDisplay.Text = txtDisplay.Text & strLine & vbCrLf
    6.     Loop
    7.     Close #1

    Make sure you set the MultiLine property of the textbox to True!

  3. #3
    Addicted Member
    Join Date
    Sep 2001
    Posts
    137
    Thanks for your replies guys.

    The file is stored as a normal text file. The code from ae_jester is like the one i used before accept for the "Line" in front of "Input". I tried it but it still did not work.

    vbBoy.

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    What is the exact problem you are facing now?

  5. #5
    Addicted Member
    Join Date
    Sep 2001
    Posts
    137
    Thanks for the reply mendhak.

    The exact problem is that I have this text file that I would like to display its contents line by line on a text box. I could display it but the lines follow each other directly and not line by line as it is stored in the text file.


    vbBoy.

  6. #6
    New Member
    Join Date
    May 2002
    Location
    London UK
    Posts
    10
    What is the delimiter that separates each 'line' then ?

    If it is not a CR/FL then there must be a character that delimits
    each line/record/field.

    Let me know the chars, and I'll send you a routine to read the file, and 'unpack' the input string and then manipulate as individual lines/records.

    i.e. is the record

    1) "ID", "Field1" , "Field2", "Field3"
    2) 123, "aaa" , "bbb", "ccc"
    3) 456, "ddd", "eee", "fff"
    4) etc,

    or

    1)123, "aaa" , "bbb", "ccc"<DELIM CHAR>456, "ddd", "eee", "fff" etc,

  7. #7
    Addicted Member
    Join Date
    Sep 2001
    Posts
    137
    Hello johnLoveless...

    There is no delimiter that seperates the lines. The text looks like this:
    ___________________________________________________

    How are you?

    What are doing tonight? Will you like to go to the mcdonalds?

    Say at 08:00 hours.
    ___________________________________________________


    Thanks

    vbBoy

  8. #8
    Cytharni
    Guest
    Dim strLine As String
    Open "C:\Temp\test.txt" For Input As #1
    Do While Not EOF(1)
    Line Input #1, strLine
    txtDisplay.Text = txtDisplay.Text & strLine & Chr(13) & Chr(10)
    Loop
    Close #1

    =-=-=-=-=-=-=-=-=-=-=-=-=-=-

    I've used the original code used, then changed the vbCrLf (I think?) to Chr(13) and Chr(10) which is a Carriage return and line feed...

  9. #9
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    vBoy,

    Post (attach) the textfile in question as the Line Input
    examples should have worked.

  10. #10
    Addicted Member
    Join Date
    Sep 2001
    Posts
    137
    Thanks for your reply guys....

    The code from Cytharni works just as I wanted.


    vbBoy

  11. #11
    New Member
    Join Date
    May 2002
    Location
    London UK
    Posts
    10
    Have a look at the attached and let me know what else is needed
    and/or what is wrong etc.
    Attached Files Attached Files

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