-
January 22nd, 2004, 09:05 AM
#1
number of bytes readed by Get statement
I need to read from binary file. For this task I'm using get statement like this:
Code:
dim buffer(BUFFER_SIZE) as byte
...
Get #filenum1, , buffer
Probably I'm mistaken, but it seems, that get doesn't return number for bytes readed. Is there any standart method to retrive this value?
thanks a lot!
-
January 22nd, 2004, 09:44 AM
#2
Get
Get with open file for Binary
will fill the buffer with all the bytes taht could fit it-
It means, if your buff is 30 bytes, it will try to get 30 bytes. If there are more than 30, it will not read the extras.
If there are less, it will get as much as there are.
Next time you execute Get (on an opened file), the reading will procede from the byte next to the last read.
Things are different if you're using Open for Random....
Thus, How many bytes you read?
usually you fill the buffer with a char you do not expect to read
ie:
Code:
buff= string(30, Chr(0))
'then, after reading, you strip since first unexpected char
buf=left$(buf,instrrev(1,buf,chr(0)))
'and then you could know the bytes:
msgbox len(buf)
A better way is to know the length of the file in bytes (taht you know via Lof function once you opened it), then, knowing where starting reading, and knowing the lenght of buffer, you know if you fill it all or partially...
If you want to deal with, there is an api that tells you how many bytes it reads:
Private Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, ByVal lpOverlapped As Any) As Long
but doing some math while using get wuold be easier...
Last edited by Cimperiali; January 22nd, 2004 at 09:56 AM.
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
-
January 23rd, 2004, 01:16 AM
#3
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
|