Announcement

Collapse
No announcement yet.

SETEOF problem, perhapse a "bug"

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • SETEOF problem, perhapse a "bug"

    Hello,

    I was trying to use the following code to presize a database file
    but found that it didn't work the way I had hoped.

    This example leaves the file at zero bytes...
    Code:
    #compile exe
    
    function pbmain
        open"d:\mark.db" for random as #1 len = 1
        
        seek #1,50000
        seteof #1
        close #1
    end function
    And this example works just fine...
    Code:
    #compile exe
    
    function pbmain
        open"d:\mark.db" for binary as #1
        
        seek #1,50000
        seteof #1
        close #1
    end function
    I would have though that they both would work the same way?

    ------------------
    Cheers

    [This message has been edited by mark smit (edited October 05, 2000).]

  • #2
    Mark,

    It is not a bug, its the difference in the files that you
    are trying to set the eof on.

    For Random Files you will have to write a record to the
    file at the record location, it must be the correct length
    as specified in the open statement, but it can be all spaces

    With Binary Files the SETEOF command must be the next byte
    where a new record will go, not the end of the current record

    Phil

    Example Code Below:
    In both cases the file lengths will be 50000 bytes.
    Binary and Random Files are handled completely different.
    It's strange, but this is how it works.
    pbcc CODE

    Code:
    #COMPILE EXE
    
    FUNCTION PBMAIN() AS LONG
        a$=" "  ' one record
        OPEN"c:\mark.db" FOR RANDOM AS #1 LEN = 1
    
        SEEK #1,50000
        PUT #1,,a$
        SETEOF #1
        PRINT "length #1 =";LOF(1)
        CLOSE #1
        '-------------------
        OPEN"c:\mark2.db" FOR BINARY AS #2
    
        SEEK #2,50001  ' actual end plus one for binary files
        SETEOF #2
        PRINT "length #2 =";LOF(2)
        CLOSE #2
        LINE INPUT "Press any key";a$
        '------------------
        a$=" "  ' one record
    
        OPEN"c:\mark.db" FOR RANDOM AS #1 LEN = 1
    
        SEEK #1,30000
        'GET #1,,a$    'get record 30000 if you want to save it.
        'SEEK #1,30000
        PUT #1,,a$
        SETEOF #1
        PRINT "length #1 =";LOF(1)
        CLOSE #1
        '----------------------
        OPEN"c:\mark2.db" FOR BINARY AS #2
    
        SEEK #2,30001  ' actual end plus one for binary files
        SETEOF #2
        PRINT "length #2 =";LOF(2)
        CLOSE #2
        LINE INPUT "Press any key";a$
    END FUNCTION


    [This message has been edited by Phil Tippit (edited October 05, 2000).]
    E-Mail:
    pt AT pursuersoft DOT com

    Comment

    Working...
    X