?
Solved

Files in VB

Posted on 1998-12-30
11
Medium Priority
?
157 Views
Last Modified: 2010-05-03
I need to erase duplicate lines in a file.
please write the code that does it.
0
Comment
Question by:amird
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
  • +1
11 Comments
 

Author Comment

by:amird
ID: 1453199
Adjusted points to 100
0
 

Expert Comment

by:ChasDevlin
ID: 1453200
What is your file?   Is it a database or a text file?
0
 

Author Comment

by:amird
ID: 1453201
it's a text file

i need the function that search for duplicate lines and erase them

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 13

Expert Comment

by:Mirkwood
ID: 1453202
Are the duplicate lines after each other?

Sample:
xxx
xxx
yyy
zzz
zzz
xxx

So should the following file become a or b
a)
xxx
yyy
zzz
xxx
b)
xxx
yyy
zzz


0
 

Author Comment

by:amird
ID: 1453203
yes and no

the duplicate line scan be after each other or somewhere in the file
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1453204
So option B is what you want? If not please give an example.
0
 
LVL 18

Expert Comment

by:deighton
ID: 1453205
Private Sub RemoveDup(sFilePath As String)

    Dim iFile1 As Integer
    Dim iFile2 As Integer
    Dim iLine As Long
    Dim iline2 As Long
   
    Dim sString1 As String
    Dim sString2 As String
   
    Dim bDel(30000) As Boolean
   
    iFile1 = FreeFile
    Open sFilePath For Input As #iFile1
   
    While Not EOF(iFile1)
   
        Line Input #iFile1, sString1
        iLine = iLine + 1
   
        iFile2 = FreeFile
        Open sFilePath For Input As #iFile2
       
        iline2 = 0
        While Not EOF(iFile2)
       
            Line Input #iFile2, sString2
            iline2 = iline2 + 1
       
            If iline2 > iLine And sString1 = sString2 Then
           
                bDel(iline2) = True
               
            End If
           
        Wend
       
        Close iFile2
       
    Wend


    Close iFile1
   
    iFile1 = FreeFile
    Open sFilePath For Input As #iFile1
   
    iFile2 = FreeFile
   
    'Your text file is output here with no duplicates
    Open "Output" For Output As #iFile2
   
    iLine = 0
   
    While Not EOF(iFile1)
   
        Line Input #iFile1, sString1
        iLine = iLine + 1
        If Not bDel(iLine) Then
       
            Print #iFile2, sString1
           
        End If
       
    Wend
   
    Close #iFile1, #iFile2
   
   
End Sub


0
 
LVL 18

Expert Comment

by:deighton
ID: 1453206
sFilePath is the name and path of your file to process e.g.

"c:\data\file1.txt"


0
 

Author Comment

by:amird
ID: 1453207
the function doesnt work !!!!!!!!!!
0
 

Author Comment

by:amird
ID: 1453208
Sorry Thank you its working great
0
 
LVL 18

Accepted Solution

by:
deighton earned 300 total points
ID: 1453209
ok, any more problems then just let me know.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month12 days, left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question