|
-
Mar 24th, 2007, 07:13 PM
#1
Thread Starter
New Member
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:
Dim strText(3) As Variant, strTextInternal(3) As Variant, strTextWrite(3) As Variant, strTextTemp(3) As Variant
Dim strTextTemp2(3) As Variant
Dim strInput As Variant
Dim strInput2 As Variant
Dim i As Integer, j As Integer, k As Integer
'Creating FreeFiles
Dim IPF As Integer
Dim OPF As Integer
Dim OPF2 As Integer
OPF = FreeFile()
Open "c:\data\secondfile.txt" For Output As #OPF
IPF = FreeFile()
Open "c:\data\bobo.txt" For Input As #IPF
IPF2 = FreeFile()
Open "c:\data\bobo2.txt" For Input As #IPF2 'bobo2.txt is same as bobo.txt.
Do While Not EOF(IPF)
Input #IPF, strInput
strTextTemp(3) = Split(strInput, ",")
strText(0) = strTextTemp(0)
strText(1) = strTextTemp(1)
Do While Not EOF(IPF2)
Input #IPF2, strInput2
strTextTemp2(3) = Split(strInput2, ",")
strTextInternal(0) = strTextTemp2(0)
strTextInternal(1) = strTextTemp2(1)
If strText(0) = strTextInternal(0) And strText(1) = strTextInternal(1) Then
strTextWrite(0) = strTextInternal(0)
End If
Loop
Write #OPF, strTextWrite(0); vbNewLine;
Loop
Close #IPF
Close #OPF
Close #OPF2
End Sub
-
Mar 25th, 2007, 04:44 PM
#2
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|