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
 Sort worksheets in subfolder for foreach
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

oconnor

UK
Posts

Posted - 11/22/2004 :  10:17:08 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi,

I have a series of worksheets titled pbBLOCK01,pbBLOCK02, pbBLOCK03 etc. When I use foreach to go through this collection of worksheets to get the name using:

foreach (PageBase pb in Pages)
{
Worksheet wks(pb.GetName());
string bName=pb.GetName();
printf("Worksheet %s", bName);
}

The list I get doesn't always seem to be sorted by the numerical sorting (ie. pBLOCK01 before pBLOCK02 before pBLOCK03 ...). Every now and then pBLOCK98 shows up before pBLOCK01. The order in which I process these worksheets in the collection is important, so is there anyway to sort the worksheets or instruct foreach to read them in the right order or sort the collection using the last two numbers of the name as an index?

Cheers,

Rod.

Mike Buess

USA
3037 Posts

Posted - 11/22/2004 :  11:41:08 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Rod,

This should work...

StringArray sa;
string bName;
foreach (PageBase pb in Project.Pages)
{
bName = pb.GetName();
Worksheet wks(bName);
if( wks.IsValid() )
{
sa.Add(bName);
}
}
sa.Sort();
for(int i=0;i<sa.GetSize();i++)
{
printf("Worksheet %s",sa[i];
}

Mike Buess
Origin WebRing Member
Go to Top of Page

hajo

Germany
Posts

Posted - 11/22/2004 :  1:29:12 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hello, Rod

I use a similar sollution as Mike in his posting before.

The only thing is, that I fill the globally definded StringArray sa by creating the worksheets during reading in the data - I create always a worksheet named by Origin itself ("DataXX"). After that I rename it to my needs like "pbBLOCK_NUMBER" with my own numbering system. After renaming the worksheet to its final name I store the name in the StringArray sa to keep tracked to the newly created pages.

Working on these imported worksheets is done in the same way as suggested by Mike.

Hope that helps

Hajo

--
Dipl.-Ing. Hans-Joerg Koch
SiemensVDO Automotive,
Regensburg, Germany
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