T O P I C R E V I E W |
juannim |
Posted - 04/17/2007 : 11:01:52 PM 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 |
11 L A T E S T R E P L I E S (Newest First) |
juannim |
Posted - 04/20/2007 : 2:47:06 PM Thanks, Mike. Works perfectly. |
Mike Buess |
Posted - 04/20/2007 : 2:06:03 PM 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 |
juannim |
Posted - 04/20/2007 : 1:53:07 PM [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. |
Mike Buess |
Posted - 04/20/2007 : 12:51:06 PM 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 |
juannim |
Posted - 04/20/2007 : 12:45:23 PM 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;
|
Mike Buess |
Posted - 04/20/2007 : 12:31:14 PM 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 |
juannim |
Posted - 04/20/2007 : 12:02:06 PM 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; |
Mike Buess |
Posted - 04/18/2007 : 11:03:57 PM 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 |
juannim |
Posted - 04/18/2007 : 6:00:07 PM 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. |
Mike Buess |
Posted - 04/18/2007 : 08:57:08 AM 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 |
Deanna |
Posted - 04/18/2007 : 01:25:32 AM 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 |