|
-
Jan 6th, 2003, 07:23 AM
#1
Thread Starter
Hyperactive Member
Reading data from files [RESOLVED]
I have a textfile a bit over 2 MB of size, and it takes painfully long to open it (almost 60 seconds). I'm using the following code to input the data:
VB Code:
Open App.path & "\index" For Input As #FF
Do
Line Input #FF, inputString ' Read a line
wholeLog = wholeLog & inputString & vbNewLine ' Append newly read line
Loop Until EOF(FF)
Close #FF
Is there some faster method of reading the data from the file?
-JR-
Last edited by Jareware; Jan 6th, 2003 at 09:26 AM.
"Blessed are we who can laugh at ourselves for we shall never cease to be amused"
- Unknown
-
Jan 6th, 2003, 08:10 AM
#2
Frenzied Member
It will be the append command thats slowing it down not the read. I have a program that reads all lines in text files and its like lightning. Comment out the append line and see how fast it is then
There are 3 types of people in this world.........those that can count, and those that can't.
Blobby
-
Jan 6th, 2003, 08:18 AM
#3
Thread Starter
Hyperactive Member
What would be the fastest way to store the entire file in a string-variable then? I am myself writing a file searching application, and the file I'm opening is an index of some 600 word documents (that have been parsed and useful data from them has been extracted and stored in XML in the index file).
Thank you for your interest in my problem - my project is not making much progress while it takes a minute for the program to load!
-JR-
"Blessed are we who can laugh at ourselves for we shall never cease to be amused"
- Unknown
-
Jan 6th, 2003, 08:36 AM
#4
Addicted Member
try using binary mode so you can read the whole file into one string without loops, use something like this:
VB Code:
Open "file.dat" for Binary As #1
Dim FileData As String * LOF(1)
Get #1, , FileData
Close #1
that should dump the whole file into the string
-=[Ç¥ßè®Ìú§]=-
How many microsoft employees does it take to change a lightbulb? None, they simply define darkness as the new industry standard.
CAUTION: OVERCLOCKING A 386 TO 5Ghz MAY BE HAZARDOUS
-
Jan 6th, 2003, 09:05 AM
#5
Frenzied Member
Yes i agree. Apening for Binary access reads the whole file in in one go whereas opening for Input allows u to read line by line (each line terminated by a newline).
reading the whole file is faster in Binary mode but then you have the problems of finding the things u want from this huge file.
There are 3 types of people in this world.........those that can count, and those that can't.
Blobby
-
Jan 6th, 2003, 09:10 AM
#6
Thread Starter
Hyperactive Member
Cyberius: The code you posted gives me a compile error (expected: end of statement) on the Dim-line. I have never played around with binary access to files, so what could be wrong?
Blobby: I have already made an xml-parsing engine that takes care of that and it works perfectly, so that is not an issue.
So how do I input the entire file into a variable using binary access?
-JR-
"Blessed are we who can laugh at ourselves for we shall never cease to be amused"
- Unknown
-
Jan 6th, 2003, 09:11 AM
#7
Addicted Member
Originally posted by Jareware What would be the fastest way to store the entire file in a string-variable then?
i was just answering the question
-=[Ç¥ßè®Ìú§]=-
How many microsoft employees does it take to change a lightbulb? None, they simply define darkness as the new industry standard.
CAUTION: OVERCLOCKING A 386 TO 5Ghz MAY BE HAZARDOUS
-
Jan 6th, 2003, 09:13 AM
#8
Addicted Member
my mistake...try this, it should work now
VB Code:
Open "file.dat" for Binary As #1
Dim FileSize As Long
FileSize = LOF(1)
Dim FileData As String * FileSize
Get #1, , FileData
Close #1
-=[Ç¥ßè®Ìú§]=-
How many microsoft employees does it take to change a lightbulb? None, they simply define darkness as the new industry standard.
CAUTION: OVERCLOCKING A 386 TO 5Ghz MAY BE HAZARDOUS
-
Jan 6th, 2003, 09:16 AM
#9
Frenzied Member
In Cyberius's post the entire file will be in the variable 'Filedata' which should be dimmed as a string
There are 3 types of people in this world.........those that can count, and those that can't.
Blobby
-
Jan 6th, 2003, 09:18 AM
#10
Thread Starter
Hyperactive Member
Still gives me a compile error, now "Constant expression required", on the same line still.
-JR-
"Blessed are we who can laugh at ourselves for we shall never cease to be amused"
- Unknown
-
Jan 6th, 2003, 09:18 AM
#11
Frenzied Member
VB Code:
Dim x As String
Open "C:\somefile.txt" For Input As #1
x = Input(LOF(1), 1)
Close #1
There!
-
Jan 6th, 2003, 09:20 AM
#12
Addicted Member
i DID dim it as a string
-=[Ç¥ßè®Ìú§]=-
How many microsoft employees does it take to change a lightbulb? None, they simply define darkness as the new industry standard.
CAUTION: OVERCLOCKING A 386 TO 5Ghz MAY BE HAZARDOUS
-
Jan 6th, 2003, 09:25 AM
#13
Thread Starter
Hyperactive Member
Thank you very much, got it working now, and it's fast as a breeze!
-JR-
"Blessed are we who can laugh at ourselves for we shall never cease to be amused"
- Unknown
-
Jan 6th, 2003, 09:29 AM
#14
Addicted Member
that what i get for not actually trying the code, lol....someone else comes in and steals the glory
-=[Ç¥ßè®Ìú§]=-
How many microsoft employees does it take to change a lightbulb? None, they simply define darkness as the new industry standard.
CAUTION: OVERCLOCKING A 386 TO 5Ghz MAY BE HAZARDOUS
-
Jan 6th, 2003, 09:35 AM
#15
Frenzied Member
hehehe Cyberius so u did! Im going code blind,....must be this snow we are having
There are 3 types of people in this world.........those that can count, and those that can't.
Blobby
-
Jan 6th, 2003, 09:38 AM
#16
Addicted Member
snow...hehe.....i wish.....take a look at my location....hot and humid summer
-=[Ç¥ßè®Ìú§]=-
How many microsoft employees does it take to change a lightbulb? None, they simply define darkness as the new industry standard.
CAUTION: OVERCLOCKING A 386 TO 5Ghz MAY BE HAZARDOUS
-
Jan 6th, 2003, 09:39 AM
#17
Frenzied Member
yes indeedee, bitterly cold here. As this post is now finished and the authors buggered off.....fancy a pint?
There are 3 types of people in this world.........those that can count, and those that can't.
Blobby
-
Jan 6th, 2003, 09:42 AM
#18
Addicted Member
dont mind if i do
-=[Ç¥ßè®Ìú§]=-
How many microsoft employees does it take to change a lightbulb? None, they simply define darkness as the new industry standard.
CAUTION: OVERCLOCKING A 386 TO 5Ghz MAY BE HAZARDOUS
-
Jan 6th, 2003, 09:46 AM
#19
Addicted Member
well isnt that a coincidence, your 'hollow-headed-homer' logo is the same themed image i have on my WinXP logon screen...this can only mean one thing...great, yet incredibly small minds think alike
-=[Ç¥ßè®Ìú§]=-
How many microsoft employees does it take to change a lightbulb? None, they simply define darkness as the new industry standard.
CAUTION: OVERCLOCKING A 386 TO 5Ghz MAY BE HAZARDOUS
-
Jan 6th, 2003, 09:56 AM
#20
Frenzied Member
hehehe Yeas but ive got a bigger head than you cos my brain is smaller than yours....so there!
There are 3 types of people in this world.........those that can count, and those that can't.
Blobby
-
Jan 6th, 2003, 09:57 AM
#21
Frenzied Member
..........and its your round..........
There are 3 types of people in this world.........those that can count, and those that can't.
Blobby
-
Jan 6th, 2003, 10:28 AM
#22
Addicted Member
right you are.....*buys a round of drinks*
i think we've officially made this a 'Chit Chat' thread now lol.....or more to a point, a thread about big heads and small brains
-=[Ç¥ßè®Ìú§]=-
How many microsoft employees does it take to change a lightbulb? None, they simply define darkness as the new industry standard.
CAUTION: OVERCLOCKING A 386 TO 5Ghz MAY BE HAZARDOUS
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
|