Results 1 to 9 of 9

Thread: Fastest way to open TXT ??

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2002
    Posts
    60

    Exclamation Fastest way to open TXT ??

    Hi All !

    What is the fastest way to open a TXT as ReadOnly ?
    Open "" as #1 ?
    FSO ?

    The TXT has about 11Mb, and is being added line by line during the day. That is why I need it to be read-only and doesnt stop the other process.
    Imagine this, during the day, a program keeps adding lines to a TXT and I need to get the from minute to minute....

    What do you recommend ??
    Any help is appreciated !!


    THANKS !!!!
    Martin.
    Martin

  2. #2
    Frenzied Member Lightning's Avatar
    Join Date
    Oct 2002
    Location
    Eygelshoven
    Posts
    1,611
    I recommend that you use a Database in stead of a textfile
    VB6 & C# (WCF LINQ) mostly


    If you need help with a WPF/WCF question post in the NEW WPF & WCF forum and we will try help the best we can

    My site

    My blog, couding troubles and solutions

    Free online tools

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2002
    Posts
    60
    I can´t.
    The TXT is generated by another software.
    Martin

  4. #4
    Frenzied Member
    Join Date
    May 2003
    Location
    So Cal
    Posts
    1,564
    Well, since both methods only take a few seconds to code, why not try them both and see which is faster?

  5. #5
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    Dont bother with FSO...it adds un-needed bulk to your app (unless you doing other things with files)

    Just read the whole file at once...then split it...
    its faster than reading line by line...

    Open ...blah blah as #1
    Data = Input(lof(1),1)
    Close #1
    DIm Lines() as string
    Lines = Split(Data,vbcrlf)

    etc..
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  6. #6
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    I don't think you would want to read an entire 11mb file into a string and split it into an array.

    The file I/O commands you use depend on the file itself. Are the records fixed length or variable? Is it binary data? Does the third party program open the file shared or is it expecting exclusive access?

    Sample to open a text file for read only shared access.

    VB Code:
    1. Dim lngFileNo As Long
    2. lngFileNo = FreeFile
    3.  
    4. Open "M:\Testing\SomeData.dat" For Input Access Read Shared As lngFileNo
    5. Seek lngFileNo, LOF(lngFileNo) 'you are now at the end of file.
    6. Close lngFileNo

  7. #7
    Frenzied Member Spajeoly's Avatar
    Join Date
    Mar 2003
    Location
    Utah
    Posts
    1,068
    There is none faster than this in VB...
    Slap the first 2 linesin a module...
    VB Code:
    1. Declare Function SysAllocStringByteLen Lib "oleaut32" (ByVal olestr As Long, ByVal BLen As Long) As Long
    2. Declare Sub RtlMoveMemory Lib "kernel32" (dst As Any, src As Any, ByVal nBytes As Long)
    Then we make the function..
    VB Code:
    1. Function Text_Read(ByVal FilePath As String) As String
    2. On Error Resume Next
    3.   Dim FileBuffer As String, fl As Long
    4.   fl = FreeFile
    5.   Open FilePath For Binary As #fl
    6.   RtlMoveMemory ByVal VarPtr(FileBuffer), SysAllocStringByteLen(0&, LOF(fl) * 2), 4&
    7.   Get #fl, , FileBuffer
    8.   Close fl
    9.   Text_Read = FileBuffer
    10. End Function
    Then we use the function...
    VB Code:
    1. TheFile = Text_Read(FilesPathAndName)
    I thank the Nick man for turning me onto this code.

  8. #8
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    If the text is just being added on to, then why not keep a note of the size of the file from the last time you opened it. Then the next time you open the file, move to that position and continue on.

    Make sense to me.
    Please rate my post.

  9. #9
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385
    sogtulakk

    you haven't stated what you are doing with the file. That would have some input to how you read it. But anyway look at a project named Automatic Log File Updater to get some ideas.

    You can find it at http://www.***********/freeware.html

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