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
 complex for and if statement
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

zknauss

USA
72 Posts

Posted - 07/25/2022 :  09:41:23 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
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

YimingChen

1647 Posts

Posted - 07/25/2022 :  11:12:27 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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

Edited by - YimingChen on 07/25/2022 11:13:58 AM
Go to Top of Page

zknauss

USA
72 Posts

Posted - 07/25/2022 :  4:38:17 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

YimingChen

1647 Posts

Posted - 07/25/2022 :  4:54:28 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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")$)$)$;

Go to Top of Page

zknauss

USA
72 Posts

Posted - 07/26/2022 :  09:34:52 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
That worked!! Thanks

ZTK
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