Sorting a CList

Hello,

I need to sort a CList (No, it not possible to use STL)

I have this code but it there is something wrong with the pointers..
CList<CLaserObject*,CLaserObject*> m_listObjects;

CArray<CLaserObject*,CLaserObject*> vector;
POSITION pos = m_listObjects.GetHeadPosition();		
int i=0;
while(pos != NULL)
{
   vector.Add(m_listObjects.GetNext(pos));
}
// sort array
qsort(vector.GetData(),vector.GetSize(),sizeof(CLaserObject*),cmpLaserObject);
// empty list and fill it with the sorted data
m_listObjects.RemoveAll();
int n=vector.GetCount();
for(i=0;i<n;i++)
{
  m_listObjects.AddTail(vector[i]);
}

int CSCMLaserDoc::cmpLaserObject(const void * v1, const void * v2)
{
	CLaserObject *data1 = (CLaserObject *)v1;
	CLaserObject *data2 = (CLaserObject *)v2;

}


When I check in the debugger  the vector is Ok!
My problem is that when I reach cmpLaserObject the data1 and data2 pointers
doesn't point to the vector

What am I doing wrong?

// Anders
-- 
English is not my first, or second, language
so anything strange, or insulting, is due to
the translation.
Please correct me so I may improve my English!
0
andis59 (75)
6/14/2007 2:16:41 PM
vc.mfc 33608 articles. 0 followers. Follow

17 Replies
2416 Views

Similar Articles

[PageSpeed] 41

On Thu, 14 Jun 2007 16:16:41 +0200, Anders Eriksson
<andis59@gmail.com> wrote:


>CArray<CLaserObject*,CLaserObject*> vector;

>// sort array
>qsort(vector.GetData(),vector.GetSize(),sizeof(CLaserObject*),cmpLaserObject);

>int CSCMLaserDoc::cmpLaserObject(const void * v1, const void * v2)
>{
>	CLaserObject *data1 = (CLaserObject *)v1;
>	CLaserObject *data2 = (CLaserObject *)v2;
>
>}
>
>
>When I check in the debugger  the vector is Ok!
>My problem is that when I reach cmpLaserObject the data1 and data2 pointers
>doesn't point to the vector

Try adjust cmpLaserObject like this:

int CSCMLaserDoc::cmpLaserObject(const void * v1, const void * v2)
{
	CLaserObject *data1 = (CLaserObject *)(*v1);
	CLaserObject *data2 = (CLaserObject *)(*v2);
}

I've not tested it, but it should work, because if I remember
correctly, qsort compare routine parameters are *pointers* to array
items. Your array items are of type "CLaserObject *", so the
comparison function gets *pointers* to "CLaserObject *" (one more
level of indirection).

(Note that if you would have used STL this problem won't occurr, the
code would be more "clear" IMHO.)

MrAsm
0
mrasm (715)
6/14/2007 3:04:19 PM
On Thu, 14 Jun 2007 15:04:19 GMT, MrAsm <mrasm@usa.com> wrote:

>int CSCMLaserDoc::cmpLaserObject(const void * v1, const void * v2)
>{
>	CLaserObject *data1 = (CLaserObject *)(*v1);
>	CLaserObject *data2 = (CLaserObject *)(*v2);
>}

No, sorry:

  const CLaserObject * data1 = *( (const CLaserObject **)v1 );
  const CLaserObject * data2 = *( (const CLaserObject **)v2 );


MrAsm
0
mrasm (715)
6/14/2007 3:11:56 PM
On Thu, 14 Jun 2007 16:16:41 +0200, Anders Eriksson
<andis59@gmail.com> wrote:


>I need to sort a CList (No, it not possible to use STL)

OK, but it would be interesting to compare MFC collection code + qsort
vs. STL code:


Your code (with qsort problem):

>CList<CLaserObject*,CLaserObject*> m_listObjects;
>
>CArray<CLaserObject*,CLaserObject*> vector;
>POSITION pos = m_listObjects.GetHeadPosition();		
>int i=0;
>while(pos != NULL)
>{
>   vector.Add(m_listObjects.GetNext(pos));
>}
>// sort array
>qsort(vector.GetData(),vector.GetSize(),sizeof(CLaserObject*),cmpLaserObject);
>// empty list and fill it with the sorted data
>m_listObjects.RemoveAll();
>int n=vector.GetCount();
>for(i=0;i<n;i++)
>{
>  m_listObjects.AddTail(vector[i]);
>}
>
>int CSCMLaserDoc::cmpLaserObject(const void * v1, const void * v2)
>{
>	CLaserObject *data1 = (CLaserObject *)v1;
>	CLaserObject *data2 = (CLaserObject *)v2;
>
>}

