Results 1 to 10 of 10

Thread: [RESOLVED] Problems loading specific block of data from a file

Threaded View

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Resolved [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:
    1. Function blockload(filename As String, Optional blocksize As Double, Optional block As Single)
    2. Dim fre As Integer
    3. Dim start As Double
    4. Dim data As String
    5.  
    6. If blocksize = 0 Then blocksize = 50000
    7. If block = 0 Then block = 1
    8.  
    9. 'calculate start of block to get
    10. start = (blocksize * (block - 1)) + 1
    11.  
    12. fre = FreeFile
    13. Open filename For Random As #fre Len = blocksize
    14. Get #fre, start, data
    15. blockload = data
    16. Close #fre
    17. 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
  •  



Click Here to Expand Forum to Full Width