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
 Ave over many worksheets
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

nbo10

USA
Posts

Posted - 08/13/2006 :  12:26:32 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version (Select Help-->About Origin): 7.5
Operating System:XP

I found the following code on the forum and for some and I can;t find the error in it


%W=%H;
win -d;
doc -ef W {%A=%H};
nn=1;
doc -ef W {
if("%H"!="%W" && "%H"!="%A")
{
//If I only have two of these addtions everything works fine, but with //more than two I get a command error.

%(%A,1)+=%(%H,1)
%(%A,2)+=%(%H,2)
%(%A,3)+=%(%H,3)
%(%A,4)+=%(%H,4) }}

Mike Buess

USA
3037 Posts

Posted - 08/13/2006 :  09:09:44 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You need a semicolon after each %(%A,n)+=%(%H,n) line.

Mike Buess
Origin WebRing Member
Go to Top of Page

nbo10

USA
Posts

Posted - 08/13/2006 :  4:32:43 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
nope that doesn't fix it. I still get the command error. everything works fine if i only have 1 or 2 of those commands but if i have 3 or more i get a error.
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 08/13/2006 :  7:06:19 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
This works fine in my tests as long as all worksheets have at least 4 columns...

%W=%H;
win -d;
doc -ef W {%A=%H};
nn=1;
doc -ef W {
if("%H"!="%W" && "%H"!="%A")
{
%(%A,1)+=%(%H,1);
%(%A,2)+=%(%H,2);
%(%A,3)+=%(%H,3);
%(%A,4)+=%(%H,4);
}}

Sometimes it helps to restart Origin and try again.

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 08/13/2006 7:08:09 PM
Go to Top of Page

nbo10

USA
Posts

Posted - 08/14/2006 :  10:35:57 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
No it doesn't work. the following link has the project that I'm working with. I need to ave, Col 2-4 in all worksheets in each sub folder.



Edited by - nbo10 on 08/14/2006 1:33:28 PM
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 08/14/2006 :  11:24:29 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I downloaded your project and tried my last script in all subfolders of the 0T project folder. It failed (without command errors) only in subfolders that contained empty worksheets with two columns (tth 0.257 and tth 0.300). Once again I suggest that you restart Origin and try again.

The script sums cols 1-4 in all worksheets in the subfolder. The following version averages cols 2-4...

%W=%H;
win -d;
doc -ef W {%A=%H};
win -a %A; // activate result wks
nn=1;
doc -ef W {
if("%H"!="%W" && "%H"!="%A")
{
nn++; // count worksheets
loop(ii,2,4) {%(%A,ii)+=%(%H,ii)};
};
};
loop(ii,2,4) {%(%A,ii)/=nn}; // average result columns

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 08/14/2006 1:00:13 PM
Go to Top of Page

nbo10

USA
Posts

Posted - 08/14/2006 :  11:55:34 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I've restarted Origin, I've ran the project on a second computer. I'm still getting an error.

"Attention!

%(%A,II)+=Data100_DichroSum is a built-in function that can not be renamed."

Are you running it through the script window? Can this be rewritten in OriginC?
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 08/14/2006 :  12:52:06 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I've been running it from the script window but it's easier from the Custom Routine button. I get the same results both ways. It can be rewritten in Origin C but your problem most likely stems from a syntax error. For example, I get a similar error if I omit the {} brackets from the loop statements of my last script. (BTW, nn should be initialized to 1 in that script.) And missing (or extra) semicolons will create similar errors.

This Origin C function does the same as my last LabTalk script...

void average_folder_columns()
{
Worksheet wksSrc = Project.ActiveLayer();
if( !wksSrc )
return;
string sName1 = wksSrc.GetPage().GetName();
Worksheet wksAve;
wksAve.CreateCopy(wksSrc);
string sName2 = wksAve.GetPage().GetName();
Dataset ds1(wksAve,1),ds2(wksAve,2),ds3(wksAve,3);
Dataset dd;
string sName;
int nWks = 1;
Folder fld = Project.ActiveFolder();
foreach(PageBase pg in fld.Pages)
{
sName = pg.GetName();
if( sName==sName1 || sName==sName2 )
continue;
nWks++;
dd.Attach(sName,1);
ds1 += dd;
dd.Attach(sName,2);
ds2 += dd;
dd.Attach(sName,3);
ds3 += dd;
}
ds1 /= nWks;
ds2 /= nWks;
ds3 /= nWks;
}


Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 08/14/2006 2:12:23 PM
Go to Top of Page

nbo10

USA
Posts

Posted - 08/15/2006 :  5:41:55 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks, I got it to work using the Custon Routine. For some reason I couldn't get it to work using the script window.
Go to Top of Page

larry_lan

China
Posts

Posted - 08/15/2006 :  10:52:55 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi

Did you generate a new empty worksheet before running the scripts? I got the similar error too if to do so.

Larry
OriginLab GZ Office
Go to Top of Page

nbo10

USA
Posts

Posted - 08/16/2006 :  12:06:08 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Nope, the folder just had worksheets with data. It's the same code. But in the script window if I ave more than two col, I get an error.
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