A possible STL version:

  std::list< CLaserObject * > laserObjects;
  laserObjects.sort( LessByPointedValue<CLaserObject>() );

(just two simple lines of code! :)

and define an operator< on your laser object class:

  bool operator<( 
    const CLaserObject & lhs, 
    const CLaserObject & rhs 
  );

Note that you have no need to pass from list to vector and back to
list, and to use the IMHO not very clear 'qsort' function (OK, qsort
was well designed in the C age, but with C++ more clear things could
be done...).

Note that you just need to call the list.sort() method.

The "strange" thing could be the LessByPointedValue<...> thing.
It is because the list stores *pointers* to CLaserObject, so you must
"teach" 'sort' method how to compare those pointed values.

The LessByPointedValue is a template you could reuse in other cases
when you have lists storing *pointers* to class instances (you could
put the LessByPointedValue template in your "programming tool-box" and
reuse it):

//
// operator < with pointed values
//
template <typename T>
class LessByPointedValue
  : std::binary_function< const T *, const T *, bool >
{
public:

  bool operator()( const T * x, const T * y ) const
  { 
    return std::less<T>()( *x, *y ); 
  }
};

I don't know if Boost has a "standard" version of this useful template
(maybe it has one, but I'm quite ignorant about Boost :(

If you need to use MFC collection, this CodeProject article might be
interesting:


http://www.codeproject.com/cpp/colsort.asp?df=100&forumid=2454&exp=0&select=223176

MrAsm
0
mrasm (715)
6/14/2007 4:32:05 PM
On Thu, 14 Jun 2007 15:11:56 GMT, MrAsm wrote:

> On Thu, 14 Jun 2007 15:04:19 GMT, MrAsm <mrasm@usa.com> wrote:
> 
> 
>   const CLaserObject * data1 = *( (const CLaserObject **)v1 );
>   const CLaserObject * data2 = *( (const CLaserObject **)v2 );
> 
Worked almost! I had to remove the const since I got an error when
accessing a method in CLaserObject. 

With this answer your scoring is now +1000 which is the highest I use. So
you are in great company

+1000 From "Joseph M. Newcomer"
+1000 From "Igor Tandetnik"
+1000 From "Mihai N."
+1000 From "MrAsm"

Thank you very much for this answer and for all the effort you and everyone
else put in making my and many others life easier!


// Anders
-- 
English is not my first, or second, language
so anything strange, or insulting, is due to
the translation.
Please correct me so I may improve my English!
0
andis59 (75)
6/15/2007 5:40:04 AM
On Fri, 15 Jun 2007 07:40:04 +0200, Anders Eriksson
<andis59@gmail.com> wrote:

>Thank you very much for this 

You're welcome.

MrAsm
0
mrasm (715)
6/15/2007 8:23:21 AM
See below....
On Thu, 14 Jun 2007 16:16:41 +0200, Anders Eriksson <andis59@gmail.com> wrote:

>Hello,
>
>I need to sort a CList (No, it not possible to use STL)
>
>I have this code but it there is something wrong with the pointers..
>CList<CLaserObject*,CLaserObject*> m_listObjects;
>
>CArray<CLaserObject*,CLaserObject*> vector;
>POSITION pos = m_listObjects.GetHeadPosition();		
>int i=0;
>while(pos != NULL)
>{
>   vector.Add(m_listObjects.GetNext(pos));
>}
*****
While the above code works, if there is any reasonable number of elements in the list, it
is not terribly efficient.

CArray<CLaserObject*, CLaserObject*> vector;
vector.SetSize(m_ListBoxes.GetCount());
int i  = 0;
POSITION pos = ...; // as above
while(pos != NULL)
   {
    vector[i] = m_listObjecst.GetNext(pos);
    i++;
  }

Since this preallocates the array, you don't get into the exponential-growth-performance
problem that the Add will engender
*****
>// sort array
>qsort(vector.GetData(),vector.GetSize(),sizeof(CLaserObject*),cmpLaserObject);
>// empty list and fill it with the sorted data
>m_listObjects.RemoveAll();
>int n=vector.GetCount();
>for(i=0;i<n;i++)
>{
>  m_listObjects.AddTail(vector[i]);
>}
*****
Yes, this is the classic list-sort algorithm.  I've not done this with CLists, but often
what I'll do is have a list of pointers-to-the-thing so that all I have to do is replug
the pointer in the list and this saves doing the RemoveAll and having to redo all the
allocations with AddTail.  I've not investigated if this is possible in a CList
*****
>
>int CSCMLaserDoc::cmpLaserObject(const void * v1, const void * v2)
>{
>	CLaserObject *data1 = (CLaserObject *)v1;
>	CLaserObject *data2 = (CLaserObject *)v2;
>
>}
>
>
>When I check in the debugger  the vector is Ok!
>My problem is that when I reach cmpLaserObject the data1 and data2 pointers
>doesn't point to the vector
*****
No, what you get are pointers to the elements.  So you have a pointer to a CLaserObject*,
which you are casting to be a CLaserObject *.   If you wrote

	CLaserObject * data1 = *(CLaserObject**)v1;
then you would get what you want.

(By the way, this is one reason that you should use the C++ <dynamic_cast> operator; it
would have detected the error in the types, if you enabled run-time-type-information
(RTTI))
				joe
****
>
>What am I doing wrong?
>
>// Anders
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
6/17/2007 6:40:24 PM
On Sun, 17 Jun 2007 14:40:24 -0400, Joseph M. Newcomer
<newcomer@flounder.com> wrote:


>	CLaserObject * data1 = *(CLaserObject**)v1;

>(By the way, this is one reason that you should use the C++ <dynamic_cast> operator; it
>would have detected the error in the types, if you enabled run-time-type-information
>(RTTI))

Hi Joe,

may I ask how could you use dynamic_cast in this context?
What C++ statement should we write?

Moreover, - I'm not sure - but I think that the CLaserObject class
must have at least one virtual method (i.e. the class must have a
v-table) to use the dynamic_cast.

Thanks,
MrAsm
0
mrasm (715)
6/17/2007 9:30:23 PM
Hmmm... indeed, it doesn't work; syntax error.  I'd not ever tried it with two levels of
indirection before.
				joe
On Sun, 17 Jun 2007 21:30:23 GMT, MrAsm <mrasm@usa.com> wrote:

>On Sun, 17 Jun 2007 14:40:24 -0400, Joseph M. Newcomer
><newcomer@flounder.com> wrote:
>
>
>>	CLaserObject * data1 = *(CLaserObject**)v1;
>
>>(By the way, this is one reason that you should use the C++ <dynamic_cast> operator; it
>>would have detected the error in the types, if you enabled run-time-type-information
>>(RTTI))
>
>Hi Joe,
>
>may I ask how could you use dynamic_cast in this context?
>What C++ statement should we write?
>
>Moreover, - I'm not sure - but I think that the CLaserObject class
>must have at least one virtual method (i.e. the class must have a
>v-table) to use the dynamic_cast.
>
>Thanks,
>MrAsm
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
6/18/2007 3:25:21 PM
On Sun, 17 Jun 2007 21:30:23 GMT, MrAsm <mrasm@usa.com> wrote:

>On Sun, 17 Jun 2007 14:40:24 -0400, Joseph M. Newcomer
><newcomer@flounder.com> wrote:
>
>
>>	CLaserObject * data1 = *(CLaserObject**)v1;
>
>>(By the way, this is one reason that you should use the C++ <dynamic_cast> operator; it
>>would have detected the error in the types, if you enabled run-time-type-information
>>(RTTI))
>
>Hi Joe,
>
>may I ask how could you use dynamic_cast in this context?
>What C++ statement should we write?

There is no way to use dynamic_cast here.

>Moreover, - I'm not sure - but I think that the CLaserObject class
>must have at least one virtual method (i.e. the class must have a
>v-table) to use the dynamic_cast.

You are correct about the virtual function requirement. There's no way to
use dynamic_cast on a pointer to pointer of type X**, because that would
require the type X* to have a virtual function. Moreover, dynamic_cast
cannot cast from void*, so when you start from void*, as the sort
comparison function does, you have to do a static_cast first. Thus, you
will have this initial unchecked cast at the very least, and you have to
get it right. If you get it wrong, everything that follows, including
dynamic_cast, will be invalid.

-- 
Doug Harrison
Visual C++ MVP
0
dsh (2498)
6/18/2007 4:05:04 PM
Gosh Joe, you don't know EVERYTHING!!!  I'm disapointed :o)  I'm actually 
glad to see you are human and not just an auto-response tech support robot 
with an built in opinion-personality-module.

