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
 Origin Forum
 complex for and if statement

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
zknauss Posted - 07/25/2022 : 09:41:23 AM
I am trying to run the following for/if statement

for (int i = 2; i <= wks.ncols; i++ ) { wcol(i)[1] = if([NCONT1PeakDat]"Frequency_N_CON_T1"!$(i)[10]==0,A,B); }

and am having two issues. first I cant seem to get the output letter into row 1 col "i" instead it seems to try to input the A or B column. Second, when I change the output to numeric values as below I always get the failed response of "2" and what I've determined is that it does not accept the values on the source worksheets and thus returns "2". The source worksheets that are compared here are located in separate folders of the project. I'd appreciate any help with getting this to work. Thanks!

for (int i = 2; i <= wks.ncols; i++ ) { wcol(i)[1] = if([NCONT1PeakDat]"Frequency_N_CON_T1"!$(i)[10]==0,1,2); }


ZTK
4   L A T E S T    R E P L I E S    (Newest First)
zknauss Posted - 07/26/2022 : 09:34:52 AM
That worked!! Thanks

ZTK
YimingChen Posted - 07/25/2022 : 4:54:28 PM
You are missing the dollar signs:
wcol(i)[2]$ = if(bb[10]>aa[15],"A",if(bb[10]<aa[14],"C",if(bb[10]==0,"D","B")$)$)$;

zknauss Posted - 07/25/2022 : 4:38:17 PM
So that worked but the next few failed when I tried to run multiple if statements in the same line see below.

for (int i = 2; i <= wks.ncols; i++ ) { range aa = [NCONT1PeakDat]"Frequency_N_CON_T1"!$(i); range bb = [NCONT2PeakDat]"Frequency_N_CON_T2"!$(i); wcol(i)[2]$ = if(bb[10]>aa[15],"A",if(bb[10]<aa[14],"C",if(bb[10]==0,"D","B")))$; }

for (int i = 2; i <= wks.ncols; i++ ) { range bb = [NCONT2PeakDat]"Frequency_N_CON_T2"!$(i); range cc = [NCONT3PeakDat]"Frequency_N_CON_T3"!$(i); wcol(i)[3]$ = if(cc[10]>bb[15],"A",if(cc[10]<bb[14],"C",if(cc[10]==0,"D","B")))$; }

instead what I get is an output of the if statement at the end for example in row 2

"C",if(bb[10]==0,"D","B"

ZTK
YimingChen Posted - 07/25/2022 : 11:12:27 AM
You need to define a column range first. And you need dollar sign to assign text to a cell. Can you try the code below?
for (int i = 2; i <= wks.ncols; i++ ) 
{ 
	range rr = [NCONT1PeakDat]"Frequency_N_CON_T1"!$(i);
	wcol(i)[1]$ = if(rr[10]==0,"A","B")$; 
}


James

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