|
-
Apr 2nd, 2003, 09:13 AM
#1
Thread Starter
Frenzied Member
open large text files
i use this code to open text files, but it cant open large ones...
is there a better code?
VB Code:
Open Filename For Input As #1
Do While Not EOF(1)
Text1 = Input(LOF(1), 1)
Loop
Close #1
-
Apr 2nd, 2003, 09:33 AM
#2
Frenzied Member
VB Code:
Open Filename For Input As #1
Text1.Text = Input(LOF(1), #1)
Close #1
Note: try not to rely on DEFAULT property but always provide them explicitely.
-
Apr 2nd, 2003, 09:37 AM
#3
Junior Member
Hmmm... this wouldn't be related to your "slow variables" post by any chance?
Would I be right in guessing that you're using a textbox control to show the contents of a text file? That you read in the contents of the file and append them one character at a time to the text field in the control?
You really want to be using the Microsoft Scripting Runtime component for this. It is a better choice for getting your data out of the file. Create a FileSystem object and from this, get a TextStream and then use the ReadAll method.
Does this help?
Dave
-
Apr 2nd, 2003, 09:42 AM
#4
Frenzied Member
Input$ function works just as fast BUT it doesn't depend on any library what-so-ever (except for VB runtimers). Also, KIM that Scripting library was NOT developed for use in VB but ASP primarely.
-
Apr 2nd, 2003, 09:47 AM
#5
Fanatic Member
Hmm, isn't a VB textbox limited to 65535 chars? I'm not sure...
-
Apr 2nd, 2003, 09:56 AM
#6
Frenzied Member
Originally posted by riis
Hmm, isn't a VB textbox limited to 65535 chars? I'm not sure...
Not exactly. Here is a quote from MSDN:
... The Text setting for a TextBox control is limited to 2048 characters unless the MultiLine property is True, in which case the limit is about 32K
-
Apr 2nd, 2003, 10:00 AM
#7
Fanatic Member
Then that's the reason that Cyborg can't open large text files (larger than 32k). He should store the contents in a buffer if he needs to have the entire text file accessible by the application at once.
-
Apr 2nd, 2003, 10:57 AM
#8
I wonder how many charact
1) Don't bother with the scripting object (too much resource comitted for such a simple operation, plus you may have distribution problems)
2) Don't use a For-Next loop to read in the text.... that will be take much longer for larger files. Instead, use one Get statement, which invokes OS API's...
You can simply
1) declare a string
2) buffer the string to size of the file
3) load the file contents directly into the string
VB Code:
Dim myFileData As String
myFileData = Space(FileLen("C:\myfile.txt"))
Open "C:\myfile.txt" For Binary As #1
Get #1,,myFileData
Close #1
If you need to display only a portion of the filedata, use Mid$()...
Last edited by nemaroller; Apr 2nd, 2003 at 11:01 AM.
-
Apr 2nd, 2003, 10:59 AM
#9
Retired VBF Adm1nistrator
Originally posted by nemaroller
VB Code:
Dim myFileData As String
ReDim myFileData(FileLen("C:\myfile.txt"))
Open "C:\myfile.txt" For Binary As #1
Get #1,,myFileData
Close #1
Suerly you mean:
VB Code:
Dim myFileData As String
[b]myFileData = Space(Lof(1))[/b]
Open "C:\myfile.txt" For Binary As #1
Get #1, , myFileData
Close #1
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Apr 2nd, 2003, 11:00 AM
#10
I wonder how many charact
Surely I did!
Sorry bout that.... I usually work with Byte arrays instead... so it was a matter of habit... i'll change it...
-
Apr 2nd, 2003, 11:03 AM
#11
PowerPoster
Re: open large text files
Originally posted by cyborg
i use this code to open text files, but it cant open large ones...
is there a better code?
VB Code:
Open Filename For Input As #1
Do While Not EOF(1)
Text1 = Input(LOF(1), 1)
Loop
Close #1
Use a RichTextBox instead of a standard one. Youll have to add it from the components menu first. Your problem is likely that a standard textbox cannot hold the amount of data (as someone already mentioned).
-
Apr 2nd, 2003, 11:15 AM
#12
Frenzied Member
Originally posted by riis
Then that's the reason that Cyborg can't open large text files (larger than 32k). He should store the contents in a buffer if he needs to have the entire text file accessible by the application at once.
Hey, RTB can come handy ..., but you are the one to decide.
-
Apr 2nd, 2003, 04:29 PM
#13
Thread Starter
Frenzied Member
thanks alot guys! you've been really helpful!
-
Apr 2nd, 2003, 04:38 PM
#14
Member
lol...
is there a better way to go threw a plain text file thats 6.7MB???
and changeing just about every line...
-
Apr 2nd, 2003, 06:00 PM
#15
I wonder how many charact
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
|