Tom

"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message 
news:qa7d73toepoce4u5f25snvtc4s72hls41a@4ax.com...
> Hmmm... indeed, it doesn't work; syntax error.  I'd not ever tried it with 
> two levels of
> indirection before.
> joe

0
tom.nospam (3240)
6/18/2007 4:35:58 PM
On Mon, 18 Jun 2007 09:35:58 -0700, "Tom Serface"
<tom.nospam@camaswood.com> wrote:

>Gosh Joe, you don't know EVERYTHING!!!

I believe that no human being can know EVERYTHING :)

MrAsm
0
mrasm (715)
6/18/2007 9:38:13 PM
On Mon, 18 Jun 2007 11:25:21 -0400, Joseph M. Newcomer
<newcomer@flounder.com> wrote:

>Hmmm... indeed, it doesn't work; syntax error.

Yes, I also tried the dynamic_cast and had syntax error.

I think that the post by C++ guru Doug makes a clear assertion that it
is not possible to use dynamic_cast in this context.

I used to think that dynamic_cast was useful when one wants to do
down-casts with type safety, e.g. we have class 'Base', and class
'Derived' derived from 'Base'.
We have a Base * and want to down-cast to Derived *, with type-safety
check at run-time. My understanding is that in this context,
dynamic_cast would help.

