Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I couldn't write a code to find repeated cods.

Status
Not open for further replies.

Rosciano

Technical User
Jun 16, 2003
64
0
0
IT
Hi everybody,

I have a file that has thousands of records; one of the fields is called “cod”.
Happens that some records have the same cod. I already fix the input part to avoid input repeated “cods”, but I couldn’t do a code to list/find the records with the same code.
I state that “cod” is four characters long. Can somebody help me? [sad]
Thank you.

Antonio
dBase III Plus Version 1.1

 
Code:
USE myTable
INDEX ON cod TO mySearch
GO TOP

tmpCodWas = cod
tmpRecWas = RECNO()
DO WHILE .NOT. EOF()
   SKIP
   IF tmpCodWas = cod
      ? cod + " duplicated in records " + LTRIM(STR(tmpRecWas,10)) + " & " + LTRIM(STR(RECNO()))
   ENDIF
   tmpCodWas = cod
   tmpRecWas = RECNO()
ENDDO

DELETE TAG mySearch  && or delete when review completed
USE IN myTable

This should work for you. The output will list in the indexed order of the COD values, not the record number order. Of course if there are more than two duplicated values, more than one report line will display for those matches.

If you already have an index with the COD field as the first condition, then you can use that index and don't need to delete it afterward. I have assumed COD is a character field. Depending on the setting for SET EXACT you may needd to use "==" in place of "=".
 
Hi Mark, thank for your help.
I'm sorry if it took me a while to answer, I was away from the PC.

I did it some days after posting, but now I don’t remember how, I had to check the code, but your code is much but much shorter! I already took notes to review mine.
The only part I didn’t understand is the use of two “=” depending on SET EXACT...
I run to my book to read about.

Thank you again.
 
This is Visual FoxPro implementation, should be substantially similar to Dbase.

The == operator (or = operator when SET EXACT ON) can be used when an exact comparison of character strings is needed. If two character expressions are compared with the == operator, the expressions on both sides of the == operator must contain exactly the same characters, including blanks, to be considered equal. The SET EXACT setting is ignored when character strings are compared using ==.

SET EXACT OFF
Specifies that expressions must match character for character when comparing character data, or byte for byte when comparing binary data, until the end of the expression on the right side is reached to be equivalent.
 
Ah... that's used in Visual FoxPro, that's why I didn't recognize.
It is not used in dBase III Plus.

Thank you for your explanation.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top