Hallo!
Das eben war die Frage. Einzelne Zeile oder gesamte Datei als
Selektionskriterium.
Zunächst eine kleine Hilfsfunktion, um zu testen, ob ein
Wert bereits in einer Collection enthalten ist.
Public Function Contains(col As Collection, vl As Variant) As Boolean
Contains = False
Dim index As Integer
For index = 1 To col.count
If col(index) = vl Then Contains = True: Exit For
Next index
End Function Und so könnte es dann funktionieren ...
(Übrigens wäre alles einfacher zu verstehen und die Hinweise
zielgerichteter, wenn der Sinn dieser Operationen erklärt worden
wäre.)
Dim fc%, i1%, i2%, i3%, i4%
fc = FreeFile
'1. Ermittlung der Werte in Spalte 1 und Spalte 4
Open "C:\daten\demodaten.txt" For Input As #fc
Dim i1_col As New Collection, i4_col As New Collection
While Not EOF(fc)
Input #fc, i1, i2, i3, i4
If Not Contains(i1_col, i1) Then i1_col.Add i1
If Not Contains(i4_col, i4) Then i4_col.Add i4
Wend
Close #fc
'2. gefilterte Häufigkeit der Zahlenkombinationen in Spalte 2 / 3
Open "C:\daten\demodaten.txt" For Input As #fc
Dim i2_col As New Collection, i3_col As New Collection
Dim freq(10000) As Integer
Dim index As Integer, count As Integer, vorhanden As Boolean
While Not EOF(fc)
Input #fc, i1, i2, i3, i4
vorhanden = False
If Not (Contains(i1_col, i2) Or Contains(i1_col, i3) _
Or Contains(i4_col, i2) Or Contains(i4_col, i3)) Then
vorhanden = False
For index = 1 To i2_col.count
If i2_col(index) = i2 And i3_col(index) = i3 Then
freq(index) = freq(index) + 1: vorhanden = True: Exit For
End If
Next index
If Not vorhanden Then
i2_col.Add (i2): i3_col.Add (i3): freq(i2_col.count) = 1
End If
Else
'Bedingung: gefilterter Datensatz
'.....
End If
Wend
Close #fc
'3. Füllen der Ergebnisdatei: gefilterte Zahlenkombis, Häufigkeiten
Open "C:\daten\demoresult.txt" For Output As #fc
For index = 1 To i2_col.count
Print #1, CStr(i2_col(index)) & " - " & CStr(i3_col(index)) & _
": " & CStr(freq(index))
Next index
Close #fc [I]alle Zahlen die auf i1 und i4 stehen - dürfen in keiner - egal welcher Zeile -
der demoresult.txt in i2 oder i3 vorkommen.[/I] - vermute ich jetzt mal ???
Beitrag wurde zuletzt am 24.01.13 um 07:30:54 editiert. |