ITabRange.IfError

Syntax

IfError(Var ValueIfError: Variant);

Parameters

ValueIfError. The message that will be displayed if the cell contains error.

Description

The IfError method returns the cell value if it does not contain errors, otherwise it contains the specified value.

Example

Executing the example requires that the repository contains a regular report with the RO identifier. The report contains data.

Add links to the Metabase, Report and Tab system assemblies.

Sub UserProc;
Var
    MB: IMetabase;
    Regrep: IPrxReport;
    Table: IPrxTable;
    Tsheet: ITabSheet;
    Range, DestRange: ITabRange;
    value: Variant;
    i, j: integer;
Begin
    // Get current repository
    MB := MetabaseClass.Active;
    // Get regular report
    Regrep := mb.ItemById("RO").Bind As IPrxReport;
    // Get regular report sheet table
    Table := Regrep.Activesheet As IPrxTable;
    TSheet := Table.TabSheet;
    // Determine range
    Range := TSheet.Cells(1126);
    // Determine cell with error
    For i := Range.Top To Range.Bottom Do
        For j := Range.Left To Range.Right Do
            value := "cell contains error";
            DestRange := TSheet.Cell(i, j);
            DestRange.IfError(value);
            Debug.WriteLine("Cell value " + DestRange.Address + ": " + (value As String));
        End For;
    End For;
    // Determine maximum and minimum range values
    Range.Recalc;
    value1 := Range.MaxValue;
    value2 := Range.MinValue;
    Debug.WriteLine("Maximum value: " + value1 As String);
    Debug.WriteLine("Minimum value: " + value2 As String);
    Try
    If value1.IsEmpty Then
        Raise New TabNoDataException.CreateEx;
    End If;
    Except On ex: Exception Do
        Debug.WriteLine(ex.Message);
    End Try;
    // Check cell value type
    Range := TSheet.Cell(21);
    Debug.WriteLine("Logical value: " + TabCellValidate.IsBoolean(value1).ToString);
    Debug.WriteLine("Numeric value: " + TabCellValidate.IsNumber(value1).ToString);
    Debug.WriteLine("Text value: " + TabCellValidate.IsText(value1).ToString);
    Debug.WriteLine("Value with error: " + TabCellValidate.IsError(value1).ToString);
    Debug.WriteLine("Value is unavailable: " + TabCellValidate.IsNA(value1).ToString);
End Sub UserProc;

After executing the example the console window displays cell values if data does not contain errors or contains the specified message if the error contains an error.

See also:

ITabRange