Author |
Topic  |
|
AKazak
Russia
1205 Posts |
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 |
Edited by - AKazak on 04/05/2022 07:20:27 AM |
|
AKazak
Russia
1205 Posts |
|
AKazak
Russia
1205 Posts |
|
YimingChen
1649 Posts |
Posted - 04/06/2022 : 09:43:53 AM
|
See the attached figure a LT solution:

James |
 |
|
AKazak
Russia
1205 Posts |
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 |
 |
|
ChaoC
USA
185 Posts |
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
Russia
1205 Posts |
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 |
 |
|
YimingChen
1649 Posts |
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
Russia
1205 Posts |
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 |
Edited by - AKazak on 04/07/2022 03:01:50 AM |
 |
|
minimax
355 Posts |
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
Russia
1205 Posts |
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 |
 |
|
YimingChen
1649 Posts |
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
Russia
1205 Posts |
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 |
Edited by - AKazak on 07/15/2022 05:35:04 AM |
 |
|
YimingChen
1649 Posts |
|
AKazak
Russia
1205 Posts |
|
YimingChen
1649 Posts |
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
Russia
1205 Posts |
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
1649 Posts |
|
AKazak
Russia
1205 Posts |
|
YimingChen
1649 Posts |
|
AKazak
Russia
1205 Posts |
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 |
 |
|
|
Topic  |
|