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
 Sorting worksheets
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Rimmer

Sweden
25 Posts

Posted - 11/19/2003 :  12:10:35 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
I have a number of worksheets that I go between using the foreach statement. What I would like to be able to do is sort these in a specific order based on a value in cell 1,1, so that the next time I use foreach I know the first worksheet up is the one with the lowest value in cell 1,1 out of all the worksheets. Is this possible?

Also is there a origin c equavalent to the labtalk round() function or do I need to incase the labtalk command into my code.

Thanks for your time

Michael

Mike Buess

USA
3037 Posts

Posted - 11/19/2003 :  2:14:47 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Michael,

I don't know off hand how to approach your sorting problem, but there is a round() function in 7.0 and 7.5 under Global Functions->Mathematical. According to its description it's equivalent to the LT round().

Mike Buess
Origin WebRing Member
Go to Top of Page

rlewis

Canada
253 Posts

Posted - 11/19/2003 :  8:33:01 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Try this approach ... it seems to work ...

bool ProcessSortedWorkSheets(bool ActiveFolderFlag)
{
int NumPages=0;
string WksPageList="";
if(ActiveFolderFlag)
{
NumPages=Worksheet_pages_in_folder(WksPageList);
// Worksheet names from active folder collected as tokens in the string "WksPageList"
}
else
{
NumPages=Worksheet_pages_in_project(WksPageList);
// Worksheet names from entire project collected as tokens in the string "WksPageList"
}
if(NumPages>0)
{
Worksheet TempWks;
if(TempWks.Create(NULL,CREATE_HIDDEN))
{
TempWks.SetNumRows(NumPages);
string strWksName, strCellValue;
Worksheet SampleWks;
for (int i=0;i<NumPages;i++)
{
string strWksName=WksPageList.GetToken(i);
if(!SampleWks.Attach(strWksName))
{
TempWks.Destroy();
return (false);
}
SampleWks.GetCell(0,0,strCellValue);
TempWks.SetCell(i,0,strCellValue);
TempWks.SetCell(i,1,strWksName);
}
Dataset TempWksCol0;
if(!TempWksCol0.Attach(TempWks,0))
{
TempWks.Destroy();
return (false);
}

string strCommand="sort -w "+TempWks.GetPage().GetName()+" "+TempWksCol0.GetName();
LT_execute(strCommand);


for (i=0;i<NumPages;i++)
{
TempWks.GetCell(i,1,strWksName);
if(!SampleWks.Attach(strWksName))
{
TempWks.Destroy();
return (false);
}
/*
Code for Processing individual Worksheets
using the SampleWks worksheet object goes here ...


*/
}
TempWks.Destroy();
return (true);
}
}
return (false);
}

//////////////////////////////////////////////////////////////////////////////////////////////////
int Worksheet_pages_in_folder(string &WksPageList)
{
Folder Fld=Project.ActiveFolder();
if (Fld)
{
int counter=0;
WksPageList="";
foreach(PageBase pB in Fld.Pages)
{
if (pB.GetType()==EXIST_WKS)
{
counter ++;
WksPageList+=" ";
WksPageList+=pB.GetName();
}
}
return (counter);
}
return (0);
}

//////////////////////////////////////////////////////////////////////////////////////////////////
int Worksheet_pages_in_project(string &WksPageList)
{
int counter=0;
WksPageList="";
foreach (WorksheetPage wP in Project.WorksheetPages)
{
counter ++;
WksPageList+=" ";
WksPageList+=wP.GetName();
}
return (counter);
return (0);
}

/////////////////////////////////////////////////////////////////////////////////////////////////////
Go to Top of Page

rlewis

Canada
253 Posts

Posted - 11/20/2003 :  02:04:52 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Oops ... There is a little bug in "ProcessSortedWorksheet" function in the last post. The first column of the temporary worksheet should be formatted as numeric before the sort ...

The following coorrects that ...

bool ProcessSortedWorkSheets(bool ActiveFolderFlag)
{
int NumPages=0;
string WksPageList="";
if(ActiveFolderFlag)
{
NumPages=Worksheet_pages_in_folder(WksPageList);
// Worksheet names from active folder collected as tokens in the string "WksPageList"
}
else
{
NumPages=Worksheet_pages_in_project(WksPageList);
// Worksheet names from entire project collected as tokens in the string "WksPageList"
}
if(NumPages>0)
{
Worksheet TempWks;
if(TempWks.Create(NULL,CREATE_HIDDEN))
{
TempWks.SetNumRows(NumPages);
string strWksName, strCellValue;
Worksheet SampleWks;
for (int i=0;i<NumPages;i++)
{
string strWksName=WksPageList.GetToken(i);
if(!SampleWks.Attach(strWksName))
{
TempWks.Destroy();
return (false);
}
SampleWks.GetCell(0,0,strCellValue);
TempWks.SetCell(i,0,strCellValue);
TempWks.SetCell(i,1,strWksName);
}
Dataset TempWksCol0;
if(!TempWksCol0.Attach(TempWks,0))
{
TempWks.Destroy();
return (false);
}
Column colWks;
if(!colWks.Attach(TempWks,0))
{
TempWks.Destroy();
return (false);
}
colWks.SetFormat(OKCOLTYPE_NUMERIC);
string strCommand="sort -w "+TempWks.GetPage().GetName()+" "+TempWksCol0.GetName();
LT_execute(strCommand);
for (i=0;i<NumPages;i++)
{
TempWks.GetCell(i,1,strWksName);
if(!SampleWks.Attach(strWksName))
{
TempWks.Destroy();
return (false);
}
/*
Code for Processing individual Worksheets
using the SampleWks worksheet object goes here ...
*/
}
//TempWks.Destroy();
return (true);
}
}
return (false);
}

//////////////////////////////////////////////////////////////////////////////////////////////////
int Worksheet_pages_in_folder(string &WksPageList)
{
Folder Fld=Project.ActiveFolder();
if (Fld)
{
int counter=0;
WksPageList="";
foreach(PageBase pB in Fld.Pages)
{
if (pB.GetType()==EXIST_WKS)
{
counter ++;
WksPageList+=" ";
WksPageList+=pB.GetName();
}
}
return (counter);
}
return (0);
}

//////////////////////////////////////////////////////////////////////////////////////////////////
int Worksheet_pages_in_project(string &WksPageList)
{
int counter=0;
WksPageList="";
foreach (WorksheetPage wP in Project.WorksheetPages)
{
counter ++;
WksPageList+=" ";
WksPageList+=wP.GetName();
}
return (counter);
return (0);
}

/////////////////////////////////////////////////////////////////////////////////////////////////////
Go to Top of Page

Rimmer

Sweden
25 Posts

Posted - 11/20/2003 :  05:39:06 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks

I'll give it a go

Michael
Go to Top of Page

rlewis

Canada
253 Posts

Posted - 11/20/2003 :  09:29:27 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Also ... you should uncomment the line "\\TempWks.Destroy();" ...
This line was commented out for debugging purposes ...
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