-
I want to read a file and
put it in a byte array.
Why wont it put it in the
array?
Code:
Dim StrFile as String
Dim bytTemp() As Byte
StrFile = "C:\readme.txt"
Open strFile For Binary As #1
Get #1, , bytTemp
Close #1
ReadMe.txt:
Code:
MainBoard : M599LMR
BIOS Date : Release 03/08/2000S
VGA : SiS Multimedia V1.08
Sound : Version 2.32
Modem : Pctel R7.64-pcc-06
Lan DAVICOM : Version 1.12
Gamut : Version 1.56
Super Voice : Version 2.2
Audio Rack : Version 2.32
[Edited by Evan on 08-29-2000 at 03:13 PM]
-
<?>
Code:
Private Sub Command1_Click()
Dim StrFile As String
Dim bytTemp() As Byte
Dim i As Integer
StrFile = "C:\readme.txt"
Open StrFile For Binary As #1
Do Until EOF(1)
ReDim Preserve bytTemp(i)
Get #1, , bytTemp(i)
i = i + 1
Loop
Close #1
'for display only List1
For i = 0 To i - 1
List1.AddItem bytTemp(i)
Next
End Sub
-
No offence HeSaidJoe, but that is the slowest possible way to read a file in, you also seem to be redimensioning the array as a variant, or does a dynamic array stay as the type it was originally declared as? Thats a good question.
Code:
Private Sub Command1_Click()
Dim StrFile As String
Dim bytTemp() As Byte
StrFile = "C:\readme.txt"
Open StrFile For Binary As #1
'redim the array to the size of the file
ReDim bytTemp(LOF(1) - 1) As Byte
'read the whole file in one go
Get #1, , bytTemp
'close the file
Close #1
End Sub
[Edited by Iain17 on 08-29-2000 at 05:02 PM]
-
??
Ok..
That works .. all acept the
file im reading is going to
be about 100mbs sometimes.
How do I store it in a byte
varable with out it over flowing?
-
<?>
No offence taken..I only adjusted what was given to make it work.
-
Are you sure that is a good idea. 100mb file in memory. Can you not work with chunks of the file? That i think would be better idea. I just tried the code i gave you, and it loaded a 100mb file ok, took some time though.
Mind you i am running windows 2000, so it may not work on 98.