Worksheet::FindColIndex

Description

Starting from a given column index, find a column with the required designation. The column returned could be the first or last found, dependending on the options, and the search could go to the left or to the right.

Syntax

int FindColIndex( int nRefCol, int nColDesignation, DWORD dwCntrl = 0 )

Parameters

nRefCol
[input] The index of the column from which to start the search.
nColDesignation
[input] The desired designation of the sought column (from the OKDATAOBJ_DESIGNATION_ enumeration).
dwCntrl
[input] Options - any combination of values from the enumeration:
enum {
FCI_RIGHT = 0x00001000, // search to the right of the starting column (if off, it will search to the left)
FCI_LAST_FOUND = 0x00002000, // if set, it will return the last column found in the given direction and with the given designation, otherwise the first.
};
default is 0.

Return

the column index if found, otherwise a negative number.

Examples

EX1

// Indicate error columns and their associated value columns (to left)
void Worksheet_FindColIndex_Ex1()
{
    Worksheet    wks;
    wks.Create("origin", CREATE_VISIBLE);
    int    ii, iCol, iColType;
    for( ii = 1 ; ii <= 10 ; ii++ )
        wks.AddCol();
    wks.SetColDesignations("XMYEYEXMYEYE");
    // Let's go left to right looking for Error columns
    for( ii = 0 ; ii < wks.GetNumCols() ; ii++ )
    {
        iColType = wks.Columns(ii).GetType();
        if( iColType == OKDATAOBJ_DESIGNATION_ERROR || iColType == OKDATAOBJ_DESIGNATION_X_ERROR)
        {
            // Once an error column is found, find first data to the left (no dwCntrl needed)
            switch(iColType)
            {
            case OKDATAOBJ_DESIGNATION_ERROR:
                // A Y Error column, so find its Y
                iCol = wks.FindColIndex( ii , OKDATAOBJ_DESIGNATION_Y );
                if( iCol < 0 )
                    printf("No Y column found for YErr column %u\n", ii + 1);
                else
                    printf("Y is column %u, YErr is column %u\n", iCol + 1, ii + 1);
                break;
            case OKDATAOBJ_DESIGNATION_X_ERROR:
                // An X Error column, so find its X
                iCol = wks.FindColIndex( ii , OKDATAOBJ_DESIGNATION_X );
                if( iCol < 0 )
                    printf("No X column found for XErr column %u\n", ii + 1);
                else
                    printf("X is column %u, XErr is column %u\n", iCol + 1, ii + 1);
            }
        }
    }
}

Remark

See Also

Worksheet::SetColDesignations, Column::SetType

header to Include

origin.h