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
 Set Column Values: referencing by sheet and column
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

AKazak

Russia
1205 Posts

Posted - 04/05/2022 :  07:00:35 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
OriginPro 2022 (64-bit) SR1 9.9.0.225
Windows 7 Pro SP1 x64

Greetings!

What is the correct approach to fill the columns C and D using Set Column Values...?



Thank you.

---
Andrey

Edited by - AKazak on 04/05/2022 07:20:27 AM

AKazak

Russia
1205 Posts

Posted - 04/05/2022 :  09:51:23 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I prepared a sample project illustrating the question:
https://my.originlab.com/ftp/forum_and_kbase/Images/Set%20Column%20Value%20Reference.opju

---
Andrey
Go to Top of Page

AKazak

Russia
1205 Posts

Posted - 04/06/2022 :  08:26:41 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Setting Column Values tutorial @ https://www.originlab.com/index.aspx?go=Products/Origin/DataManagement/WorkbooksAndWorksheets&ss=chm&pid=1556 doesn't help in solving the problem.

Can you share a hint, please?

---
Andrey

Edited by - AKazak on 04/06/2022 08:27:11 AM
Go to Top of Page

YimingChen

1649 Posts

Posted - 04/06/2022 :  09:43:53 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
See the attached figure a LT solution:


James
Go to Top of Page

AKazak

Russia
1205 Posts

Posted - 04/06/2022 :  11:41:12 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Dear James,

Nice trick!
Can you show the script for calculating column D (total value), please?

---
Andrey
Go to Top of Page

ChaoC

USA
185 Posts

Posted - 04/06/2022 :  11:45:53 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Andrey,

The script is similar. Instead of return rng[1];,
it is return Total(rng);

Chao
Go to Top of Page

AKazak

Russia
1205 Posts

Posted - 04/06/2022 :  12:30:12 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by ChaoC

Hi Andrey,

The script is similar. Instead of return rng[1];,
it is return Total(rng);

Chao



Cool, thank you!

Does the customly defined function run faster than a for loop in the Before Formula Script?

---
Andrey
Go to Top of Page

YimingChen

1649 Posts

Posted - 04/06/2022 :  1:59:43 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Yes, the function is applied to the input column(s) row by row. So there is no overhead as to copy the entire column and do for loop.

James
Go to Top of Page

AKazak

Russia
1205 Posts

Posted - 04/07/2022 :  03:01:19 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by YimingChen

Yes, the function is applied to the input column(s) row by row. So there is no overhead as to copy the entire column and do for loop.

James



Got it!

What if I want to add an numerical offset to B value before sending it to the formula.
The following code doesn't work:
GetFirstCellValue("A$" + "!" + $(B+2))


---
Andrey

Edited by - AKazak on 04/07/2022 03:01:50 AM
Go to Top of Page

minimax

355 Posts

Posted - 04/07/2022 :  05:10:01 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi AKazak,

You may change the function prototype a bit, like

function double getFirstCell(string sheet, int col, int offset=0)
{
    string strcol = $(col + offset);
    string strrng = sheet$ + "!" + strcol$;
    range rng = strrng$;
    return rng[1];
}


and call it with getFirstCell(A$,B,2)
Go to Top of Page

AKazak

Russia
1205 Posts

Posted - 04/07/2022 :  08:47:33 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by minimax

Hi AKazak,

You may change the function prototype a bit, like

function double getFirstCell(string sheet, int col, int offset=0)
{
    string strcol = $(col + offset);
    string strrng = sheet$ + "!" + strcol$;
    range rng = strrng$;
    return rng[1];
}


and call it with getFirstCell(A$,B,2)



OK, got it!

Anyway can I use the syntax similar to the following?
GetFirstCellValue("A$" + "!" + $(B+2))


---
Andrey
Go to Top of Page

YimingChen

1649 Posts

Posted - 04/07/2022 :  09:10:51 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
We don't support range string as function input right now. I created a jira for it: ORG-25024. Thanks.

James
Go to Top of Page

AKazak

Russia
1205 Posts

