|
-
May 19th, 2003, 03:07 PM
#1
Thread Starter
New Member
reading from binary files
I am trying to read from a binary file. I am getting some weird input however.
The binary file is called "my file.bin" and contains these simple hex
characters:
F7 00 00 08 F0
I want to be able to insert every pair of hex data into a simple array. Here's
the code I've produced...
Private Sub button_Click()
Dim data As Integer
Dim small_array(1 to 5) as Integer
nFileNum = FreeFile
picBox.Cls
Open App.Path & "\" & "my file.bin" For Binary As #nFileNum
for i = 1 to 5
Get #nFileNum, i, data
small_array(i) = data
Next
for i = 1 to 5
picBox.print Hex(small_array(i))
Next
Close #nFileNum
End Sub
When the code is executed, I get this result:
F7 0 800 F008 F0
Can someone tell me what is happening, why Visual Basic is producing these
results, and how I can fix this? Thank you!
-
May 19th, 2003, 03:53 PM
#2
Fanatic Member
does your file contain 5 bytes? or does it contain the string "F7 00 00 08 F0"?
there are 2 reasons why i leave my work unfinished:
(1) i'm getting old.
-
May 19th, 2003, 04:31 PM
#3
Frenzied Member
For starters, you are reading 2 of the 5 bytes with every Get because the variable data is an Integer. Try changing data to Byte and see if it doesn't work.
I got basically the same results when reading the file as though it contains Integers. I should think that VB would raise a read past EOF type error.
-
May 20th, 2003, 08:20 AM
#4
Thread Starter
New Member
issue resolved
Changing the variable data into a type byte fixed the problem! Thank you very much!
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
|