Results 1 to 2 of 2

Thread: Trying to read from two files at once

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2007
    Posts
    8

    Trying to read from two files at once

    Hello VB community,

    Ok, I am at the point of hiring someone to do this for me. Sadly, I am a broke student. Here is my problem:

    I am reading from one file (bobo.txt). That file contains this:

    ...
    L0G1W0,35200824,0.00202164486,0
    L0H1G0,35190765,0.11641453567,0
    L0H1G0,35190766,0.06262106163,0
    L0H1G0,35190766,0.09166227313,0
    ...

    Do you see L0H1G0? It occurs three times, but the last two occurrences belong to the same ID (35190766). I basically have to eliminate that and only have one occurrence of L0H1G0 per 35190766.

    This is the code I came up with. It is so short yet does not do what is has to!

    The output is simply:

    ,"
    ",,"
    ",,"
    ",,"
    ",,"

    Can anyone please let me know what could ne wrong with this code? I am really losing it...

    thank you so much,

    Sashka

    vb Code:
    1. Dim strText(3) As Variant, strTextInternal(3) As Variant, strTextWrite(3) As Variant, strTextTemp(3) As Variant
    2. Dim strTextTemp2(3) As Variant
    3. Dim strInput As Variant
    4. Dim strInput2 As Variant
    5. Dim i As Integer, j As Integer, k As Integer
    6.  
    7. 'Creating FreeFiles
    8. Dim IPF As Integer
    9. Dim OPF As Integer
    10. Dim OPF2 As Integer
    11.  
    12. OPF = FreeFile()
    13. Open "c:\data\secondfile.txt" For Output As #OPF
    14. IPF = FreeFile()
    15. Open "c:\data\bobo.txt" For Input As #IPF
    16. IPF2 = FreeFile()
    17. Open "c:\data\bobo2.txt" For Input As #IPF2 'bobo2.txt is same as bobo.txt.
    18.  
    19. Do While Not EOF(IPF)
    20.     Input #IPF, strInput
    21.     strTextTemp(3) = Split(strInput, ",")
    22.     strText(0) = strTextTemp(0)
    23.     strText(1) = strTextTemp(1)
    24.    
    25.     Do While Not EOF(IPF2)
    26.         Input #IPF2, strInput2
    27.         strTextTemp2(3) = Split(strInput2, ",")
    28.         strTextInternal(0) = strTextTemp2(0)
    29.         strTextInternal(1) = strTextTemp2(1)
    30.        
    31.         If strText(0) = strTextInternal(0) And strText(1) = strTextInternal(1) Then
    32.             strTextWrite(0) = strTextInternal(0)
    33.         End If
    34.     Loop
    35.         Write #OPF, strTextWrite(0); vbNewLine;
    36. Loop
    37.  
    38. Close #IPF
    39. Close #OPF
    40. Close #OPF2
    41.  
    42. End Sub

  2. #2
    Addicted Member
    Join Date
    Jan 2007
    Location
    England
    Posts
    234

    Re: Trying to read from two files at once

    would it not be best sorting the records first?
    then compare the 2 lines
    eg line 1 and line 2
    if line 2 = to line1 then delete like 2
    then line 3 would become line 2
    if theyre different, then line 2 would become line 1
    if you get me?

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