# 2.8.5 csetvalue

Programmatic equivalent of Column : Set Column Values... menu option.

## Brief Information

Set column values with custom formula

Minimum Origin Version Required:Origin 8.5 SR0

X-Function not designed for Auto GetN Dialog.

## Command Line Usage

 

1. csetvalue formula:="int(rnd()*100)" //Set active column random number less than 100 

2. csetvalue col:=col(b) formula:="sin(Col(A))" script:="Col(A) = Data(0.1,6.2,0.1)" //Use built-in function in the before formula script 

3. csetvalue col:=sheet1!A[3:10] formula:="i*i" //Set values for a range with row index i as a variable 

4. csetvalue col:=col(B) formula:="total(col(A)[i-3:i+3])"; //Set values for a specified column by a sub-range from other column. (" i " is the row index.) 

5. csetvalue col:=col(B) formula:="col(Sensor Amp)*0.5"; //When calling columns using column Long Name,e.g.,Sensor Amp, you should remove the quotation mark. 

## Variables

Display
Name
Variable
Name
I/O
and
Type
Default
Value
Description
Column col

Input

Range

<active>
Specify the target column in which the values will be input.
Formula formula

Input

string

"?"
Specify the formula to compute the values for the target column.
Before Formula Script script

Input

string

"?"
Specify LabTalk scripts and the scripts will be executed before the Formula has been executed.
Recalculate Mode recalculate

Input

int

2
Specify the Recalculate mode.

Option list:

• none:None
Do not update the output when the source data changes
• auto:Auto
Automatically update the output when the source data changes
• manual:Manual
Manually update the output when the source data changes

## Description

This X-Function is designed for realizing the same ability as the Set Column Values option in the Column menu, which is used to fill a column or part of a column with data.
Note that use of Recalculate of Auto or Manual requires that the output is a different column than the input.

## Examples

This example is similar to the Quick Start Set Column Values example, which shows you how to use the csetvalue example to input values for two columns in a worksheet. To use the following scripts, please first create a new project to make sure there is a worksheet called Sheet1 in Book1.

csetvalue col:=[Book1]Sheet1!col(A) formula:="Data(-1,5,0.03)" //Input values for Column A
csetvalue col:=[Book1]Sheet1!col(b) formula:=" 1 + (5/(1.5*sqrt(PI/2)))*exp(-2*((col(a)-2)/1.5)^2)"//Input values for Column B

This example shows to use the before formula script to call columns from other workbooks and set recalculation mode to automatically update results.

newbook;
%A=%H;//store the workbook name of the newly created book.
csetvalue col:=1 formula:="Data(0,1,0.01)";//Set values for column A in the first new book
newbook;
%B=%H;//store the workbook name of the newly created book.
wks.nCols=12;
//The following loop will set value for each column in the second new book with the value from the first new book
for(int ii=1; ii<=12; ii++)
{
csetvalue col:=[%A]Sheet1!col(2) formula:="sin(r1)+ii" script:="range r1=[%A]Sheet1!col(1)" recalculate:=1;//Recalculation mode set to "Auto"
csetvalue col:=[%B]Sheet1!col(\$(ii)) formula:="r2" script:="range r2=[%A]Sheet1!col(2)" recalculate:=0;//Recalculation mode set to "none"
}