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
 script in worksheet script window
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

juannim

USA
Posts

Posted - 04/17/2007 :  11:01:52 PM  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

Can someone tell me what is wrong with this script? I try running it from the worksheet script window and get absolutely nada. Any suggestions?

del wcol(8);
del wcol(7);
del wcol(6);
del wcol(5);
del wcol(1);
del wcol(1); //eliminate all but cols 3 and 4
mark -d %h_c -b 1 -e 5011; delete all rows below 5011
for (i=1; i<wks.nrows; i++) {
if (%h_c[i]$=="=") %h_c[i]=%h_d[i];
}; //replace all "=" in col 1 with adjacent # in col2//
del wcol(2); //
martha=wks.maxrows-4;
jam=martha/10;
worksheet a jam-1;
//add columns to move groups of 10 rows to individual columns//
martha=wks.maxrows-4;
jam=martha/10;
worksheet a jam-1;
for(ii=1; ii<10*jam; ii++) {
for(i=0; i<10; i++) {
%(%h, ii+1,1+i)= %(%h, 1,10*ii+i+1);
};// copy col1 data to adjacent columns in groups of 10 cells per column//
};
I'm sure that this is quite an unnecessarily convoluted method. Thanks. Jonathan

Deanna

China
Posts

Posted - 04/18/2007 :  01:25:32 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hello Jonathan.

Please try to replace
worksheet a jam-1;
with
worksheet -a jam-1;
Note that the hyphens before the first "a" are different.

After this change, the script works fine for me.

Deanna
OriginLab Technical Services

Edited by - Deanna on 04/18/2007 03:36:58 AM
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 04/18/2007 :  08:57:08 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
The comment slashes "//" are missing from the comment after your mark command. Also, worksheet scripts are executed one line at a time so multi-line commands (such as your for-loops) can create problems. If your worksheet script doesn't work after these corrections, copy it to the script window and execute by selecting all lines and pressing Enter. If that works you should move the script to a script file...
http://www.originlab.com/index.aspx?s=9&pid=366
and launch it from the Worksheet Script with run.section(fileName,sectionName).

...Your first for-loop which replaces '=' with corresponding values in adjacent column can be replaced with this ternary function

col(1) = col(1)==0/0 ? col(2) : col(1);

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 04/18/2007 09:08:51 AM
Go to Top of Page

juannim

USA
Posts

Posted - 04/18/2007 :  6:00:07 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
What is a good way to erase a range of rows? I used mark -d in this script, but am trying to do it again w/o luck. Thanks.
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 04/18/2007 :  11:03:57 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
If you mean this commamd...

mark -d %h_c -b 1 -e 5011; delete all rows below 5011

... it doesn't work because you forgot the double-slash '//' in front of the comment.

Mike Buess
Origin WebRing Member
Go to Top of Page

juannim

USA
Posts

Posted - 04/20/2007 :  12:02:06 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Yeah, I had fixed that, but it still doesn't work. Ideas?
del wcol(8);
del wcol(7);
del wcol(6);
del wcol(5);
del wcol(1);
del wcol(1); //eliminate all but cols 3 and 4
mark -d %h_c -b 1 -e 5011; // delete all rows below 5011
for (i=1; i<wks.nrows; i++) {
if (%h_c[i]$=="=") %h_c[i]=%h_d[i];
}; //replace all "=" in col 1 with adjacent # in col2//
del wcol(2); //
martha=wks.maxrows-4;
jam=martha/10;
worksheet -a jam-1;
//add columns to move groups of 10 rows to individual columns//
martha=wks.maxrows-4;
jam=martha/10;
worksheet -a jam-1;
for(ii=1; ii<10*jam; ii++) {
for(i=0; i<10; i++) {
%(%h, ii+1,1+i)= %(%h, 1,10*ii+i+1);
};// copy col1 data to adjacent columns in groups of 10 cells per column//
} ;
mark -d -b 11 -e wks.nrows;
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 04/20/2007 :  12:31:14 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
The first mark command will only fail if the active worksheet does not contain a column C. (Although the results might be unpredictable if the worksheet has fewer than 5011 rows.) The last mark command will surely fail because it does not specify a dataset. If the script window is open each command will generate a #Command Error! when it fails.

Mike Buess
Origin WebRing Member
Go to Top of Page

juannim

USA
Posts

Posted - 04/20/2007 :  12:45:23 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I fixed the second mark command, but it still does not work. Ideas?
[postfit]
del wcol(8);
del wcol(7);
del wcol(6);
del wcol(5);
del wcol(1);
del wcol(1); //eliminate all but cols 3 and 4
mark -d %h_c -b 1 -e 5011; // delete all rows below 5011
for (i=1; i<wks.nrows; i++) {
if (%h_c[i]$=="=") %h_c[i]=%h_d[i];
}; //replace all "=" in col 1 with adjacent # in col2//
del wcol(2); //
martha=wks.maxrows-4;
jam=martha/10;
worksheet -a jam-1;
//add columns to move groups of 10 rows to individual columns//
martha=wks.maxrows-4;
jam=martha/10;
worksheet -a jam-1;
for(ii=1; ii<10*jam; ii++) {
for(i=0; i<10; i++) {
%(%h, ii+1,1+i)= %(%h, 1,10*ii+i+1);
};// copy col1 data to adjacent columns in groups of 10 cells per column//
} ;
mark -d %h_c -b 11 -e wks.nrows;
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 04/20/2007 :  12:51:06 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
The worksheet has a column C?

...The first mark command works perfectly as you can see by inserting a return after that command. The second mark command never executes because missing values are encountered in the nested for loops. That's partly because you've duplicated the lines martha=... through worksheet -a ... which creates more columns than you need. Once you've fixed that you can replace the final mark command with set %H -er 10 which deletes all rows after 10.

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 04/20/2007 1:43:49 PM
Go to Top of Page

juannim

USA
Posts

Posted - 04/20/2007 :  1:53:07 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
[quote]
The worksheet has a column C?
Yes, it has a column c. Iterestingly enough, the first mark command operates on all of the columns, in spite of the fact that I specify column c.
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 04/20/2007 :  2:06:03 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Iterestingly enough, the first mark command operates on all of the columns, in spite of the fact that I specify column c.
That's by design if you read the programming guide. Following code should work much better. I've replaced your %(%h,colnum,rownum) notation with cell(rownum,colnum) which is more reliable...
http://www.originlab.com/forum/topic.asp?TOPIC_ID=5606
I'm not sure about your intentions for copying all rows but will let you sort that out.

[postfit]
repeat 4 {del col(5)}; //delete cols 5-8
repeat 2 {del col(1)}; //delete cols 1-2
mark -d %h_c -b 1 -e 5011; // delete all rows below 5011
for (i=1; i<wks.nrows; i++) {
if (%h_c[i]$=="=") %h_c[i]=%h_d[i];
};
del col(2);
martha=wks.maxrows-4;
jam=martha/10;
worksheet -a jam;
for(ii=1; ii<10*jam; ii++) {
for(i=0; i<10; i++) {
if( 10*ii+i+1>wks.maxrows ) break;
cell(1+i,ii+1)=cell(10*ii+i+1,1);
};// copy col1 data to adjacent cols in groups of 10 cells per col
};
set %H -er 10;

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 04/20/2007 2:09:49 PM
Go to Top of Page

juannim

USA
Posts

Posted - 04/20/2007 :  2:47:06 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks, Mike. Works perfectly.
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