4DToday.com
4D Net Center Hosting
Home Directory Classifieds Reference Archives
Site Info
About 4DToday.com
Contact Us
Version française
Quote
Developers (721)
4D Developers (597)
Web Developers (339)
Tools Publishers (197)
Instructors (165)
Web Hosts (60)
Resellers (86)
Software Publishers (298)
Search Developers
Products (406)
Plug-Ins (121)
Components (62)
Code Libraries (9)
Books (7)
Tools (42)
Vertical Applications (147)
Search Products
User Groups
All User Groups (22)
Classified Ads (8)
Help Wanted (3)
Opportunities Wanted (5)
Hardware Wanted (0)
Hardware for Sale (0)
Software Wanted (0)
Software for Sale (0)
Other (0)
Resources
4D
4D, Inc.
4D Wiki
4D Partner Central
4D Knowledgebase
4D Doc Center
Example Applications
4D BugDisplayer
4D, Inc. Training
Podcasts on 4D
Message Lists
4D Bulletin Board
4D-Forum
4D Mailing Lists
4D Tech Google Group
iNUG Archives (Nabble)
iNUG Archives (Gmane)
Other
4D Code Exchange
4D Resources
Sviluppo4D.it (Italy)
Quote
You don't get to choose how you're going to die, or when. You can only decide how you're going to live now.
Joan Baez  
  Suggest a Quote  
Developer News
4D Announces New Web Publishing Pricing for 4D 2004
4D, Inc. today notified 4D Partners of a new price plan that splits the costs of serving web pages and offering web services. Now 4D 2004 can be used as a Web server for just US$499 (a $400 savings), or for Web services publising for US$499. Developers can purchase a bundle to do both for US$899. 5 Aug 2004
4D Werkstatt - Developer Meeting in Wiesbaden August 6th
The monthly developer meeting of the 4D user group of the Rhein-Main area will be held on August 6th in Wiesbaden, Germany. 5 Aug 2004
 Submit Future News    Archive 
Technical Tip
Multi-criteria Sort for Arrays
Submitted by Thibaud Arguillière

Here is a method, named r_SortMultiArray, that allows you to do a multi-criteria sort on arrays. Here is the routine's syntax:

r_SortMultiArray("criteria";->array1;...;->array24max)

The criteria sort the n first arrays (1 per criteria). For example:

r_SortMultiArray(">><>";->array1;->array2->array3->array4->array5->array6->array7)

The sort on the arrays will be as follows: array1 in ascending order, array2 in ascending order, array3 in descending order, array4 in ascending order, and the others remain synchronized.

You can pass any type of array as parameters to this routine (including two-dimensional arrays), but the sort will only be done on "sortable" arrays, meaning no pointer or image arrays.

Remember that there is another routine, r_IsBasicUnidimArray, which is shown at the bottom that checks the types of arrays.

Here is the r_SortMultiArray method:

  ` Method : r_SortMultiArray
  ` By  Pierre Nayrolles / Thibaud Arguillère
  ` Parameters
  `  $1; Alpha 31, sort order
  `  ${2}; pointer to the arrays to sort

C_STRING(31;$1)  ` indicates the sort order, if it's empty, nothing happens
C_POINTER(${2})  ` pointer to the arrays to sort
  `
