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 for Programming
 LabTalk Forum
 script divide columns
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

It251

United Kingdom
7 Posts

Posted - 01/14/2020 :  08:23:50 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
I'm new to the forum and to scripting.

I would like to divide all Y columns (in a worksheet containing 100+ columns) by a specific one. How can I do this?

Thanks

It251

yuki_wu

896 Posts

Posted - 01/14/2020 :  9:17:56 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi It251,

To loop over columns in the worksheet:

//assume source data in [book1]sheet1!
int ncols = wks.ncols;
//add new worksheet for the results
newsheet name:=sheet2 cols:=ncols;
//activate the source data worksheet
page.active = 1;
//loop over columns in worksheet, and put the result in the corresponding column of new worksheet [book1]sheet2!
for(int ii = 1; ii <= ncols; ii++) {
	range ss = [book1]sheet1!col($(ii));
	range dd = [book1]sheet2!col($(ii));
	dd = ss/100;;
}

Hope it helps.

Regards, Yuki
OriginLab

Edited by - yuki_wu on 01/14/2020 9:18:42 PM
Go to Top of Page

It251

United Kingdom
7 Posts

Posted - 01/15/2020 :  10:48:31 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you very much Yuki.

I got to:

for (ii=2; ii<=wks.ncols; ii+2)
{Col($(ii))=Col($(ii))/Col(AN); }

The problem I got now is that when the script reaches column AN it does AN/AN=1 ... so all the subsequent columns get divided by 1. Is there any way of create an exception so the above operation doesn't apply to Col(AN)?


Regards

It251
Go to Top of Page

It251

United Kingdom
7 Posts

Posted - 01/15/2020 :  11:54:11 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I solved it this way:

for (ii=2; ii<40; ii+2)
{Col($(ii))=Col($(ii))/Col(AN); }

for (ii=42; ii<=wks.ncols; ii+2)
{Col($(ii))=Col($(ii))/Col(AN); }

it's not very elegant... but works.

It251
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