2.14.2.6 dlgChkList


Brief Information

A simple checklist dialog that outputs user choices to worksheet

Additional Information

Minimum Origin Version Required: 8.5 SR0

Command Line Usage

Dataset vnStat;
// Creates a dialog with 2 checkboxes. The 1-based indices of the checked checkboxes is output to the Dataset.
dlgChkList  inames:="Descriptive Statistics|Normality Test" osel:=vnStat;  

X-Function Execution Options

Please refer to the page for additional option switches when accessing the x-function from script

Variables

Display
Name
Variable
Name
I/O
and
Type
Default
Value
Description
Check Names inames

Input

string

"Case 1|Case 2|Case 3"
String contains the text names for the checkboxes in the dialog. Individual texts are separated by '|' within the string.
Dialog Title title

Input

string

Checkbox List
The text that appears in the title bar for the dialog.
Description desc

Input

string

Please select the needed cases
A text description for the dialog. It is displayed above the checkboxes in the dialog.
Choices ochks

Input

vector

<optional>
A vector (e.g. A Loose Dataset) specifying each checkbox's checked status.
  • 0: unchecked
  • 1: checked
Selected Indices osel

Output

vector

<optional>
A vector containing the indices of the checked checkboxes once dialog closes. Unchecked ones are not included in vector. The index is 1-offset.
Selected as a comma separated string olist

Output

string

<optional>
A string of selected checkbox indices separated by commas. Same as osel output variable but in a delimited-string form.

Description

This X-Function opens a dialog with an arbitrary number of checkboxes whose texts are based on a delimited-string input variable. The status of the checked checkoxes is available once the dialog is closed. It can be used to provide interactive options in Labtalk script.

Examples

  • Code Sample 1.

In this example, the use of the dlgChkList X-function will not only be illustrated, but a StringArray will be used to build a list of checkbox texts, a Loose Dataset will be used to specify which checkboxes are checked by default, and the results will be iterated to output which checkboxes were checked.

// Create StringArray of checkbox texts and Dataset of which are checked by default.
StringArray saTexts;
Dataset dsDefaults;
// Add texts to StringArray and default checked states to Dataset (0=unchecked, 1=checked).
saTexts.Add("Option #1");
dsDefaults.Add(1);
saTexts.Add("Option #2");
dsDefaults.Add(0);
saTexts.Add("Option #3");
dsDefaults.Add(0);
saTexts.Add("Option #4");
dsDefaults.Add(0);
saTexts.Add("Option #5");
dsDefaults.Add(1);
// Combine texts in StringArray into a single string variable with each option separated by a "|".
string strTexts$;
int nSize = saTexts.GetSize();
loop(nn, 1, nSize)
{
	strTexts$ += saTexts.GetAt(nn)$;
	if (nn != nSize)
		strTexts$ += "|";
}
// Create a Dataset to hold the indices of the checkboxes that get checked while dialog is open. 
Dataset dsChecked;
// Integer flag to determine if Cancel button was clicked in dialog.
// Must set it to true (1) to work properly.
int nCancelled = 1;

// Surround X-Function call with braces to trap any error returned during execution.
// If user clicks the Cancel button, there would be an error generated. This will stop that behavior.
{
dlgChkList inames:=strTexts$ title:="Options Dialog" desc:="Select one or more options." ochks:=dsDefaults osel:=dsChecked;
// If user clicked the Cancel button, the following line will not run and nCancelled will remain equal to 1.
nCancelled = 0;
}
// Test of user clicked the Cancel button and if so, stop script execution.
if (1 == nCancelled)
	return;

// User did not click Cancel, so output the checked checkboxes by looping through the Dataset of indices
// and using the values from that Dataset to get the relevant Texts from the original StringArray.
type "You have checked:";
int nSize = dsChecked.GetSize();
loop(nn, 1, nSize)
{
	// Because GetAt() returns a string, don't forget to add a $ at end of function call.
	type saTexts.GetAt(dsChecked[nn])$;
}
  • Code Sample 2.
// The following script allow user to pick a few sheets from the active book and do
// row average on each column and output the results into Mean,N, SD sheets in the same book
//prepare two sheets with data
string fn1$=system.path.program$+"Samples\Curve Fitting\Dose Response - Inhibitor.dat";
string fn2$=system.path.program$+"Samples\Curve Fitting\Dose Response - No Inhibitor.dat";
newbook;
impASC fn1$;
newsheet;
impASC fn2$;
string sheets$;// string to hold all sheet names from active book
loop(ii,1,page.nLayers)
{
	range ss = $(ii)!;
	if(ii > 1) sheets$+="|";
	sheets$ += ss.name$;
}
dataset vnSels;
string strSelShts;

dlgChkList i:=sheets$ olist:=strSelShts osel:=vnSels;

if(strSelShts.GetLength() < 1)
{
	type "No sheet selected";
	return 0;
}
int nSel = vnSels[1];// first selected sheet
range s1 = $(nSel)!;
int ncols=s1.ncols;//save number of columns of first selected sheet
//ncols=;
loop(i,1,ncols) 
{
   rowstats (%(strSelShts$))!wcol(i) mean:=Mean!wcol(i) n:=N!wcol(i) sd:=SD!wcol(i);
}