The Origin Forum
File Exchange
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum
 Origin Forum
 Sort columns by comments/short name

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkInsert EmailInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
thitchen Posted - 06/18/2012 : 03:09:34 AM
Origin Ver. 8.6 and Service Release 2(Select Help-->About Origin):
Operating System: win7 pro

Is there a way to sort columns in a worksheet by comments/short name w/o contaminating the data in each columns? Thanks.
3   L A T E S T    R E P L I E S    (Newest First)
Hideo Fujii Posted - 06/19/2012 : 11:02:17 AM
Hi again, thitchen,

For columns' short names, the following may do the better job.
Here, shorter names will come first, and the names are treated case insensitively.
///////////////////////////////////////
nc=wks.ncols;
for(ii=nc; ii>1; ii--) {
  for(jj=1; jj<ii; jj++) {
    //for SHORT NAMES
      str1$=Upper(wks.col$(jj).name$)$; len1=Len(str1$);
      str2$=Upper(wks.col$(jj+1).name$)$; len2=Len(str2$);
    ff=str1.Compare(str2$);  //Comparison between this and nrxt
    if((len1==len2 && ff>0) || len1>len2) { //when str1>str2, Move Right
      colmove r:=wcol(jj) operation:=right;
    }
  }
}
/////////////////////////////////////////

Then, you can rename all column short names in regular naming convention,
i.e., A, B, C, etc. by the next script:
//////////////////////////////////////////////
wks1$=%H;
nc=wks.ncols;
window -t wks;
wks2$=%H;
//////////// Stage 1/3 //////////////////////
Break -b Stage 1 / 3; Break -r 1 (nc-2);
loop (ii, 1, nc-2) {Break -p ii; worksheet -a 1};
Break -end;
//////////// Stage 2/3 //////////////////////
Break -b Stage 2 / 3; Break -r 1 nc;
for(ii=1; ii<=nc; ii++) {  Break -p ii;
  col2$="oo"+wks.col$(ii).name$;
  %(wks1$)!wks.col$(ii).name$="oo"+%(wks2$)!wks.col$(ii).name$;
}
Break -end;
window -a %(wks1$);
//////////// Stage 3/3 //////////////////////
Break -b Stage 3 / 3; Break -r 1 nc;
for(ii=1; ii<=nc; ii++) { Break -p ii;
  str1$=wks.col$(ii).name$;
  wks.col$(ii).name$=Mid(str1$,3,Len(str1$))$;
}
Break -end;
type -b $(nc) columns have been renamed.;
window -cd %(wks2$);
//////////////////////////////////////////////



--Hideo Fujii
OriginLab
thitchen Posted - 06/18/2012 : 3:36:55 PM
Thank you again Hideo, that indeed helps.

quote:
Originally posted by Hideo Fujii

Hi thitchen,

There is no built-in menu command, etc., but the following script can sort columns
according to the long names (or, comments, or the short name) in dictionary order:
//////////////////////////////
nc=wks.ncols;
for(ii=nc; ii>1; ii--) {
  for(jj=1; jj<ii; jj++) {
    //for LONG NAMES
      str1$=wcol(jj)[L]$;
      str2$=wcol(jj+1)[L]$;
    //for COMMENTS
      //str1$=wcol(jj)[C]$;
      //str2$=wcol(jj+1)[C]$;
    //for SHORT NAMES
      //str1$=wks.col$(ii+1).name$;
      //str2$=wks.col$(ii+1).name$;
    ff=str1.Compare(str2$);  //Comparison between this and nrxt
    if(ff>0) { //when str1>str2, Move Right
      colmove r:=wcol(jj) operation:=right;
    }
  }
}
/////////////////////////////////

Maybe there are more elegant codes.
Anyway, I hope this helps.

--Hideo Fujii
OriginLab

Hideo Fujii Posted - 06/18/2012 : 12:02:55 PM
Hi thitchen,

There is no built-in menu command, etc., but the following script can sort columns
according to the long names (or, comments, or the short name) in dictionary order:
//////////////////////////////
nc=wks.ncols;
for(ii=nc; ii>1; ii--) {
  for(jj=1; jj<ii; jj++) {
    //for LONG NAMES
      str1$=wcol(jj)[L]$;
      str2$=wcol(jj+1)[L]$;
    //for COMMENTS
      //str1$=wcol(jj)[C]$;
      //str2$=wcol(jj+1)[C]$;
    //for SHORT NAMES
      //str1$=wks.col$(ii+1).name$;
      //str2$=wks.col$(ii+1).name$;
    ff=str1.Compare(str2$);  //Comparison between this and nrxt
    if(ff>0) { //when str1>str2, Move Right
      colmove r:=wcol(jj) operation:=right;
    }
  }
}
/////////////////////////////////

Maybe there are more elegant codes.
Anyway, I hope this helps.

--Hideo Fujii
OriginLab

The Origin Forum © 2008 Originlab Corporation Go To Top Of Page
Snitz Forums 2000