Maybe there are also more advanced uses of dynamic_cast that I don't
know about.

Thanks to all
MrAsm
0
mrasm (715)
6/18/2007 9:50:22 PM
On Mon, 18 Jun 2007 11:05:04 -0500, "Doug Harrison [MVP]"
<dsh@mvps.org> wrote:


>There is no way to use dynamic_cast here.
....

>You are correct about the virtual function requirement. There's no way to
>use dynamic_cast on a pointer to pointer of type X**, because that would
>require the type X* to have a virtual function. 
....

Thank you very much for your elaborated points.

MrAsm
0
mrasm (715)
6/18/2007 9:51:07 PM
Indeed, but Joe knows a bunch...

Tom

"MrAsm" <mrasm@usa.com> wrote in message 
news:poud731u67a3tdd6e5paqhef6tlua8157p@4ax.com...
> On Mon, 18 Jun 2007 09:35:58 -0700, "Tom Serface"
> <tom.nospam@camaswood.com> wrote:
>
>>Gosh Joe, you don't know EVERYTHING!!!
>
> I believe that no human being can know EVERYTHING :)
>
> MrAsm 

0
tom.nospam (3240)
6/19/2007 12:13:13 AM
On Mon, 18 Jun 2007 17:13:13 -0700, "Tom Serface"
<tom.nospam@camaswood.com> wrote:

>Indeed, but Joe knows a bunch...
>
>Tom

He certainly knows much *more* than me.

MrAsm
0
mrasm (715)
6/19/2007 10:18:38 AM
Some years ago a programmer who worked with me kept being dismayed because every time he
asked me a question I had an answer.  A couple years later we were working on a project,
when I remarked, "I have a 25th anniversary this month!" (it was September, 1988).  

"Of what?" he asked.  

"I met my first computer 25 years ago.  It was September, 1963".  

He then said, in his best Marvin-the-paranoid-android voice, "Ohhhh.  I feel soooo
depressed".  

"Why do you feel depressed?"

"Because I was *born* in October of 1963!"

"Well, that's why I know so much more.  I've been doing this longer than you've been
alive!  You'll be doing this to junior programmers in a few years.  Don't worry about it!"

He went on to get his PhD (one of my personal triumphs was being one of the people who
convinced him to do this) and now has 20 more years experience.  I expect he's at least as
good as I am, and probably better.

Write enough code, and you eventually end up knowing a lot.  All it takes is experience
(and remember: good judgment is the result of experience; experience is the result of bad
judgment.  Trust me: I have good judgment, at least most of the time.  Now figure out
why...)

*****
One day I went in to see my thesis advisor.  I'd been bashing my head against the wall for
two weeks on a problem that was COMPLETELY intractable.  So I filled his board up with
diagrams, he sat there and said, "But isn't that just a special case of..." and I turned
to the board, my jaw fell down, and it was OBVIOUS what I'd missed.  So I got seriously
pissed off at myself, and said "I have no idea why I'm wasting your time; I'm not capable
of doing this work!"

So he told me to sit down and listen.  When he was working on HIS Ph.D., on some bizarre
aspect of partial differential equations, he hit a similar block.  He filled the board
with formulae, and his advisor said "But that's just <name here>'s Theorem"  He was a
graduate assistant, taught the introductory calculus courses, and in fact had just taught
this theorem and its derivation the previous semester.  His advisor told him a similar
story.

