Put statement - MapBasic - 2023

MapInfo MapBasic Reference

Product type
Software
Portfolio
Locate
Product family
MapInfo
Product
MapInfo > MapBasic
Version
2023
Language
English
Product name
MapBasic
Title
MapInfo MapBasic Reference
First publish date
1985
Last updated
2023-09-12
Published on
2023-09-12T16:32:32.686312

Purpose

Writes the contents of a MapBasic variable to an open file.

Syntax

Put [ # ] filenum, [ position,] var_name

filenum is the number of a file opened through an Open File statement.

position is the file position to write to (does not apply to sequential file access).

var_name is the name of a variable which contains the data to be written.

Description

The Put statement writes to an open file.

Note: If the Open File statement specified a sequential access mode (Output or Append), use the Print # statement or the Write # statement instead of Put.

If the Open File statement specified Random file access, the Put statement's Position clause can be used to indicate which record in the file to overwrite. When the file is opened, the file position points to the first record of the file (record 1). If the Open File statement specified Binary file access, one variable can be written at a time. The byte sequence written to the file depends on whether the hardware platform's byte ordering; see the ByteOrder clause of the Open File statement. The number of bytes written depends on the variable type, as summarized below:

Variable Type Storage In File
Logical One byte, either 0 or non-zero.
SmallInt Two byte integer
Integer Four byte integer
Float Eight byte IEEE format
String Length of string plus a byte for a 0 string terminator
Date Four bytes: Small integer year, byte month, byte day
Other Variable types Cannot be written.

The Position parameter sets the file pointer to a specific offset in the file. When the file is opened, the position is initialized to 1 (the start of the file). As a Put is done, the position is incremented by the number of bytes written. If the Position clause is not used, the Put simply writes to the current file position. If the file was opened in Binary mode, the Put statement cannot specify a variable-length string variable; any string variable used in a Put statement must be fixed-length. If the file was opened in Random mode, the Put statement cannot specify a fixed-length string variable which is longer than the record length of the file.

See Also:

EOF() function, Get statement, Open File statement, Print # statement, Write # statement