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
Printable View
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
Note: try not to rely on DEFAULT property but always provide them explicitely.VB Code:
Open Filename For Input As #1 Text1.Text = Input(LOF(1), #1) Close #1
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
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.
Hmm, isn't a VB textbox limited to 65535 chars? I'm not sure...
Not exactly. Here is a quote from MSDN:Quote:
Originally posted by riis
Hmm, isn't a VB textbox limited to 65535 chars? I'm not sure...
... 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
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.
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$()...
Suerly you mean:Quote:
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
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
Surely I did!
Sorry bout that.... I usually work with Byte arrays instead... so it was a matter of habit... i'll change it...
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).Quote:
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
Hey, RTB can come handy ..., but you are the one to decide.Quote:
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.
thanks alot guys! you've been really helpful!
is there a better way to go threw a plain text file thats 6.7MB???
and changeing just about every line...
nice signature btw...