-
Hi all,
Sometime ago I asked here how to present a text file that I read on a form. I got an answer that suggested me simply to use a text box control.
Problem is that I read that file in a loop. something like:
While (NOT EOF)
read....
Textbox1.text = read_str
Wend
now each line erase the other and I can not display the whole file.
How to avoid it?
Should I use a different control? which one?
Thanks.
-
Try enabling multiline for the textbox.
btw, isn't there a limit for the number of characters u can place in a string?
-
A string character limit is s^31 that's 2 gigabyte so that's not the problem but a textbox character limit is 65536 byte + that nullchars will cut off the rest of the text.
Use & operater to add up strings instead of overwriting it again and again.
Don't read a file line by line, open in binary and get the whole file in one chunk:
Code:
Dim buffer as string
Open file for binary as #1
buffer=space(lof(1))
Get#1,,buffer
close #1
'now if that text file is smaller than 65536 bytes then you could put it in a textbox else put it in a richtextbox or leave it in the string.
TExt1=buffer
-
I did try the multiline property, but it did not help.
And as for the limit, I limit the string that I read for 200 chars and it works OK.
-
You have to add the string to the textbox, like this:
Text1.text = Text1.text + read_str
if you want to do it line by line.
-
If you decide to use Line Input, use this
Code:
Text1.text = Text1.text & read_str
'Because if:
'text.text = 4
'readstr = 4
'it will result in
'Text1.Text = 44
instead of this
Code:
Text1.text = Text1.text + read_str
'Because if:
'text.text = 4
'readstr = 4
'it will result in
'Text1.Text = 8 < not what we want huh?
Get why?
-
Sorry, I meant & and not +.
But + will work if it's only text...
[Edited by Tote on 10-15-2000 at 10:14 AM]
-
Use the following method instead of Line Input.
Code:
Open "MyTextFile.txt" For Input As #1
Text1 = Input(LOF(1), 1)
Close #1
-
Should have known this, if you post something then everyone comes with their own suggestion, well hope you don't choose one of the "adding upp strings"-solutions