×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

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

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

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

(OP)
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

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

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 "=".

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

(OP)
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.

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

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.

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

(OP)
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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close