How do i open a file more than 1meg in size and display its contents in a textbox??
much appreciated!!
Printable View
How do i open a file more than 1meg in size and display its contents in a textbox??
much appreciated!!
A textbox can't display that much text. It's not the buffer, it's because it can't reference that high a number. You'd need to use a RichTextBox instead.
Be sure to...
...open the file in binary mode
http://www.vb-world.net/files/openstatement/
...or using the command
Text1.Loadfile ("C:\largefile.txt")
I know this is (for some reason) not so popular among many programmers, but it works well for me.
nah...
The reason I told him to use Binary mode is because I heard it was alot faster than the other methods, ok, your's is easier but for large files I believe it's better to use Binary, and it sounds cool :)
the textbox doesn't have a method call loadfile
i got an error message trying
Text1.Loadfile("C:\somelargefile.txt")
It's meant for the RichTextBox from Microsoft (Press CTRL + T) and add it to your project.
one last things.. how much data can the rich text box hold...
in other words.. is there a limit on the file size i can display in the RTB?
Much Appreciated
I think its 2 or 3 gigabytes....
I think that 2-3 GB is enough and nobody enters that much text.
every char on a textbox is one Byte, so imagine 1 MB is 10000000 Bytes, so it's like 10000000 characters. 1000 MB is 1000 MB. so it's 100000000000 characters. Times 3 it's 300000000000 characters, and that's a lot!
Summary:
1 Byte = 1 Char
1 MB = 10000000 Chars
1 GB = 10000000000 Chars
3 GB = 30000000000 Chars
30000000000 chars is a lot!!!
More posts for me!
Well, I use RichTexBox and LoadFile, and it only took a few seconds to open a Mp3-file of 3800 kB.Quote:
Originally posted by Jop
The reason I told him to use Binary mode is because I heard it was alot faster than the other methods
So it's fast enough.
Pentax
Ohh it probably uses Binary mode too then :)Quote:
Well, I use RichTexBox and LoadFile, and it only took a few seconds to open a Mp3-file of 3800 kB.
So it's fast enough.
Sorry for the incovidence...
Well, that's of course possible.Quote:
it probably uses Binary mode too then
I thought of Open file As Binary and all that stuff when you wrote open in binary mode.
What does incovidence mean?
Pentax
You try loading a file byte by byte from a file nto RAM - It's very slow
I meant the LoadFile method, I mentioned Open File ... As Binary before. That was not what I meant mate :)Quote:
Well, that's of course possible.
I thought of Open file As Binary and all that stuff when you wrote open in binary mode.
What does incovidence mean?
Pentax
You're wrong.Quote:
Originally posted by Asaf_99
Summary:
1 Byte = 1 Char
1 MB = 10000000 Chars
1 GB = 10000000000 Chars
3 GB = 30000000000 Chars
30000000000 chars is a lot!!!
1 char = 8 bits
8 bits = 1 byte
1024 bytes = 1 KB
1,048,576 bytes = 1 MB(1024 KB)
1,073,741,824 bytes = 1 GB(1024 MB)
1,099,511,627,776 bytes = 1 TeraByte(TB, 1024 GB)
You get the picture I hope.
1024 / 8 = 128
multiples of two!
128 / 2 = 64
62 / 2 = 32
..16
..8
..4
..2
..1
If it were:
1000 / 8 = 125
125 / 2 = 62.5
you can't have 62.5 bits!
So that'll make 1 Char = 1 byte Isn't that the same as Asaf_99 said?Quote:
1 char = 8 bits
8 bits = 1 byte
Yes, 1 character is 1 byte, but 1000 bytes is not a kilobyte, it takes 1024 byte to make a kilobyte.
Yeah I overlooked that part in his post, sorry!
On type names:
4 bits = 1 nibble
2 nibbles = 1 byte
And here's the explanation for why a text-box can't load more than 64K:
The text box is one of the original Windows controls, and as such, is 16bit. This means it can only address a maximum of 2^16 bytes = 65536 bytes. The RichTextBox is 32bit, so it can use 2^32 bytes = 4294967296 bytes (4 gigs).