|
-
Mar 2nd, 2004, 08:15 AM
#1
Thread Starter
Member
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.
-
Mar 2nd, 2004, 08:24 AM
#2
I recommend that you use a Database in stead of a textfile
-
Mar 2nd, 2004, 08:26 AM
#3
Thread Starter
Member
I can´t.
The TXT is generated by another software.
-
Mar 2nd, 2004, 09:03 AM
#4
Frenzied Member
Well, since both methods only take a few seconds to code, why not try them both and see which is faster?
-
Mar 2nd, 2004, 09:48 AM
#5
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"
-
Mar 2nd, 2004, 03:58 PM
#6
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:
Dim lngFileNo As Long
lngFileNo = FreeFile
Open "M:\Testing\SomeData.dat" For Input Access Read Shared As lngFileNo
Seek lngFileNo, LOF(lngFileNo) 'you are now at the end of file.
Close lngFileNo
-
Mar 2nd, 2004, 06:14 PM
#7
Frenzied Member
There is none faster than this in VB...
Slap the first 2 linesin a module...
VB Code:
Declare Function SysAllocStringByteLen Lib "oleaut32" (ByVal olestr As Long, ByVal BLen As Long) As Long
Declare Sub RtlMoveMemory Lib "kernel32" (dst As Any, src As Any, ByVal nBytes As Long)
Then we make the function..
VB Code:
Function Text_Read(ByVal FilePath As String) As String
On Error Resume Next
Dim FileBuffer As String, fl As Long
fl = FreeFile
Open FilePath For Binary As #fl
RtlMoveMemory ByVal VarPtr(FileBuffer), SysAllocStringByteLen(0&, LOF(fl) * 2), 4&
Get #fl, , FileBuffer
Close fl
Text_Read = FileBuffer
End Function
Then we use the function...
VB Code:
TheFile = Text_Read(FilesPathAndName)
I thank the Nick man for turning me onto this code.
-
Mar 2nd, 2004, 07:08 PM
#8
Frenzied Member
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.
-
Mar 2nd, 2004, 11:56 PM
#9
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|