Results 1 to 9 of 9

Thread: Reply Quickly (Not to Hard) Editing a text document.

  1. #1

    Thread Starter
    Hyperactive Member Animelion's Avatar
    Join Date
    Jan 2001
    Location
    Jacksonville NC
    Posts
    283

    Reply Quickly (Not to Hard) Editing a text document.

    How can I read a text file, alphabatize it and then remove all duplicates down to 2

    so

    cow
    cow
    cow
    fun
    fun
    me
    me
    me
    me
    we

    NOW BECOMES

    cow
    cow
    fun
    fun
    me
    me
    we

    After that how can I read the same text file and be able to tell wich items are listed twice.

    If anyone can tell me, this would be major help.
    ~ Animelion

  2. #2
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    1. Load the text file into a ListBox (Sorted = True - at build),
    2. Loop thru an increment a counter if the next item is the same, if it reaches 3, delete that Item,
    3. And I think thats it

  3. #3
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    This will load a TextFile, and place it into a Sorted ListBox:
    VB Code:
    1. Option Explicit
    2. 'Set the List1 Sorted property to True at Build
    3.  
    4. Private Sub Form_Load()
    5.    Dim sBuff As String
    6.    Dim i As Long
    7.  
    8.    On Error GoTo err_Handler
    9.  
    10.    Open App.Path & "\TestFile.txt" For Input As #1
    11.        Do Until EOF(1)
    12.           Line Input #1, sBuff
    13.           List1.AddItem sBuff
    14.        Loop
    15.     Close #1
    16.  
    17.     Exit Sub
    18. err_Handler:
    19. MsgBox "Description : " & Err.Description & vbCrLf _
    20.     & "Number : " & Err.Number
    21.     Err.Clear
    22. End Sub

  4. #4
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    And this will remove 3 or more duplicates:
    VB Code:
    1. Option Explicit
    2. 'Set the List1 Sorted property to True at Build
    3.  
    4. Private Sub Form_Load()
    5.    Dim sBuff As String
    6.    Dim i As Long
    7.  
    8.    On Error GoTo err_Handler
    9.  
    10.    Open App.Path & "\TestFile.txt" For Input As #1
    11.        Do Until EOF(1)
    12.           Line Input #1, sBuff
    13.           List1.AddItem sBuff
    14.        Loop
    15.     Close #1
    16.  
    17.     For i = List1.ListCount - 1 To 0 Step -1 'Removes > 2 duplicates
    18.       If List1.List(i) = List1.List(i - 1) And List1.List(i) = List1.List(i - 2) Then
    19.          List1.RemoveItem (i)
    20.       End If
    21.     Next
    22.  
    23.     Exit Sub
    24.  
    25. err_Handler:
    26. MsgBox "Description : " & Err.Description & vbCrLf _
    27.     & "Number : " & Err.Number
    28.     Err.Clear
    29. End Sub

  5. #5
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    And, Done................
    VB Code:
    1. Option Explicit
    2. 'Set the List1 Sorted property to True at Build
    3.  
    4. Private Sub Form_Load()
    5.    Dim sBuff As String
    6.    Dim i As Long
    7.  
    8.    On Error GoTo err_Handler
    9.  
    10.    Open App.Path & "\TestFile.txt" For Input As #1
    11.        Do Until EOF(1)
    12.           Line Input #1, sBuff
    13.           List1.AddItem sBuff
    14.        Loop
    15.     Close #1
    16.  
    17.     For i = List1.ListCount - 1 To 0 Step -1 'Removes > 2 duplicates
    18.       If List1.List(i) = List1.List(i - 1) And List1.List(i) = List1.List(i - 2) Then
    19.          List1.RemoveItem (i)
    20.       End If
    21.     Next
    22.    
    23.     For i = 0 To List1.ListCount - 1   'Identifies any Duplicates
    24.       If List1.List(i) = List1.List(i + 1) Then MsgBox "Duplicate Found : " & List1.List(i)
    25.     Next
    26.  
    27.     Exit Sub
    28.  
    29. err_Handler:
    30. MsgBox "Description : " & Err.Description & vbCrLf _
    31.     & "Number : " & Err.Number
    32.     Err.Clear
    33. End Sub


    Tou could have used an Array, but why load an extra Variable, when
    this does the same thing...

    Bruce.

  6. #6

    Thread Starter
    Hyperactive Member Animelion's Avatar
    Join Date
    Jan 2001
    Location
    Jacksonville NC
    Posts
    283

    Thanks Bruce_Fox

    Thanks a ton, but I'm still having troubles.

    I'm gonna post what I have done.

    What I am trying to do is make it so that when a user opens a txt file all the words listed one time will be put in lstUsers2 and all names listed twice will go into lstUsers3

    After that it will take all the names in lstUsers2 and add them to lstUsers like such Column1: (word) Column2: (lvl 1)

    and then

    all the names in lstUsers3 and add them to lstUsers like such Column1: (word) Column2: (lvl 2)


    Maybe I am over complifying things, but I think this methode would still work.

    I will post the program in the next post.
    Last edited by Animelion; May 12th, 2002 at 09:48 AM.
    ~ Animelion

  7. #7

    Thread Starter
    Hyperactive Member Animelion's Avatar
    Join Date
    Jan 2001
    Location
    Jacksonville NC
    Posts
    283

    Here

    Here is as far as I could get.
    Attached Files Attached Files
    ~ Animelion

  8. #8
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: Thanks Bruce_Fox

    Originally posted by Animelion
    What I am trying to do is make it so that when a user opens a txt file all the words listed one time will be put in lstUsers2 and all names listed twice will go into lstUsers3
    Maybe u could load the data into a third, hidden, listbox.
    Then (after its sorted, and stripped of all 3 or more duplicates)
    only load Items if they don't match the next Item in the list.

    VB Code:
    1. If whatever.List(?) <> whatever.List(? + 1) Then IstUsers3 Additem whatever.List(?)



    Oh, and replace the On Error: code too!
    (also, it should be "On Error Goto Error", without the ":", and there
    should be an Exit Sub just above the Error: routine)

  9. #9

    Thread Starter
    Hyperactive Member Animelion's Avatar
    Join Date
    Jan 2001
    Location
    Jacksonville NC
    Posts
    283

    Thanks bruce_fox

    Thanks for your help, but I have now super simplified things.

    I have just used 4 seperate text files, and then compile them on command instead of trying to do it on the fly with 2 text files.

    THANKS A TON.

    By the end of all this I should wright a quick help tutorial for listviews and lisboxes.
    ~ Animelion

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width