The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum
 Origin Forum
 LabTalk and Set Column Values
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

bur2000

Germany
36 Posts

Posted - 12/11/2013 :  08:59:19 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): 8.6

I want to add the values of three columns, then round the result to 3 digits and write it to a fourth column.

I was trying this script in Set Column Values...

double sum = Col(A)+Col(B)+Col(C);
double roundSum = Round(sum,3);

Unfortunately this enters the sum of the first rows in all rows of Col(D). I tried Col(A)[i], but that doesn't work at all.

Is it possible to address the specific row in a script?

snowli

USA
1379 Posts

Posted - 12/11/2013 :  10:29:51 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Open Set Column Values dialog of the 4th column.

Enter
round(col(A)+col(B)+col(C),3)

in the formula box.

It will add each row and round to 3 digits.


You defined double for sum and roundsum so they only return one value. You don't have to use the script before fomula in such case.

Thanks, Snow
OriginLab Corp.

Edited by - snowli on 12/11/2013 10:33:00 AM
Go to Top of Page

lkb0221

China
497 Posts

Posted - 12/11/2013 :  10:32:18 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi, Bur

That is because you defined the variable "sum" and "roundsum" to be double, which can only keep one numeric data.

I guess you want to let each row in col(D) has the rounded sum of column A, B and C correspondingly.

To do this, just change all the "double" to "dataset".

Zheng
OriginLab

Edited by - lkb0221 on 12/11/2013 10:33:22 AM
Go to Top of Page

bur2000

Germany
36 Posts

Posted - 12/11/2013 :  10:46:38 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks for your replies.

So when using "Set Column values" the script is only run once and then the formula box is applied to each row? I thought the script was run for each row.

Dataset also works well, but I don't understand why range can't be used in this case. I tried range and it doesn't sum the values but simply uses the values of the first column.

For example
range sum = Col(A)+Col(B);

Fills the column with the values of A.
Go to Top of Page

lkb0221

China
497 Posts

Posted - 12/11/2013 :  3:21:01 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
In Set Values dialog, because your input is a dataset, Col(A)+Col(B)+Col(C), so the output will also be a dataset. So it will only run once and give all the values.

The data type of range is like a pointer, it just allows you to access your data easily in a standard way. But itself does not contain any data.
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000