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
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Sorting worksheets

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 HyperlinkUpload FileInsert 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
Rimmer Posted - 11/19/2003 : 12:10:35 PM
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
5   L A T E S T    R E P L I E S    (Newest First)
rlewis Posted - 11/20/2003 : 09:29:27 AM
Also ... you should uncomment the line "\\TempWks.Destroy();" ...
This line was commented out for debugging purposes ...
Rimmer Posted - 11/20/2003 : 05:39:06 AM
Thanks

I'll give it a go

Michael
rlewis Posted - 11/20/2003 : 02:04:52 AM
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);
}

/////////////////////////////////////////////////////////////////////////////////////////////////////
rlewis Posted - 11/19/2003 : 8:33:01 PM
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);
}

/////////////////////////////////////////////////////////////////////////////////////////////////////
Mike Buess Posted - 11/19/2003 : 2:14:47 PM
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

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