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
 Sort columns by comments/short name
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

thitchen

44 Posts

Posted - 06/18/2012 :  03:09:34 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
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.

Hideo Fujii

USA
1582 Posts

Posted - 06/18/2012 :  12:02:55 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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

Edited by - Hideo Fujii on 06/18/2012 12:04:08 PM
Go to Top of Page

thitchen

44 Posts

Posted - 06/18/2012 :  3:36:55 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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

Go to Top of Page

Hideo Fujii

USA
1582 Posts

Posted - 06/19/2012 :  11:02:17 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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

Edited by - Hideo Fujii on 06/19/2012 4:33:28 PM
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