Tom Ogilvy said:
the addressof operator probably is what you want.
It isn't clear whether the original poster is writing the sort code in
VB/VBA or in C/C++. If the code is written in C/C++, then the AddressOf
operator will be useful. However, if the code is written in VB/VBA, the
AddressOf operator will be useless. You can surely use it to obtain the
address of a function, but there is no way in VB/VBA to execute the function
pointed to by the value returned by AddressOf.
I have a qsort procedure for arrays of simple variable types (e.g., Longs,
Strings, etc) at
www.cpearson.com/excel/QSort.htm and a procedure for
arrays of objects of any type at
www.cpearson.com/excel/SortingArraysOfObjects.htm . Both support
user-defined comparison functions, but the functions must be named
"QSortCompare" (for arrays of simple variables) or "QSortObjectCompare" (for
arrays of Objects).
The only other way to do it would be to put the comparison function(s) in a
Class module and use CallByName to call the appropriate comparison
procedure, but this would likely introduce an excessive amount of overhead
if the arrays are large.
I use AddressOf in VBA in a Windows Timer Manager program I'm writing, but
all I do with the address is pass it forward to the SetTimer API function.
If you are staying within VB/VBA, there is nothing useful you can do with
AddressOf.
--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)