Search code examples
arraysif-statementcrystal-reportsincrement

Incrementing An Array Crystal Report


I have a user inputted parameter that can be 1 value up to how ever many values they enter. Right now where [i] is in the formula that is the index of the array of how many they enter. I need to increment the formula so that it iterates over every one of their parameters but no more than what they enetered. I tried hard coding indexes[1] through [20] but if there were fewer than 20 parameters entered I would get an error.

    if TONUMBER({?Order #}[i]) = TONUMBER({V_ORD_COMB.ORDERNO})
    then TRUE
    ELSE

    FALSE

This works fine for 1 input value but no more

    if TONUMBER({?Order #}[1]) = TONUMBER({V_ORD_COMB.ORDERNO})
    then TRUE
    ELSE

    FALSE

This works fine for 3 input values but no less or more

    if TONUMBER({?Order #}[1]) = TONUMBER({V_ORD_COMB.ORDERNO})
    then TRUE
    ELSE
    if TONUMBER({?Order #}[2]) = TONUMBER({V_ORD_COMB.ORDERNO})
    then TRUE
    ELSE
    if TONUMBER({?Order #}[3]) = TONUMBER({V_ORD_COMB.ORDERNO})
    then TRUE
    ELSE
    FALSE

I am trying to get it to work for any number of inputted parameters.


Solution

  • Try this:

    Local Numbervar i;
    Local Stringvar result:="not found";
    
    for i:=1 To Ubound({?Order #}) do (
        if {?Order #}[i]={V_ORD_COMB.ORDERNO} then  (
            result:="found";
            exit for
        );
    );
    
    result