yk2000,
Create a [tt]
TYPE[/tt] for your record, and open the file [tt]
FOR BINARY[/tt]. I have an example that shows how you can maintain a list of deleted records, with a large block of untested code

-)) in another thread. With any luck, this should link to it:
thread314-289593
The basic idea is that you take the length of that [tt]
TYPE[/tt] (and you can't just use [tt]
LEN[/tt] on the [tt]
TYPE[/tt], as this will just give you 4 for some reason (perhaps it is erroneously treating it as a variable of type [tt]
SINGLE[/tt]) -- you have to create a variable of that [tt]
TYPE[/tt] and take the [tt]
LEN[/tt] of that variable), and then you use that to calculate the offset into the file of the corresponding record on disk. For instance, if the record is 500 bytes long, then the offset of record #20 is 20 * 500 = 1000 bytes from the start of the file. Since the start of the file is offset 1, this means that record #20 is offset 1001. In general, the following formula will give you the offset on disk:
[tt]
diskOffset& = 1 + recordNumber& *
LEN(recordVariable)
[/tt]
With this scheme, the first record in the file is numbered 0.
Anyway, now that you have the offset of the record, you can load the existing data into that [tt]recordVariable[/tt] with [tt]
GET[/tt] and save the current data from the [tt]recordVariable[/tt] using [tt]
PUT[/tt]. Here is a simple example:
[tt]
TYPE recordType
userName
AS STRING * 50
' a 50-byte record
END TYPE
DIM recordVariable
AS recordType
OPEN "database"
FOR BINARY AS #1
DO
INPUT "Record number"; recordNum&
byteOffset& = 1 + recordNum& *
LEN(recordVariable)
GET #1, byteOffset&, recordVariable
PRINT "Current username: "; recordVariable.userName
PRINT "Change [y/n]? ";
DO
a$ =
UCASE$(
INPUT$(1))
LOOP UNTIL INSTR("YN", a$)
PRINT a$
IF (a$ = "Y"
THEN
LINE INPUT "New name: ", recordVariable.userName
PUT #1, byteOffset&, recordVariable
PRINT "Changes saved!"
END IF
PRINT "Continue [y/n]? ";
DO
a$ =
UCASE$(
INPUT$(1))
LOOP UNTIL INSTR("YN", a$)
PRINT a$
LOOP UNTIL a$ = "N"
CLOSE #1
[/tt]