T O P I C R E V I E W |
AKazak |
Posted - 04/05/2022 : 07:00:35 AM 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 |
20 L A T E S T R E P L I E S (Newest First) |
AKazak |
Posted - 07/16/2022 : 12:23:29 AM 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 |
YimingChen |
Posted - 07/15/2022 : 3:14:44 PM wcol() accepts numeric variable or expression, while col() accepts column name or column index. https://www.originlab.com/doc/LabTalk/ref/Col-func
James |
AKazak |
Posted - 07/15/2022 : 12:54:49 PM 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 |
YimingChen |
Posted - 07/15/2022 : 12:36:38 PM 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.
|
AKazak |
Posted - 07/15/2022 : 12:17:11 PM 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 |
YimingChen |
Posted - 07/15/2022 : 12:06:33 PM It is a strange bug related to wcol(). Can you try the line below in col(B):
GetFirstCellValue( "1!" + A$ + "[1]") |
AKazak |
Posted - 07/15/2022 : 11:18:33 AM 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 |
YimingChen |
Posted - 07/15/2022 : 10:30:16 AM 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 |
AKazak |
Posted - 07/15/2022 : 05:34:10 AM 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 |
YimingChen |
Posted - 04/07/2022 : 09:10:51 AM We don't support range string as function input right now. I created a jira for it: ORG-25024. Thanks.
James |
AKazak |
Posted - 04/07/2022 : 08:47:33 AM 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 |
minimax |
Posted - 04/07/2022 : 05:10:01 AM 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) |
AKazak |
Posted - 04/07/2022 : 03:01:19 AM 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 |
YimingChen |
Posted - 04/06/2022 : 1:59:43 PM 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 |
AKazak |
Posted - 04/06/2022 : 12:30:12 PM 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 |
ChaoC |
Posted - 04/06/2022 : 11:45:53 AM Hi Andrey,
The script is similar. Instead of return rng[1];, it is return Total(rng);
Chao |
AKazak |
Posted - 04/06/2022 : 11:41:12 AM Dear James,
Nice trick! Can you show the script for calculating column D (total value), please?
--- Andrey |
YimingChen |
Posted - 04/06/2022 : 09:43:53 AM See the attached figure a LT solution:

James |
AKazak |
Posted - 04/06/2022 : 08:26:41 AM 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 |
AKazak |
Posted - 04/05/2022 : 09:51:23 AM I prepared a sample project illustrating the question: https://my.originlab.com/ftp/forum_and_kbase/Images/Set%20Column%20Value%20Reference.opju
--- Andrey |