So one day one of my students walks into my office with an intractable problem, fills the
board with diagrams, and says "I have no idea how to approach this problem!"  I looked at
it, and said, "But you've just described an abstract data type model with derivation!"

He got The Look.  I'd seen that Look, not too many years before, from his side.  He threw
the eraser across the office, and said "I'm wasting my time here!  I've been working on
this for three months and never saw that!"

So I sat him down and told the first three cycles of this story.  He was now the fourth
cycle.  I told him that someday he, too, would have this experience, and please pass the
story on.

About five years later we met at a conference.  He said "It happened!"

I asked "What happened?"

"That day in your office.  A couple months ago, one of my students walked in, filled my
board with diagrams, and the solution was obvious.  So I told her, and she burst into
tears.  But since she had planned an academic career, I told her ot sit down, and told her
your story, and now she was the fifth turn of the cycle.  And someday it would happen to
her and she should pass this story on."

I haven't seen him in many years, although his student did go on to get her Ph.D., and
I've always wondered if she's had the experience and has passed the story on once more.
					joe
On Tue, 19 Jun 2007 10:18:38 GMT, MrAsm <mrasm@usa.com> wrote:

>On Mon, 18 Jun 2007 17:13:13 -0700, "Tom Serface"
><tom.nospam@camaswood.com> wrote:
>
>>Indeed, but Joe knows a bunch...
>>
>>Tom
>
>He certainly knows much *more* than me.
>
>MrAsm
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
6/23/2007 5:00:42 AM
I like it a lot!
Thank you for this post.

MrAsm


On Sat, 23 Jun 2007 01:00:42 -0400, Joseph M. Newcomer
<newcomer@flounder.com> wrote:

>Some years ago a programmer who worked with me kept being dismayed because every time he
>asked me a question I had an answer.  A couple years later we were working on a project,
>when I remarked, "I have a 25th anniversary this month!" (it was September, 1988).  
>
>"Of what?" he asked.  
>
>"I met my first computer 25 years ago.  It was September, 1963".  
>
>He then said, in his best Marvin-the-paranoid-android voice, "Ohhhh.  I feel soooo
>depressed".  
>
>"Why do you feel depressed?"
>
>"Because I was *born* in October of 1963!"
>
>"Well, that's why I know so much more.  I've been doing this longer than you've been
>alive!  You'll be doing this to junior programmers in a few years.  Don't worry about it!"
>
>He went on to get his PhD (one of my personal triumphs was being one of the people who
>convinced him to do this) and now has 20 more years experience.  I expect he's at least as
>good as I am, and probably better.
>
>Write enough code, and you eventually end up knowing a lot.  All it takes is experience
>(and remember: good judgment is the result of experience; experience is the result of bad
>judgment.  Trust me: I have good judgment, at least most of the time.  Now figure out
>why...)
>
>*****
>One day I went in to see my thesis advisor.  I'd been bashing my head against the wall for
>two weeks on a problem that was COMPLETELY intractable.  So I filled his board up with
>diagrams, he sat there and said, "But isn't that just a special case of..." and I turned
>to the board, my jaw fell down, and it was OBVIOUS what I'd missed.  So I got seriously
>pissed off at myself, and said "I have no idea why I'm wasting your time; I'm not capable
>of doing this work!"
>
>So he told me to sit down and listen.  When he was working on HIS Ph.D., on some bizarre
>aspect of partial differential equations, he hit a similar block.  He filled the board
>with formulae, and his advisor said "But that's just <name here>'s Theorem"  He was a
>graduate assistant, taught the introductory calculus courses, and in fact had just taught
>this theorem and its derivation the previous semester.  His advisor told him a similar
>story.
>
>So one day one of my students walks into my office with an intractable problem, fills the
>board with diagrams, and says "I have no idea how to approach this problem!"  I looked at
>it, and said, "But you've just described an abstract data type model with derivation!"
>
>He got The Look.  I'd seen that Look, not too many years before, from his side.  He threw
>the eraser across the office, and said "I'm wasting my time here!  I've been working on
>this for three months and never saw that!"
>
>So I sat him down and told the first three cycles of this story.  He was now the fourth
>cycle.  I told him that someday he, too, would have this experience, and please pass the
>story on.
>
>About five years later we met at a conference.  He said "It happened!"
>
>I asked "What happened?"
>
>"That day in your office.  A couple months ago, one of my students walked in, filled my
>board with diagrams, and the solution was obvious.  So I told her, and she burst into
>tears.  But since she had planned an academic career, I told her ot sit down, and told her
>your story, and now she was the fifth turn of the cycle.  And someday it would happen to
>her and she should pass this story on."
>
>I haven't seen him in many years, although his student did go on to get her Ph.D., and
>I've always wondered if she's had the experience and has passed the story on once more.
>					joe
>On Tue, 19 Jun 2007 10:18:38 GMT, MrAsm <mrasm@usa.com> wrote:
>
>>On Mon, 18 Jun 2007 17:13:13 -0700, "Tom Serface"
>><tom.nospam@camaswood.com> wrote:
>>
>>>Indeed, but Joe knows a bunch...
>>>
>>>Tom
>>
>>He certainly knows much *more* than me.
>>
>>MrAsm
>Joseph M. Newcomer [MVP]
>email: newcomer@flounder.com
>Web: http://www.flounder.com
>MVP Tips: http://www.flounder.com/mvp_tips.htm
0
mrasm (715)
6/23/2007 8:42:24 AM
Reply:

