|
-
Feb 16th, 2005, 05:27 AM
#1
Thread Starter
Hyperactive Member
fastest way to read text file
I have a project that reads several text files and i am really shocked as to how slow the following process does it:
Code:
FileOpen(1, strFilePath, OpenMode.Input)
Do Until EOF(1)
strTextLine = LineInput(1)
:
:
Loop
FileClose(1)
is there are faster way to read text files?
"The passion lives to keep your faith, though all are different, all are great" ... Michael Hutchence 1960-1997.
Windows & Web Developer
Specialising in Visual Basic .Net & Client Server Programming & Client/Customer Relations Databases
Sutherland Shire, Sydney Australia
www.stingrae.com.au
Developer of Arnold - Gym & Martial Arts Database Management System
www.gymdatabase.com.au
-
Feb 16th, 2005, 05:58 AM
#2
PowerPoster
Re: fastest way to read text file
Have you tried using StreamReader?
Something like;
VB Code:
Dim SR1 As StreamReader = File.OpenText("C:\ path & file )
Dim sTemp As String
Do Until SR1.Peek = -1
stemp = SR1.ReadLine
Loop
You could also read the entire file in one go with
sTemp=SR1.ReadToEnd
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Feb 16th, 2005, 07:10 AM
#3
Frenzied Member
Re: fastest way to read text file
 Originally Posted by taxes
Have you tried using StreamReader?
You could also read the entire file in one go with
sTemp=SR1.ReadToEnd
If i use that, it will read it all in one line yeah?
How do make it so that it will put it into an arraylist line by line...so that i can refer it to
al(i) quickly?
-
Feb 16th, 2005, 07:29 AM
#4
Re: fastest way to read text file
 Originally Posted by dinosaur_uk
If i use that, it will read it all in one line yeah?
How do make it so that it will put it into an arraylist line by line...so that i can refer it to
al(i) quickly?
Using the .ReadLine and adding the line to the arraylist.
Regards
Jorge
"The dark side clouds everything. Impossible to see the future is."
-
Feb 16th, 2005, 08:52 AM
#5
PowerPoster
Re: fastest way to read text file
 Originally Posted by dinosaur_uk
If i use that, it will read it all in one line yeah?
How do make it so that it will put it into an arraylist line by line...so that i can refer it to
al(i) quickly?
Not sure if you're kidding me but
VB Code:
Dim aList As New ArrayList
Dim sr1 As New StreamReader("G:\TestFile.txt")
Dim sTemp As String
Do Until sr1.Peek = -1
sTemp = sr1.ReadLine
aList.Add(sTemp)
Loop
sr1.Close()
Obviously you declare aList with the necessary scope.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Feb 16th, 2005, 08:56 AM
#6
Frenzied Member
Re: fastest way to read text file
Hiya
Taxes,,
Yeah I have got that ....i was thinking if there was any other way...
I am not that bad
-
Feb 16th, 2005, 09:09 AM
#7
PowerPoster
Re: fastest way to read text file
Hi,
Thought not from other posts, but one guy on the forum accuses me of being condescending at times ( apart from other things) - Hi Andy
See if this is faster
VB Code:
Dim sr1 As New StreamReader("G:\TestFile.txt")
Dim sTemp As String
Dim aList() As String
sTemp = sr1.ReadToEnd
sr1.Close()
aList = Split(sTemp, vbCrLf)
I would be interested to know.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Feb 16th, 2005, 10:15 AM
#8
Re: fastest way to read text file
Hi,
One other possibility, although I make no claims as to the speed, might be to use a RichTextBox with a LoadFile command (in txt mode rather than rtf) and then use the split command a la Taxes.
zaza
-
Feb 16th, 2005, 10:47 AM
#9
Frenzied Member
Re: fastest way to read text file
Hi Taxes,
The code does not work it says the 1-Dimensional array cannot be converted to a arraylist
can you please help me with this problem please please pretty please????
http://www.vbforums.com/showthread.php?t=324950
 Originally Posted by taxes
Hi,
Thought not from other posts, but one guy on the forum accuses me of being condescending at times ( apart from other things) - Hi Andy
See if this is faster
VB Code:
Dim sr1 As New StreamReader("G:\TestFile.txt")
Dim sTemp As String
Dim aList() As String
sTemp = sr1.ReadToEnd
sr1.Close()
aList = Split(sTemp, vbCrLf)
I would be interested to know.
-
Feb 16th, 2005, 10:52 AM
#10
Frenzied Member
Re: fastest way to read text file
VB Code:
Dim sr1 As New StreamReader(Application.StartupPath & "\bah.csv", FileMode.OpenOrCreate)
Dim aList As New ArrayList
Dim sTemp As String
Do Until sr1.Peek = -1
sTemp = sr1.ReadLine
aList.Add(sTemp)
Loop
MsgBox(aList.Count)
This is faster...
-
Feb 16th, 2005, 10:57 AM
#11
PowerPoster
Re: fastest way to read text file
Hi,
Thanks
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Feb 16th, 2005, 02:05 PM
#12
Frenzied Member
Re: fastest way to read text file
I am sure there must be a better way ....coz if i am handling big big csv....is there a data adaptor for it?
-
Feb 16th, 2005, 05:44 PM
#13
PowerPoster
Re: fastest way to read text file
 Originally Posted by dinosaur_uk
Hi,
I missed this post earlier, but I am rather confused about it.
I did not mention an arraylist and the code certainly works for me.
please clarify.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Feb 16th, 2005, 06:26 PM
#14
Frenzied Member
Re: fastest way to read text file
yeah sorry ...i misread your post
many many apologies
-
Feb 16th, 2005, 07:06 PM
#15
PowerPoster
Re: fastest way to read text file
No problem
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
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
|