4DToday.com
4D Net Center Hosting
Home Directory Classifieds Reference Archives
Site Info
About 4DToday.com
Contact Us
Version française
Quote
Developers (723)
4D Developers (592)
Web Developers (335)
Tools Publishers (200)
Instructors (166)
Web Hosts (58)
Resellers (90)
Software Publishers (303)
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 (8)
Help Wanted (5)
Opportunities Wanted (3)
Hardware Wanted (0)
Hardware for Sale (0)
Software Wanted (0)
Software for Sale (0)
Other (0)
Resources
4D
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
Other
4D Code Exchange
4D Resources
Sviluppo4D.it (Italy)
4D Sources (4D Plugin API, 4D Pop & Miyako
Quote
We must believe in luck. For how else can we explain the success of those we don't like?
Jean Cocteau  
  Suggest a Quote  
There are no news items at this time.
 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
// ----------------------------------------------------


C_POINTER($1;$field;$table)
C_TEXT($2;$DupSet)
C_LONGINT($i;$size)
C_LONGINT($0)
C_BOOLEAN($addFirst;$sortArray)

$field:=$1
If ($2#"")
$DupSet:=$2
Else
$DupSet:="$DupSet"
End if
$sortArray:=$3

ARRAY LONGINT($aFound;0)
ARRAY LONGINT($aRecs;0)
$table:=Table(Table($field))
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})
$addFirst:=False
Else
$addFirst:=True
End if
End for

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

If ($2="")
USE SET($DupSet)
CLEAR SET($DupSet)
End if
  Submit a Tip    Archive 
Spotlight
ObjectTools
ObjectTools ObjectTools, developed by Aparajita's World, is a plug-in that gives you a full suite of commands for managing an object. An object is like a BLOB, but instead of accessing the data by offset, you access each data item by name.
  Suggest a Spotlight  
Survey Results
This weekend, we asked you...
Have you used 4D Server, any version, successfully on any version of Mac OS X Server?
Survey Results

Your vote: (no vote)
Total votes received: 33

Survey submitted by Bill Weale
  Suggest a Survey  
Events
There are no events scheduled for the upcoming fortnight.
  Submit an Event