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 for Programming
 LabTalk Forum
 csetvalue error
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Francesco84

Italy
21 Posts

Posted - 06/26/2019 :  03:52:40 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. 2019b
Operating System: Windows 10

Good morning,
I would like to ask a question.

I have a workbook with 4 columns and 3 rows;

For each row, I have to sum the elements and write the sum in a fifth column (Col E).

I use this code:

csetvalue col:=col(E)
formula:="Sum"
script:="
dataset Sum;
for (int j=1; j<=3; j++) //Rows
{
for (int i=1; i<=4; i++) // Columns
Sum[j]+=Col($(i))[$(j)];
}
"
recalculate:=1;

I get the following errors:
Invalid Column Name: COL(--)

The strange thing is that if I go to "Set Column Value" menu and insert the script, I don't get errors

Where am I doing wrong?

Thank you
Francesco

yuki_wu

896 Posts

Posted - 06/26/2019 :  06:18:16 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Francesco,

When we execute the scripts in Script Window or Command Window, variable with $ will be resolved to its actual value directly before it is passed into Before Script options.
https://www.originlab.com/doc/Quick-Help/Avoid-Substituted

To fix this issue, we could change the code like:

%A = $;
csetvalue col:=col(E)
formula:="Sum"
script:="
dataset Sum;
for (int j=1; j<=3; j++) //Rows
{
for (int i=1; i<=4; i++) // Columns
Sum[j]+=Col(%A (i))[ %A (j)];
}
"
recalculate:=1;


In fact, we could easily use “A+B+C+D” to sum the values for each row:
csetvalue col:=col(E) formula:="A+B+C+D" recalculate:=1;


Regards,
Yuki
OriginLab
Go to Top of Page

Francesco84

Italy
21 Posts

Posted - 06/27/2019 :  09:32:58 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks Yuki,
it works perfectly.

Another small question, please.
I have to calculate an integral and store the area value for subsequent operations. I use the integ1 function.
This is the code:

double area_integ;
integ1 iy:=(col(B),col(C)) type:=math area:=area_integ -r 1;

I would like to know if the variable "area_integ" must be of type Project or Session (as I wrote in the code), so that if the function to be integrated changes, its value also changes.

Thank you
Francesco
Go to Top of Page

Chris D

428 Posts

Posted - 06/27/2019 :  09:55:11 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
It depends on your needs.

Run the command
list;
to open the LabTalk Variables and Functions dialog.

Then run your code and refresh the list in the dialog (there is a refresh button). You will observe your variable.

Now, trigger the recalculation on the new operation by changing either an X or Y value.

Back in the LabTalk Variables and Functions dialog, refresh the list and observe that the value of the variable has changed.

If you want the variable to persist with the project specify it as a Project variable. If you want it to persist only for the currently running Origin session, use a Session variable.

I hope this helps.

Thanks,
Chris Drozdowski
Originlab Technical Support
Go to Top of Page

Francesco84

Italy
21 Posts

Posted - 07/01/2019 :  08:33:52 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you Chris,
I tried your suggestion; it was useful for me to better understand the difference between Project and Session variables.

Francesco
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