Skip to content

Modern Fs WriteRecord

Paul Squires edited this page Oct 24, 2026 · 1 revision

Home › Filesystem › File Streams › WriteRecord

WriteRecord

Writes a value as record n of an open File, growing the file if needed.

Syntax

WriteRecord( of T )( f, n, r )            '' FsResultBool

Notes

  • Writes the sizeof( T ) bytes of r at ( n - 1 ) * sizeof( T ), records counting from 1.
  • Writing past the end grows the file, and the records in the gap read as zeros.
  • n below 1 fails with FS_INVALID_ARGUMENT. The File must be open for writing.
  • T must hold only fixed-size fields: see RecordFile.

Examples

#import "std/fs"
using fs

type Score field = 1
    player as long
    points as long
end type

dim as File f
f.Open( "scores.dat", OpenOptionsWrite( ) )
dim as Score s
s.player = 3 : s.points = 40
WriteRecord( of Score )( f, 3, s )       '' records 1 and 2 are zeros
print RecordCount( of Score )( f ).Value( )    '' 3
f.Close( )
RemoveFile( "scores.dat" )

Library: Filesystem Library Category: File Streams Documented under: Records

Clone this wiki locally