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
 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Script before Formula in worksheet

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
VanAwful Posted - 08/24/2019 : 9:32:39 PM
I'm having an issue with a very simple process. In my worksheet I want to use If-Else to compare Col(H) to 0. If true then set x=0, if false set x=1. This is the code:


if (Col(H)==0)
{
  x=0;
}
Else
{
  x=1;
}


I then put x in the formula window. When I apply, it evaluates all rows as 0.

Not sure what I am doing wrong. Yes, I know I can use an IF-ELSE in the formula field. I am doing it this way as a start to a much larger script, but I need to understand how to make this IF-ELSE work in the script first before proceeding.

UPDATE: Appears it is only evaluating on the first row then applying to all rows. How do I make the LabTalk script process against each row?

7   L A T E S T    R E P L I E S    (Newest First)
cpyang Posted - 08/28/2019 : 1:12:41 PM
quote:
Originally posted by aplotnikov

I'm just wondering why not to use the simpliest formula for Col(J) values? It works for sure in any Origin version.

Col(H)==0 ? 0 : 1


What is the reason to define an additional function?



His example code is to just illustrate his point, but his actual code is much more complicated and cannot be expressed as an expression.

CP
aplotnikov Posted - 08/27/2019 : 03:20:31 AM
I'm just wondering why not to use the simpliest formula for Col(J) values? It works for sure in any Origin version.

Col(H)==0 ? 0 : 1


What is the reason to define an additional function?
VanAwful Posted - 08/26/2019 : 3:35:12 PM
@cpyang

Thank You! That is what I was looking for.
cpyang Posted - 08/26/2019 : 1:42:22 PM
if more complicated code needed, then you may consider using LabTalk function, like this



Before formula script is executed only once, so you define a function there and use it as column formula.

You can google "Labtalk Function" for more details.

CP
VanAwful Posted - 08/26/2019 : 08:48:30 AM
I am using version 2019b.

Using if(col(A)==0, 0, 1) will not work for what I need. The example I provided is only the start. I need to make it work first.


if (Col(H)==0)
{
  x=0;
  <write row values to different sheet in next open row of col(A)>
}
Else
{
  x=1;
  <write rest of script based on x=1>    
}

<provide new value for x to use in cell>
aplotnikov Posted - 08/26/2019 : 04:55:01 AM
Hi!

Just a remark.

If()-function was implemented since the ver. 2019SR0. If you have an earlier version you should use the ternary (conditional) operator "?:" which works in the recent versions as well.
yuki_wu Posted - 08/26/2019 : 02:41:21 AM
Hi,

Just use if function like:
if(col(A)==0, 0, 1)
https://www.originlab.com/doc/LabTalk/ref/If-func

Regards,
Yuki
OriginLab

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000