Author |
Topic  |
|
nbo10
USA
Posts |
Posted - 08/13/2006 : 12:26:32 AM
|
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
|
You need a semicolon after each %(%A,n)+=%(%H,n) line.
Mike Buess Origin WebRing Member |
 |
|
nbo10
USA
Posts |
Posted - 08/13/2006 : 4:32:43 PM
|
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. |
 |
|
Mike Buess
USA
3037 Posts |
Posted - 08/13/2006 : 7:06:19 PM
|
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 |
 |
|
nbo10
USA
Posts |
Posted - 08/14/2006 : 10:35:57 AM
|
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 |
 |
|
Mike Buess
USA
3037 Posts |
Posted - 08/14/2006 : 11:24:29 AM
|
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 |
 |
|
nbo10
USA
Posts |
Posted - 08/14/2006 : 11:55:34 AM
|
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?
|
 |
|
Mike Buess
USA
3037 Posts |
Posted - 08/14/2006 : 12:52:06 PM
|
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 |
 |
|
nbo10
USA
Posts |
Posted - 08/15/2006 : 5:41:55 PM
|
Thanks, I got it to work using the Custon Routine. For some reason I couldn't get it to work using the script window. |
 |
|
larry_lan
China
Posts |
Posted - 08/15/2006 : 10:52:55 PM
|
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 |
 |
|
nbo10
USA
Posts |
Posted - 08/16/2006 : 12:06:08 AM
|
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. |
 |
|
|
Topic  |
|