FILE_PUTR

<< Click to Display Table of Contents >>

Navigation:  ThinBASIC Modules > File > FILE: functions working on files >

FILE_PUTR

 

Description

 

Write data record into a file open AS RANDOM

 

Syntax

 

n = FILE_PUTR(FileID, nRec, UDTStructure)

 

Returns

 

Number, error code.

 

Parameters

 

Name

Type

Optional

Meaning

FileID

Number

No

A previously open random access file handle

nRec

Number

No

Record number to be stored

UDTStructre

UDT

No

Any UDT data structure. Use the same UDT to GET data from and PUT into a random access file.

 

Remarks

 

Restrictions

 

See also

 

File_GETR

 

Examples

 

Thanks to Psch for the following script example

USES "File""Console"

 

Type tRecord

  LName As String * 12

  FName As String * 8

  Age   As Byte

End Type

 

Dim Item        As tRecord

Dim OutFileName As String = app_sourcepath & "Test.DAT"

Dim f           As DWORD

 

file_KILL(OutFileName)

f = file_Open(OutFileName, "random"SIZEOF(tRecord))

 

PRINTL "Vader in the file"

  Item.LName = "Vader"

  Item.FName = "Darth"

  Item.Age   = 40

  file_putr(f, 1, Item)

 

PRINTL "Yoda in the file"

  Item.LName = "Yoda"

  Item.FName = "Mister"

  Item.Age   = 45

  file_putr(f, 2, Item)

 

PRINTL "---------------------------"

 

PRINTL "Seeking first: "

  file_getr(f, 1, Item)

  PRINTL item.LName, item.FName, item.Age

 

PRINTL "Seeking second: "

  file_getr(f, 2, Item)

  PRINTL item.LName, item.FName, item.Age

 

file_Close(f)

 

WAITKEY