Similar Artilces:

Sort by Icon is not working
Hello, My company recently upgraded to Outlook 2003. I used to be able to look at my inbox and sort the emails by the Icon column (which indicates whether the message is unread, forwarded, replied to, or is an appointment, etc). Now it only sorts out the appointments from all the other messages but it won't sort the email messages by icon (unread, replied to, forwarded) indicated by the blue and purple right/left arrows. Does anyone know how to turn the sorting back on so it works the way it used to? I used to use this sorting heavily to sort thru, file and delete the thousand...

Sorting Subtotals
Thanks for the answers on my previous question. I ended up not using them (those formulas are far too complex for a dabbler like me). I created two columns to find the origin of either "http://" or "http:// www." (always "1" if found), multiplied that by either 7 or 11 to get the starting position and then had a columsn for Max() of the previous two columns. Then I did another column to find the trailing "/" and then a Mid() with the values obtained in the preceding columns. Not I have the domain names, and I can sort the table to get Subtotals. What I&...

Modification: Sort Pick Ticket by Bin Number?
I'm searching for software vendor that has already modified GP so that it sorts the line items on the Pick Ticket by bin number. Does any vendor have this modification? Thanks, Dan L. I believe this option already exists within GP. When you print the pick ticket, one of the options is "Bin Sequenced". This should sort the items by bin number. Give it a try! Eleni "Dan Lapp" wrote: > I'm searching for software vendor that has already modified GP so that it > sorts the line items on the Pick Ticket by bin number. > > Does any vendor have this ...

How do I stop a Pivot Table from Sorting my data (Excel 2007)
The data in my Access database is in the order that I want it to be but my Pivot Table insists on sorting it either Ascending or Descending. I can't seem to turn this off... If I right-click on the field name and choose Sort > More Sort Options... > Manual (you can drag items to rearrange them) This makes no difference! If I choose PivotTable Options > Display > Field List: Sort in data source order This again makes no difference! Is there some trick I'm missing or is it simply impossible to preserve the original data source order? Br, Nick. Excel...

sort by date column
We have a worksheet that contains a colum with the date in it like 12/26/2007. We want to be able to sort by the month but anytime we try to sort it sorts by the year. Is there an easy way to do what we are trying to do? Thanks, CEV Insert a column next to this one (I assume the data is in column A). Use this formula: =MONTH(A1) and copy down Sort both columns, using the new column as sort key "CEV" <chadv@advancebkg.com> wrote in message news:fku5lh0mig@enews4.newsguy.com... | We have a worksheet that contains a colum with the date in it like | 12/26/2007. We want t...

alphabetical sort while ignoring preceeding numbers/symbols
Is it possible to do an alphabetical sort while ignoring preceeding numbers and symbols? That is, sort based on the first letters in a string of characters. On Sat, 1 Oct 2005 16:10:02 -0700, "silver fox" <silver fox@discussions.microsoft.com> wrote: >Is it possible to do an alphabetical sort while ignoring preceeding numbers >and symbols? That is, sort based on the first letters in a string of >characters. You can use a "helper column". In an adjacent column, insert a formula similar to =LEFT(A1,2). Then select both columns and sort on the helper ...

text sort
I have some text in each cell in a column. The first few words in the cell are in bold and the rest are normal text. Is there anyway I can move all the non-bold text from column A into column B, and leave the bold text in column A? Thanks If you have the same number of characters made bold in each row, then you might use data > Text to columns > Fixed width, and set the column break where you want them.........otherwise, if you don't have too many rows, you might go in and manually insert a semicolon, or comma or something between the bold and normal text ,(or one may already exi...