Posted - 07/15/2022 :  05:34:10 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Can you look at a reason, for which the following code works correctly:
function double GetFirstCellValue (string CellAddress) {
  range ColumnRange = 1!wcol(2)[3];
  return ColumnRange;
}

if I call:
GetFirstCellValue( "1!wcol(" + C$ + ")" )


but the following code:
function double GetFirstCellValue (string CellAddress) {
  type CellAddress$;
  range ColumnRange = CellAddress$;
  return ColumnRange;
}


returns the error:
quote:
Undefined variable: COLUMNRANGE
if I call:
GetFirstCellValue( "1!wcol(" + C$ + ")" + "[1]" )


Is this a bug?
Can you explain what is my mistake, please?

Thank you.

---
Andrey

Edited by - AKazak on 07/15/2022 05:35:04 AM
Go to Top of Page

YimingChen

1649 Posts

Posted - 07/15/2022 :  10:30:16 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
The problem is from this line
range ColumnRange = CellAddress$;


You need to use
range ColumnRange = %(CellAddress$);


Quote from this page:
https://www.originlab.com/doc/en/LabTalk/guide/Substitution-Notation#.25.28_.29_Substitution

If a string is needed as an argument, you have to pass in a string variable or a string expression using the %( ) substitution to resolve run-time values.

James
Go to Top of Page

AKazak

Russia
1205 Posts

Posted - 07/15/2022 :  11:18:33 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by YimingChen

The problem is from this line
range ColumnRange = CellAddress$;


You need to use
range ColumnRange = %(CellAddress$);


Quote from this page:
https://www.originlab.com/doc/en/LabTalk/guide/Substitution-Notation#.25.28_.29_Substitution

If a string is needed as an argument, you have to pass in a string variable or a string expression using the %( ) substitution to resolve run-time values.

James



Dear James,

I changed the line to
range ColumnRange = %(CellAddress$);


but still get the same error:
quote:
Undefined variable: COLUMNRANGE


Please see a sample OPJU:
https://my.originlab.com/ftp/forum_and_kbase/Images/GetFirstCellValue%202022-07-15.opju

---
Andrey
Go to Top of Page

YimingChen

1649 Posts

Posted - 07/15/2022 :  12:06:33 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
It is a strange bug related to wcol(). Can you try the line below in col(B):
GetFirstCellValue( "1!" + A$ + "[1]")
Go to Top of Page

AKazak

Russia
1205 Posts

Posted - 07/15/2022 :  12:17:11 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by YimingChen

It is a strange bug related to wcol(). Can you try the line below in col(B):
GetFirstCellValue( "1!" + A$ + "[1]")




This works!
Where do I read more about the 1!2[3] syntax?

Anyway, can you investigate and fix the bug with wcol(), please?

---
Andrey
Go to Top of Page

YimingChen

1649 Posts

Posted - 07/15/2022 :  12:36:38 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You may refer to the range notation page:
https://www.originlab.com/doc/en/LabTalk/guide/Range-Notation#ColumnRange.2C_Column

I created jira item ORG-25503 to address this issue.
Go to Top of Page

AKazak

Russia
1205 Posts

Posted - 07/15/2022 :  12:54:49 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by YimingChen

You may refer to the range notation page:
https://www.originlab.com/doc/en/LabTalk/guide/Range-Notation#ColumnRange.2C_Column

I created jira item ORG-25503 to address this issue.




Got it.

Can you explain the key differences between wcol() and col(), please?

---
Andrey
Go to Top of Page

YimingChen

1649 Posts

Posted - 07/15/2022 :  3:14:44 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
wcol() accepts numeric variable or expression, while col() accepts column name or column index.
https://www.originlab.com/doc/LabTalk/ref/Col-func

James
Go to Top of Page

AKazak

Russia
1205 Posts

Posted - 07/16/2022 :  12:23:29 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by YimingChen

wcol() accepts numeric variable or expression, while col() accepts column name or column index.
https://www.originlab.com/doc/LabTalk/ref/Col-func

James



Dear James,

Got it.
Thanks.

---
Andrey
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