Solved

Files in VB

Posted on 1998-12-30
11
153 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
  • 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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 100 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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

829 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