Sort Columns in Excel 2007
Is it possible? I cannot seem to find a way. Data menu, Sort. There's an Options button in the Sort dialog. HTH. Best wishes Harald "Saxman" <john.h.williamsREMOVETHIS@btinternet.com> wrote in message news:d-GdnV04zfbUY6HWnZ2dnUVZ8u6dnZ2d@bt.com... > Is it possible? > > I cannot seem to find a way. Do you mean sort left to right rather than up and down? If so, do Data - Sort - Options - Sort left to right, select the row you want to sort by and click OK. HTH Otto "Saxman" <john.h.williamsREMOVETHIS@btinternet.com> wrot...

Currency format in sort
I am working in Excel 2003. I have numeric data in column A that gets sorted. I would always like currency format in the first cell (A2) under the heading in A1. If I apply the format to A2, but then sort, the number with the currency format from A2 moves around and the new number in A2 no longer has currency formatting. Is there a way to lock in the format for cell A2 and still be able to sort? I don't want to have a separate column for the dollar sign. Thanks, Ricki I couldn't do it. But if you do this a lot, maybe you could record a macro when you: select your data sort b...

Sort Protected Sheet with Header Columns
I'm trying to get a spreadsheet to sort by clicking on the Header cell. I found the following code and it works when the sheet is unprotected: Sub Worksheet_SelectionChange(ByVal Target As Excel.Range) Application.EnableEvents = False If Not Intersect(ActiveCell, _ Range("A13:AT13")) Is Nothing Then 'Range with column headings ActiveCell.CurrentRegion.Sort Key1:=ActiveCell, Header:=xlYes End If Application.EnableEvents = True End Sub But, when I protect the sheet and try to run the following code, nothing happens. Sub Worksheet_SelectionCh...

Email Sorting
I have a column with email addresses. I'd like them grouped and sorted by email address. test@domain.com smith@help.com test2@domain.com alpha@help.com yahoo@yahoo.com would become.. test@domain.com test2@domain.com alpha@help.com smith@help.com yahoo@yahoo.com Thanks! One way: Copy addresses to an unused column. Choose Data/Text to Columns. Select Delimited, Click Next, check Other and enter @, click Next. Select the first column and choose the "Do not import column radio button". Click Finish. Sort on the column of domains. In article <1171379816.938911.73700@k78...

Sorting Contacts
How do I set-up the contacts on Outlook '97 so that it arranges the entries by company rather than by individual? The help option talks as changing the "File As", but I can't find this option. Can you help? Peter ...

Outlook XP Contact Sort
Transferred .pst file to new computer. Contacts sorted properly (last, first) in "Contacts" view, however when trying to send e-mail using contact list, the list shown is sorted first, last. I know that the Tools>Options>Contact Options" routine is only supposed to "fix" new entries, but how do I correct existing entries? TIA. --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.688 / Virus Database: 449 - Release Date: 5/18/2004 Willy <dehinten@yahoo.com> wrote: > Transferred .pst ...

Sort and exclude certain words
Hi ... I work in a public library and frequently export lists of books from our online catalog to Excel, so that I can manipulate the data in various ways. My problem in sorting in Excel is this: Our library catalog excludes words like "The" "A" or "An" at the beginning of a title when sorting. Excel, however, does not. Is there any way I can sort on a field in Excel and have it ignore certain words at the beginning of a string? Thanks! -- jds217 ------------------------------------------------------------------------ jds217's Profile: http://www.exc...

Sorting files in a folder
I have a folder with *.jpg files and *.AVI files. I would like to group or sort these files so that all the jpg files are separated from the AVI files. Within those two groups, I would like the second sort criteria to be by the Date Taken or Date Created in ascending order. In XP, you could sort by file type - but, unless MS changed the name, I don't see how to do this. If I can only sort the AVI files in a sort or group - then change to the jpg files (all by date), that's OK. Can anyone help? Right-mouse click on empty spac in that folder, and all options are open for ...

Disconnected ado recordset can not apply filter and sort
I created a disconnected ado recordset when a form is open: Private Sub Form_Open(Cancel As Integer) Dim formrst As ADODB.Recordset Set formrst = New ADODB.Recordset 'append 3 fields With formrst .ActiveConnection = Nothing .CursorLocation = adUseClient .Fields.Append "Fname", adBSTR .Fields.Append "Lname", adBSTR .Fields.Append "Age", adBigInt End With 'append some values to the recordset With formrst .Open .AddNew .Fields("fname") = "Tom" ...

