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
 Using cell values in a function/script
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

DerekK

USA
14 Posts

Posted - 03/02/2016 :  3:58:32 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
I am not an expert yet on scripting, but I would like to try this...

I am using ReduceDup to create a new column. To change the range of x values for the input, I need to go into Change Parameters and modify manually.
Is there a way to get these values from other cells?

I tried to use Set Column Values to populate a column this way. So I did the generate script and got this...
reducedup -r 1 iy:=Data!(W1"T bin",L1"delta h")[x15:25] method:=sum;

I want to put this in the script before function. How do I make the "[x15:25]" read the 15 and 25 from cells in the worksheet?

Thanks, Derek

Origin Ver. and Service Release (Select Help-->About Origin): 2015sr1
Operating System: win7

Echo_Chu

China
Posts

Posted - 03/03/2016 :  05:04:24 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi, Derek

Please look at the image below as an example.
Column A and B are source data with duplicate X value. The X range is put in column C, starting as 5 and end as 12.

Then I set values of column D as in the dialog. And below are scripts which put in the Before Script Panel. the scripts read cell values to be r1 and r2 then use it in the reduceup function. Output the result to the 5th and 6th column.
Please note that in dialog I set column D = column C, which will trigger the recalculation if values of column C changes.

double  r1 = wcol(3)[1:1]; //1st row of col(c)
double  r2 = wcol(3)[2:2]; //2nd row of col(c)
reducedup iy:=1!(wcol(1),wcol(2))[x$(r1):$(r2)] oy:=(wcol(5), wcol(6));



Echo
OriginLab Corp
Go to Top of Page

DerekK

USA
14 Posts

Posted - 03/03/2016 :  12:34:18 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks, that works. Two questions...
I assume that column references in scripts are static... So, if I change the column order then the wcol() could refer to the wrong column. So is it safer to use the Col(A) or Col("XXXXX") method instead?

Also, I have pasted a link into a text field on a graph in a worksheet. When I save the worksheet as a template, it keeps the reference to the old sheet name (Book14) in the link. How do I make it refer to the current sheet name instead.

Range = %([Book14]Data,@WL,Y1[1], W) to %([Book14]Data,@WL,Y1[2], W)
Go to Top of Page

SeanMao

China
288 Posts

Posted - 03/03/2016 :  9:07:19 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

col("longname") is safer in case of column index change.

To refer to current workbook, you can use a built-in string register %H.

In your case, it would be:

Range = %([%H]Data,@WL,Y1[1], W) to %([%H]Data,@WL,Y1[2], W)

Please see the follow page for reference about other system string registers:

http://www.originlab.com/doc/LabTalk/guide/String-registers#String_Registers_as_System_VariablesSystem_VariableString_Register.2C_System_VariableSystem_Variable.2C_String_Regester

Regards!

Sean
Go to Top of Page

DerekK

USA
14 Posts

Posted - 03/04/2016 :  09:40:16 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Sean
Thanks for the response... As you showed, I used %H in place of "Book14", but that does not work (just the code of the link is shown). The linked value only displays if the "Book 14" is there.
Just to be clear, I am adding text on a graph. And I have made the graph as a sheet in the same workbook as the data sheet "Data".
When I type %H=; into the script window, I get "Graph4" which is the name of the graph sheet, not the workbook. I tried the other string registers and the closest I got was %E --> "[Book14]Graph4". I couldn't find one that returns just the "Book14".
- Derek
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 03/04/2016 :  9:05:26 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
We should add another string register to get the parent book name, but in the mean time, you can use

%(%(1Y,@W),@WL,B[1], W) 

Which will translate into %(Book14),@WL,B[1], W)

or to be more precise

%([%(1Y,@W)]%(1Y,@WS),@WL,B[1], W) 

In the [book]sheet notation.
The above is to find the sheet that hold the 1st data plot's Y column.

See
http://www.originlab.com/doc/LabTalk/ref/Legend-Substitution-Notation#List_of_.40Options

CP
Go to Top of Page

DanielSchumann

Germany
3 Posts

Posted - 09/30/2020 :  05:16:17 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hello,
I hope this is the right topic. But at least it is the most suitable for my problem.
I want to refer a bookname from a cell value in a formula.
Example:
In Cell A1 the bookname is written as string: "V1-1"
In Cell B1 is a formula which revers to another book with name in cell A1: =lastpoint([V1-1]1!L)

how do I refer cell A1 in the formula? I tried different ways, no one functioned.
Can you help me?

Thanks, Daniel
Go to Top of Page

YimingChen

1592 Posts

Posted - 09/30/2020 :  12:12:39 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Try the script below, it retrieves the last value of col(3) of workbook saved in A1.
=%([%(A1$)]1, 3, [%(A1$)]!wks.col3.nrows)




James

Edited by - YimingChen on 09/30/2020 12:14:25 PM
Go to Top of Page

DanielSchumann

Germany
3 Posts

Posted - 10/01/2020 :  03:14:11 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks James for this quick answer.
Unfortunately, it doesn't work. Error Message: unknown function.

Do you have any other idea?
Go to Top of Page

YimingChen

1592 Posts

Posted - 10/01/2020 :  08:30:21 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Please attach your two worksheets or send the project file to <tech@originlab.com> that we can check further.

James
Go to Top of Page

DanielSchumann

Germany
3 Posts

Posted - 10/01/2020 :  09:08:00 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks. I submitted the project to tech@originlab.com
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 10/01/2020 :  8:13:01 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Your book name might be an issue, but try this formula


=%([A1$],3,0)

Assuming the book name is in A1 and you want to get the last row value of the 3rd column.

The row index = 0 to get the last cell value was introduced in 2020b. ORG-21624-S2.

We will improve this in 2021, so you can do

=[A1$]1!C[0]



CP
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