' Random access file: FIELD, LOCK, UNLOCK, WRITE$, READ$
#COMPILE EXE
#DIM ALL

FUNCTION PBMAIN() AS LONG
    LOCAL buffer  AS STRING
    LOCAL rec1  AS STRING
    LOCAL rec2  AS STRING
    buffer = "Record one data here"

    OPEN "test_rand.dat" FOR BINARY AS #1

        LOCK #1

        PUT #1, 1, buffer
        buffer = "Record two data here"
        PUT #1, 33, buffer

        UNLOCK #1

    CLOSE #1

    OPEN "test_rand.dat" FOR BINARY AS #1
        buffer = SPACE$(20)
        GET #1, 1, buffer
        rec1 = buffer
        buffer = SPACE$(20)
        GET #1, 33, buffer
        rec2 = buffer
        PRINT "Record 1:"; rec1
        PRINT "Record 2:"; rec2
    CLOSE #1

    KILL "test_rand.dat"
    PRINT "Random access test complete."

    FUNCTION = 0
END FUNCTION
