|
-
May 31st, 2006, 09:42 PM
#1
Thread Starter
PowerPoster
[RESOLVED] Problems loading specific block of data from a file
I am trying to write a function where i give it a file (full path), block size and block number and it gets the given block from the file and copies it to a string...however, i am having problem after problem. For the purpose I am writing this, it *needs* to be able to load a random block and not keep loading blocks again and again until it gets to the required block...time is critical in this case...
Anyway, a friend gave me http://www.other-space.com/vb/part2/files.html which (under random access) gives a program that uses len= when opening the file, which seemed perfect to me :-) ...I modified it a little to fit my needs, thus:
VB Code:
Function blockload(filename As String, Optional blocksize As Double, Optional block As Single)
Dim fre As Integer
Dim start As Double
Dim data As String
If blocksize = 0 Then blocksize = 50000
If block = 0 Then block = 1
'calculate start of block to get
start = (blocksize * (block - 1)) + 1
fre = FreeFile
Open filename For Random As #fre Len = blocksize
Get #fre, start, data
blockload = data
Close #fre
End Function
When I run this, it stops at the GET line and returns the error 59, "bad record length". I am using test data and the file opened is over 39k and I am using blocksize 100 and block 1.
Has anyone got suggestions for alternative ways to achieve what I want to do (I understand that for someone who knows about file access it is a simple matter, but one of my main "failures" of VB is using GET correctly :-)) or perhaps got a fix for this code? 
If i gave this file a filename and said block size 100 and block 1, I want it to return the first 100 bytes of the file...if I changed block to 2 I would want the *NEXT* 100 blocks after that...and so on :-)
Last edited by smUX; May 31st, 2006 at 10:16 PM.
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
|