C_LONGINT($L_ArraySize;$i;$j;$k)
C_POINTER($W_Pointer)
C_INTEGER($I_LastKey)
C_STRING(31;$S031_SortingDirection)
  `
Case of
 : (Count parameters<2)
     `... **** Alert, log, trace...
     ` : (...tests that $1 contains only "<" or ">")
     `... **** Alert, log, trace...
 : ($1="")
     ` do nothing
 Else
     `
   If (Length($1)>(Count parameters-1))
     $I_LastKey:=Count parameters-1  
              ` maximum number of sorting keys = number of arrays
     $S031_SortingDirection:=Substring($1;1;$I_LastKey)
              ` take off the sorting direction
   Else
     $I_LastKey:=Length($1)
     $S031_SortingDirection:=$1
   End if
   $L_ArraySize:=Size of array($2->)
     
   If (($I_LastKey>0) & ($L_ArraySize>0))  ` at least one sort
     ARRAY STRING(255;$rS255_SortingString;$L_ArraySize)
                ` array for the final sort      
     ARRAY LONGINT($rL_SortingValue;$L_ArraySize)
                ` compare values in the arrays
     ARRAY LONGINT($rL_Indice;$L_ArraySize)
                ` initial order, to find the initial order
     ARRAY LONGINT($rL_KeepIndice;$L_ArraySize)
                ` to find the values sorted by line numbers
     For ($j;1;$L_ArraySize)
                ` fill the arrays with the indexes
       $rL_KeepIndice{$j}:=$j
     End for
       `
     For ($i;1;$I_LastKey)  ` create the sorting array
       $W_Pointer:=${$i+1}
       Case of
         : (Not(r_IsBasicUnidimArray ($W_Pointer)))
             ` it's not a sortable array
             `... **** Alert, log, trace...
         : (Size of array($W_Pointer->)#$L_ArraySize)
             ` Arrays are not the same size            
             `... **** Alert, log, trace...
         Else
             `  
           COPY ARRAY($rL_KeepIndice;$rL_Indice)
                ` to have th initial order
           If ($S031_SortingDirection[[$i]]=">")
                ` ascending order
             SORT ARRAY($W_Pointer->;$rL_Indice;>)
           Else
             SORT ARRAY($W_Pointer->;$rL_Indice;<)
           End if
           $rL_SortingValue{1}:=1
                ` legal because we are sure that there's at least one row (element)
           For ($j;1;$L_ArraySize-1)
                ` assign the same value to identical rows
             For ($k;$j+1;$L_ArraySize)
                ` internal comparison loop
               If ($W_Pointer->{$k}=$W_Pointer->{$j})
                ` if the "k" value is equal to the "j" value                  
                 $rL_SortingValue{$k}:=$rL_SortingValue{$j}
                ` values are the same
               Else
                 $rL_SortingValue{$k}:=$rL_SortingValue{$j}+1  ` increment
                 $j:=$k-1  ` skip the rows we just saw (take off 1)
                 $k:=$L_ArraySize  ` exit the internal loop
               End if
             End for
           End for   ` ($j;1;$L_ArraySize-1)
           SORT ARRAY($rL_Indice;$rL_SortingValue;$W_Pointer->)
                ` sort in the order of the beginning rows
           For ($j;1;$L_ArraySize)  ` add values to what already exists
             $rS255_SortingString{$j}:=$rS255_SortingString{$j} + String($rL_SortingValue{$j};"000000000")
                ` concatenate
           End for
             
       End case
     End for   ` ($i;1;$I_LastKey)
       `
       `
     Case of
       : (Count parameters=2)
         SORT ARRAY($rS255_SortingString;$2->)
       : (Count parameters=3)
         SORT ARRAY($rS255_SortingString;$2->;$3->)
       : (Count parameters=4)
         SORT ARRAY($rS255_SortingString;$2->;$3->;$4->)
       : (Count parameters=5)
         SORT ARRAY($rS255_SortingString;$2->;$3->;$4->;$5->)
       : (Count parameters=6)
         SORT ARRAY($rS255_SortingString;$2->;$3->; $4->;$5->;$6->)
       : (Count parameters=7)
         SORT ARRAY($rS255_SortingString;$2->;$3->; $4->;$5->;$6->;$7->)
       : (Count parameters=8)
         SORT ARRAY($rS255_SortingString;$2->;$3->; $4->;$5->;$6->;$7->;$8->)
       : (Count parameters=9)
         SORT ARRAY($rS255_SortingString;$2->;$3->; $4->;$5->;$6->;$7->;$8->;$9->)
       : (Count parameters=10)
         SORT ARRAY($rS255_SortingString;$2->;$3->; $4->;$5->;$6->;$7->;$8->;$9->; $10->)
       : (Count parameters=11)
         SORT ARRAY($rS255_SortingString;$2->;$3->; $4->;$5->;$6->;$7->;$8->;$9->; $10->;$11->)
       : (Count parameters=12)
         SORT ARRAY($rS255_SortingString;$2->;$3->; $4->;$5->;$6->;$7->;$8->;$9->; $10->;$11->;$12->)
       : (Count parameters=13)
         SORT ARRAY($rS255_SortingString;$2->;$3->; $4->;$5->;$6->;$7->;$8->;$9->; $10->;$11->;$12->;$13->)
       : (Count parameters=14)
         SORT ARRAY($rS255_SortingString;$2->;$3->; $4->;$5->;$6->;$7->;$8->;$9->; $10->;$11->;$12->;$13->;$14->)
       : (Count parameters=15)
         SORT ARRAY($rS255_SortingString;$2->;$3->; $4->;$5->;$6->;$7->;$8->;$9->; $10->;$11->;$12->;$13->;$14->;$15->)
       : (Count parameters=16)
         SORT ARRAY($rS255_SortingString;$2->;$3->; $4->;$5->;$6->;$7->;$8->;$9->; $10->;$11->;$12->;$13->;$14->;$15->;$16->)
       : (Count parameters=17)
         SORT ARRAY($rS255_SortingString;$2->;$3->; $4->;$5->;$6->;$7->;$8->;$9->; $10->;$11->;$12->;$13->;$14->;$15->;$16->;$17->)
       : (Count parameters=18)
         SORT ARRAY($rS255_SortingString;$2->;$3->; $4->;$5->;$6->;$7->;$8->;$9->; $10->;$11->;$12->;$13->;$14->;$15->;$16->;$17->;$18->)
       : (Count parameters=19)
         SORT ARRAY($rS255_SortingString;$2->;$3->; $4->;$5->;$6->;$7->;$8->;$9->; $10->;$11->;$12->;$13->;$14->;$15->;$16->;$17->;$18->; $19->)
       : (Count parameters=20)
         SORT ARRAY($rS255_SortingString;$2->;$3->; $4->;$5->;$6->;$7->;$8->;$9->; $10->;$11->;$12->;$13->;$14->;$15->;$16->;$17->;$18->; $19->;$20->)
       : (Count parameters=21)
         SORT ARRAY($rS255_SortingString;$2->;$3->; $4->;$5->;$6->;$7->;$8->;$9->; $10->;$11->;$12->;$13->;$14->;$15->;$16->;$17->;$18->; $19->;$20->;$21->)
       : (Count parameters=22)
         SORT ARRAY($rS255_SortingString;$2->;$3->; $4->;$5->;$6->;$7->;$8->;$9->; $10->;$11->;$12->;$13->;$14->;$15->;$16->;$17->;$18->; $19->;$20->;$21->;$22->)
       : (Count parameters=23)
         SORT ARRAY($rS255_SortingString;$2->;$3->; $4->;$5->;$6->;$7->;$8->;$9->; $10->;$11->;$12->;$13->;$14->;$15->;$16->;$17->;$18->; $19->;$20->;$21->;$22->;$23->)
       : (Count parameters=24)
         SORT ARRAY($rS255_SortingString;$2->;$3->; $4->;$5->;$6->;$7->;$8->;$9->; $10->;$11->;$12->;$13->;$14->;$15->;$16->;$17->;$18->; $19->;$20->;$21->;$22->;$23->;$24->)
       : (Count parameters=25)
         SORT ARRAY($rS255_SortingString;$2->;$3->; $4->;$5->;$6->;$7->;$8->;$9->; $10->;$11->;$12->;$13->;$14->;$15->;$16->;$17->;$18->; $19->;$20->;$21->;$22->;$23->;$24->;$25->)
     End case
   End if
End case


Here's the  other method r_IsBasicUnidimArray:

C_POINTER($1)  ` pointer to the object to test
C_BOOLEAN($0)  ` test result
  `
C_INTEGER($i_type)
  `
$0:=False
Case of
 : (Count parameters=0)
     `... **** Alert, log, trace...
 : (Not(Is a variable($1)))
   
 Else
   $i_type:=Type($1->)
   $0:=True
   Case of
     : ($i_type=String array )
     : ($i_type=Text array )
     : ($i_type=Integer array )
     : ($i_type=LongInt array )
     : ($i_type=Real array )
     : ($i_type=Date array )
     : ($i_type=Boolean array )
     Else
       $0:=False
   End case
   
End case
  Submit a Tip    Archive 
Spotlight
SapphireOne
SapphireOne SapphireOne
is a complete back-end financial management system created with 4th Dimension. This cross-platform application includes financials, assets, and payroll.
  Suggest a Spotlight  
Survey Results
Today, we asked you...
Which 4D Compiler Compilation Path setting do you generally use?
Survey Results

Your vote: (no vote)
Total votes received: 99
  Suggest a Survey  
Events
August 2010
6 4D Werkstatt Developer Meeting
Wiesbaden (Germany) from 11:00 AM to 7:00 PM
Details
9-10 4D for Database Administrators
San Jose, California
Details
11-13 Designing Relational Databases
San Jose, California
Details
12 4D WorkShop
4D Werkstatt, Wiesbaden (Germany) from 10:00 AM to 4:00 PM
Details
12 NorCal4D/Cupertino Meeting
De Anza 3 Auditorium at Apple Computer Campus from 6:30 PM to 8:30 PM
Details
  Submit an Event