Home Directory Classifieds Reference Archives
Site Info
About 4DToday.com
Contact Us
Version française
Developers (723)
4D Developers (591)
Web Developers (334)
Tools Publishers (201)
Instructors (166)
Web Hosts (58)
Resellers (90)
Software Publishers (302)
Search Developers
Products (383)
Plug-Ins (104)
Components (48)
Code Libraries (9)
Books (7)
Tools (42)
Vertical Applications (148)
Search Products
User Groups
All User Groups (22)
Classified Ads (15)
Help Wanted (9)
Opportunities Wanted (6)
Hardware Wanted (0)
Hardware for Sale (0)
Software Wanted (0)
Software for Sale (0)
Other (0)
4D, Inc.
4D International
4D Wiki
4D Partner Central
4D Beginner's Center
4D Online Documentation
4D 2004 Example Applications
4D Example Databases
4D BugDisplayer
4D, Inc. Training
Message Lists
4D Mailing Lists
4D Tech Google Group
iNUG Archives (Nabble)
iNUG Archives (Gmane)
iNUG Message Index
4D Code Exchange
4D Resources
Sviluppo4D.it (Italy)
4D Sources (4D Plugin API, 4D Pop & Miyako
Wrinkles should merely indicate where the smiles have been.
Mark Twain  
  Suggest a Quote  
4D v14 R4 official release
4D v14 R4 is now ready for download via the 4D Store.  Would you like to know more? Wednesday
 Submit Future News    Archive 
Technical Tip
Find duplicate field values in selection
Submitted by Keith Culotta, Computer Dimensions, Inc.

Here's a fairly fast 4D method for finding duplicates in a single field. Pass a pointer to the field. There must be enough memory to handle an array for each record's field value, a longint array of the selection's size and another longint array of up to half the selection's size.

The method can return a set of records that have a duplicate in the selection or just display a selection of the duplicates it found.

// ----------------------------------------------------
// User name (OS): Keith
// Date and time: 11/16/12, 11:12:14
// ----------------------------------------------------
// Method: DuplicatesToSet
//          Search the current selection for duplicate values in a field.
// INPUT1: Pointer - to field to examine
// INPUT2: Text - name of Set to contain duplicates or ""
//          The selection will not be changed when a non blank string is passed.
//          In this case the calling method will handle the created Set.
//          Pass an empty string to make this method change the selection
//          to show any duplicates found.
// INPUT3: Boolean - Sort the array
//          Falsecan be passed if the selection is already sorted on $1
// OUTPUT: Longint - Number of records in the set
// ----------------------------------------------------


If ($2#"")
End if

SELECTION TO ARRAY($table->;$aRecs;$field->;$afield)

If ($sortArray)
SORT ARRAY($afield;$aRecs)
End if

$size:=Size of array($aRecs)
$addFirst:=True // add a record to the duplicate array only once

For ($i;2;$size)
If ($aField{$i}=$aField{$i-1})
If ($addFirst)
APPEND TO ARRAY($aFound;$aRecs{$i-1})
End if
APPEND TO ARRAY($aFound;$aRecs{$i})
End if
End for

CREATE SET FROM ARRAY($table->;$aFound;$DupSet)
$0:=Records in set($DupSet)

If ($2="")
USE SET($DupSet)
End if
  Submit a Tip    Archive 
Developer Positions and Contract Projects Open Now!
Developer Positions and Contract Projects Open Now! • Full-time, on site
• Remote project contracts
• Internet linked projects
• Interface design a plus
• No winter – California!
• USA visas
• Client & network support by others
• V14, no hardware restrictions
• Stable hi-tech mfgr, 35 years
• In-house enterprise system
  Suggest a Spotlight  
Survey Results
This weekend, we asked you...
When did you start using 4D?
Survey Results

Your vote: (no vote)
Total votes received: 56
  Suggest a Survey  
There are no events scheduled for the upcoming fortnight.
  Submit an Event