3.5 X-Function RangeListBox Example
X-Function Range
Summary
This example demonstrates how to use ListBox control for Range variable.
Steps
-
Open X-Function Builder from Tools menu, enter the X-Function name and variables, as in the following picture, and then click Save.
.
-
Open this X-Function in Code Builder to edit the source code. First include the needed header file, as below.
#include <..\OriginLab\wks_utils.h> // needed for init_GetN_col_list_ctrls function
-
In the X-Function's main function, collistex, add the following code to get the range string from the specified data range.
X-Function, Range
string str;
if(collist)
collist.GetRangeString(str, NTYPE_FOR_RANGE);
out_str(str);
-
In the X-Function's before_execute function collistex_before_execute, add the following code to initialize the control of collist variable. It will make collist a ListBox to list column range.
bool bIsStart = is_xf_startup(nGetNDialog, dwCntrl);
if(bIsStart && (dwCntrl & LTXF_SHOW_DIALOG))
{
init_GetN_col_list_ctrls(NULL, trGetN.collist);
}
Run the X-Function
-
run collistex -d in the Script window, and then you can see the dialog below.
-
click the ListBox's triangle button to add columns and you can select/unselect columns in the ListBox.
-
click OK. It will output the range of selected columns.