Share this page

# Parameter Arrays

Some functions find matches inside data and save the results in a parameter. When more than one match is located, some of these functions save data in multiple parameters, numbered to emulate an array.

The members of the array are named with the base parameter name, an underscore, and an ordinal number. The number of items found is stored in a parameter named with the base parameter name, an underscore and "count".

For example:

1. A function is passed an output parameter name, "myparam".
2. The function returns 10 values.
3. The function creates 10 parameters and assigns the return values to them. The parameter names are myparam_1, myparam_2, myparam_3, ..., myparam_10.
4. The function creates parameter myparam_count, and assigns it the value 10.

Some of the functions that can create parameter arrays are lr_save_param_regexp, web_reg_save_param_ex, web_reg_save_param_xpath, web_reg_save_param_regexp, and sapgui_call_method_of_active_object_ex.

See Also

## Example of Parameter Array Use

In this example, lr_save_param_regexp is used to search a buffer and find all the substrings containing "XX", any two characters, and "YY".

    Action()
    {

        char * bufferToSearch =
            "_a_XX11YY_b_XX22YY_c_XX33YY_d_XX44YY_abcde";
        int matchCt, ord;
        char *arrayMemberValue;

        lr_save_param_regexp (
            bufferToSearch,
                   strlen(bufferToSearch),
                   "RegExp=(XX..YY)",
                   "Ordinal=All",
                   "ResultParam=reMatchesParam",
                   LAST );

        matchCt = lr_paramarr_len("reMatchesParam");

        lr_message("%d match(es) found.", matchCt);

        for (ord=1; ord <= matchCt; ord++){

                   arrayMemberValue =
                       lr_paramarr_idx("reMatchesParam", ord);

                   lr_message("Member %d value: %s",
                       ord, arrayMemberValue);

        }

        return 0;
    }

    Output:
    4 match(es) found.
    Member 1 value: XX11YY
    Member 2 value: XX22YY
    Member 3 value: XX33YY
    Member 4 value: XX44YY

## Example of Populating a Parameter Array

You can create a parameter array by populating the elements <name>_n. For example:
lr_save_string("value1", "MyTestParamArray_1");
lr_save_string("value2", "MyTestParamArray_2");

This code uses lr_save_string and strtok to extract values frin a string and populate the array.

    token = (char*) strtok(buffer, "\n"); // Get the first token

    if (token == NULL) {
    	lr_error_message ("No tokens found in string!");
    	return -1;
    }

    i = 0;
    while (token != NULL) { // While valid tokens are returned
    	++i;
    	sprintf(param_buf, "MyTestParamArray_%d", i);
    	lr_save_string(token, param_buf);
    	token = (char*) strtok(NULL, "\n");
    }

    lr_save_int(i, "MyTestParamArray_count");

    // Print all values of the parameter array.
    for (i=1; i<=lr_paramarr_len("MyTestParamArray"); i++) {
    		lr_output_message("Parameter value: %s", lr_paramarr_idx("MyTestParamArray", i));
    }

Tips to improve your search results... VuGen Function Reference Version 26.1 Function Reference 26.1 All View Local Help Center View Online Help Center Version: