Legato
Legato

GoFiler Legato Script Reference

 

Legato v 1.4j

Application v 5.22b

  

 

Chapter EightData Functions (continued)

CSVIsLastField Function

Overview

The CSVIsLastField function checks to see if any more data is available in the current record buffer.

Syntax/Parameters

Syntax

boolean = CSVIsLastField ( handle hCSV );

Parameters

hCSV

A handle to a valid CSV Object.

Return Value

Returns a boolean value as TRUE if there is no more data in the record buffer or FALSE if there is data. On error, the function returns TRUE, use the GetLastError function to retrieve a formatted error code.

Remarks

The CSVIsLastField function can be used to preemptively check if the source fields have been exhausted prior to calling the CSVGetStringField or CSVGetNumericField functions. The function considers the end of a row (line) as a last field.

When serially reading data from a CSV Object, the program must force an out of data condition to get the object to move to the next condition. As such, after an affirmative condition on a last field check, CSVGetStringField should be called to force the object to advance to the next record. For example:

handle          hCSV;
string          s1;
int             rx, cx;

s1 = "(insert your sample filename and path)";

s1 = FileToString(s1);
if (IsError(s1)) {
  MessageBox('x', "Error %08X opening source\r\r", GetLastError(), s1);
  exit;
  }
hCSV = CSVCreate(s1);
  
while (CSVIsLastRecord(hCSV) == FALSE) {
  rx++;
  AddMessage("Row %d", rx);
  cx = 1;
  while (CSVIsLastField(hCSV) == FALSE) {
    s1 = CSVGetStringField(hCSV);
    AddMessage("    %d : %s", cx, s1);
    }
  CSVGetStringField(hCSV);
  }

Notice at the bottom as the field loop exits, there is a call to CSVGetStringField to force the object to the next record.

Related Functions

Platform Support

Go13, Go16, GoFiler Complete, GoFiler Corporate, GoFiler, GoFiler Lite, GoXBRL

Legato IDE, Legato Basic