Workaround for sorting activities by date!!
I have a workaround for sorting activities by date that does not involve telling your sales people to type the date on the subject line! This is in depth and is not supported in any way. If you don't understand how to create triggers and views in SQL Server then do not attempt this. First thing's first... Make a backup of your CRM database. Create a new user defined function as follows: CREATE FUNCTION [dbo].[DateFormat] (@date datetime) RETURNS char(10) AS BEGIN RETURN ('[' + CONVERT(char(8), @date, 2) + ']') END Then find the view called "Activity". L...

Sorting/Grouping
Hello, I have a problem with Acc2003, it worked fine with acc97. 1) I have a report with Sorting/grouping section and I want that every group should start a new page. I set the Force New Page to Before Section. Now with acc2003 the first page is blank. (the After Section with the Keep Together doesn't work either) Thanks in advance abe katz wrote: >Hello, >I have a problem with Acc2003, it worked fine with acc97. > >1) I have a report with Sorting/grouping section and I want that every group >should start a new page. I set the Force New Page to Before Section. Now >...

Sorting Data that feeds into other formulas....
Hello: I have a workbook (Excel 2003) and I am having trouble with a particular sorting issue. On page 2, column GL contains specific data that feeds into formulas used in Page 1. When I sort my data on page 2 it changes the formula totals on page 1. What I want to do is have the ability to 'lock' the data on page 2 so that after I sort it doesn't change the totals in my formulas using the Page 2 cell references. For example on Page 1, one of my cells reads the following formula: ='Rep Stack Ranking'!GL$12+'Rep Stack Ranking'!GL$13+'Rep Stack Rank...

Sorting multiple columns as 1 list alphabetically?
Can anyone help with a solution for something i'm trying to achieve in excel? I have a long list of names that spread many cells down as well as several columns across and i'm trying to sort the entire list into alphabetical order. I know I can sort one column at a time but that is not what i want to achieve. I need to be able to select all of the data and sort it into alphabetical order (with the a's starting in the first cell of the first column and the z's finishing in the last cell of the last column). What I really need to do is be able to link columns so that the data i...

Sorting data in a table by the header of a column?
Is there a way to get excel to sort the data in a table by clicking on the header of a column like a windows folder does? No. You have to go to data/sort..tell it you have a header, and the pick the columns you want to sort by -- dfeld7 ----------------------------------------------------------------------- dfeld71's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=2145 View this thread: http://www.excelforum.com/showthread.php?threadid=37449 Hello Aaron, Not from the column labels A, B, etc. but from within the column of data that should be the primary sort,...

Sorted by Name Views ('SortOrder')
Please, if it is not too much trouble add some kind of sorting capabilities (sort order field maybe) to the Views (Filters). We have like 20 custom filters/views and they all appear to be sorted by - nothing in particular. That makes the whole Views/filters thing not working and the people trying to use them very frustrated. If you can add "ORDER BY Name..." to the SQL query for the Views that would make the product a little less uncomfortable to use. Thanks! You CAN define a sort order for a view! Its a facility built in to the system Take a close look at the system custom...

How to sort rows by Colors
hi there, can anybody help me out to sort the rows by Colors. like I have two colored rows Light Green and Light Yellow and some are without colors. how do i sort them that same colors come with eachother? -- Sheikh Saadi Sheikh, this is not a buit in function in excel, will be in the next version, have a look here for a way to do it http://www.cpearson.com/excel/SortByColor.htm -- Paul B Always backup your data before trying something new Please post any response to the newsgroups so others can benefit from it Feedback on answers is always appreciated! Using Excel 2002 & 2003 &qu...

Microsoft Excel Sort Problem
I have always been able to sort columns in micosoft excel. I select auto format but when I go to the Data area I cannot sort - the "sort" selection is in gray. Please help! Thanks! Is the sheet protected? -- Regards, Peo Sjoblom "VK" <anonymous@discussions.microsoft.com> wrote in message news:089601c3d45d$d89a8c40$a601280a@phx.gbl... > I have always been able to sort columns in micosoft > excel. I select auto format but when I go to the Data > area I cannot sort - the "sort" selection is in gray. > Please help! Thanks! How about...

Sort on Tab Change
Is there a way to trigger sorting of a column, when I change tabs? I have a dataset that I use for input and a different tab which is a leaderboard. I want to sort the leaderboard by high score every time I change to that tab. I currently have a macro button I click to sort by high score, then I have to click the leadboard tab. I'd obviously like to click the leaderboard tab and have the data sorted by high score. Just attempting to combine 2 steps. step 1 - Sort input form by highscore step 2 - open the leaderboard tab Thanks, Jeff right-click the ...