PutVariant


The PutVariant method writes variant data sequence to file and returns number of elements actually written. File position is moved forward by the number of bytes written.
C++
long PutVariant(
  VARIANT *VariantBuffer,             // variant that contains data
  long NumberOfElements = -1,         // number of elements to write
  long FilePosition = -1              // position of data in file
);
BASIC
PutVariant(
  VariantBuffer As Variant,           // variant that contains data
  NumberOfElements As Long = -1,      // number of elements to write
  FilePosition As Long = -1           // position of data in file
) As Long

Parameters

VariantBuffer
Variant that contains data.
Variant can be of any allowed type, it can be either single variable or one dimensional array.
NumberOfElements
Number of elements in data sequence to write.
If this parameter is -1 length of sequence is determined by the number of elements in VariantBuffer.
FilePosition
Position in file to write data at.
If this parameter is -1 data is written at current file position.

Return Values

If the method succeeds, the return value is the number of elements actually written.
If the method fails, the return value is failure code and error code is set. Call GetError to get error code.

Remarks

VariantBuffer can be either single variable or one-dimensional array depending on how many elements are to be written. If only one element is written, VariantBuffer can be a single variable of given type. If more than one element is to be written, VariantBuffer must be a one-dimensional array of one of the allowed types.

VariantBuffer variant can be of one of allowed types: Byte, Integer, Long, Single, Double, String, Boolean, Date, Currency, Decimal and Variant. The array of variants is especially interesting because it allows writing complex structured data with fields of various types. The only limitation is that all arrays must be one-dimensional. As mentioned above VariantBuffer can contain String data; it should be noted, however, that text in variant is always represented by IXFile as length-prefixed Unicode.

NumberOfElements parameter always specifies total number of elements in data sequence regardless of its structure. It means that if VariantBuffer consists of nested subarrays, NumberOfElements specifies number of elements counted recursively through all subarrays - not elements in most outer array.

See Also

GetVariant, PutBit, PutByte, PutShort, PutLong, PutFloat, PutDouble, PutText, PutUnicodeText, PutBinary, Reading and Writing Data