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 for Programming
 Forum for Origin C
 A question about sort.
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

rainlane

China
22 Posts

Posted - 03/22/2017 :  9:08:13 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): Origin 9
Operating System:Windows XP

In Origin ,I used the code to import a .dat file and sort.


void sor_Example()
{
    int        iStatus;
    ASCIMP    ai;
    string     strFile = "C:\\data.dat";
    if(AscImpReadFileStruct(strFile,&ai) == 0)
    {
        ai.iRenameWks = 0; //to rename worksheet from filename            
        ai.iRenameCols = 1; //0 to keep default column names, 1 to rename columns using 1st line of header block
 
        Worksheet wks = Project.ActiveLayer();
        wks.ImportASCII(strFile, ai);
        
        vector<int> vCol = {0,1};
	vector<int> vSort = {SORT_ASCENDING, SORT_ASCENDING};
	wks.Sort(vCol, vSort) ;
    }
}






In my thinking ,the result is :


But the result is:




forum

yuki_wu

896 Posts

Posted - 03/22/2017 :  10:57:50 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

If you want to get the result as you desired, you need to modify your code as follows:

vector<int> vCol = {1,3};
vector<int> vSort = {SORT_ASCENDING, SORT_ASCENDING};
wks.Sort(vCol, vSort);

The logic of sort in Origin may be a little bit different from other softwares, such as Excel. You should take a look at this based item about the nested sort:
http://www.originlab.com/doc/Origin-Help/Wks-Sort-Data

Regards,
Yuki
OriginLab

Edited by - yuki_wu on 03/23/2017 05:47:28 AM
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