Results 1 to 3 of 3

Thread: Read last line of text file

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2005
    Posts
    40

    Post Read last line of text file

    Hi Guys,

    I needed some help regarding file reading in VB 6. I am writing a program that needs to insert a record in a text file. The text file has following format..

    Date, Time, Open Price, Close price

    Now i need to insert record only if date is greater than last date in file.

    So everytime I need to insert record, I have to open file and read sequentially and then I reach last record. This takes time.

    IS there a way to read such file in binary or whatever so that i can get last record straight away or very quickly without going thru all records one by one.

    If there is can anyone post a small code.

    [Records in the (text) file is like -

    01/01/2006, 1100, 123.33, 155.55
    01/01/2006, 1130, 122.22, 134.33
    01/01/2006, 1200, 112.22, 124.33
    so on ... ]


    Thanks a lot,

    Cheers,
    GR

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

    Re: Read last line of text file

    Depending on the size of the file, you could read into an Array (using Split(LOF), vbCrLf) and then check the UpperBound -1 (last element) of the Array - being the last line of text.

    How may lines do you expect there to be?

  3. #3

    Thread Starter
    Member
    Join Date
    Apr 2005
    Posts
    40

    Resolved Re: Read last line of text file

    I can use binary mode and read last 50 bytes and clean up the string to get data.

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