Solved

Files in VB

Posted on 1998-12-30
11
155 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 100 total points
ID: 1453209
ok, any more problems then just let me know.
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Microsoft Access combo box help 2 57
MsgBox 4 75
VB6 - Scroll Mouse wheel on Picturebox 13 119
Excel Web Add-in Where is Visual Basic used 9 77
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

734 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