Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1268to1272
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

.txt's mit VBA bearbeiten #2

.txt's mit VBA bearbeiten #2
Horst
Hallo Sepp!
Jetzt stimmt die "train.txt", dafür ist die "test.txt" aber leer (0 Kb) und bei der "retrain.txt" fehlt die letzte Zeile.
Ich glaube am besten ist es, den Code (vorletzte Version) im Anhang zu nehmen und einfach die letzte Zeile der "train.txt" zu löschen.
Danke vorab,
Gruß, Horst
' **********************************************************************
' Modul: Modul1 Typ: Allgemeines Modul
' **********************************************************************
Option Explicit
Sub changeTXT_File2()
Dim strFile As String, strTrainFile As String, strReTrainFile As String, strTestFile As  _
String
Dim strTmpFile As String, strTmp As String
Dim lngIndex As Long, lngCol As Long, lngC As Long
Dim vntTmp As Variant, strTrain() As String, strReTrain() As String, strTest() As String
Dim FF1 As Integer, FF2 As Integer
strTrainFile = "E:\Temp\Test3\train_one.txt" 'Dateipfad train.txt - Anpassen
strReTrainFile = "E:\Temp\Test3\retrain_one.txt" 'Dateipfad retrain.txt - Anpassen
strTestFile = "E:\Temp\Test3\test_one.txt" 'Dateipfad test.txt - Anpassen
strFile = "E:\Temp\Test3\instrum.txt" 'Dateipfad Eingabe-Datei - Anpassen!
strTmpFile = Environ("TEMP") & "\Temp.txt"
'## train.txt einlesen
FF1 = FreeFile
Open strTrainFile For Input As #FF1
Do While Not EOF(FF1)
Line Input #FF1, strTmp
vntTmp = Split(strTmp, Chr(9))
Redim Preserve strTrain(lngIndex)
strTrain(lngIndex) = Trim$(Application.Clean(vntTmp(123)))
lngIndex = lngIndex + 1
Loop
Close #FF1
'## retrain.txt einlesen
FF1 = FreeFile
lngIndex = 0
Open strReTrainFile For Input As #FF1
lngIndex = 0
Do While Not EOF(FF1)
Line Input #FF1, strTmp
vntTmp = Split(strTmp, Chr(9))
Redim Preserve strReTrain(lngIndex)
strReTrain(lngIndex) = Trim$(Application.Clean(vntTmp(123)))
lngIndex = lngIndex + 1
Loop
Close #FF1
'## test.txt einlesen
FF1 = FreeFile
lngIndex = 0
Open strTestFile For Input As #FF1
Do While Not EOF(FF1)
Line Input #FF1, strTmp
vntTmp = Split(strTmp, Chr(9))
Redim Preserve strTest(lngIndex)
strTest(lngIndex) = Trim$(Application.Clean(vntTmp(123)))
lngIndex = lngIndex + 1
Loop
Close #FF1
'## train.txt erstellen
FF1 = FreeFile
lngIndex = 0
Open strFile For Input As #FF1
FF2 = FreeFile
Open strTmpFile For Output As #FF2
Do While Not EOF(FF1) And lngC  5 Then
vntTmp = Split(strTmp, Chr(9))
strTmp = ""
If UBound(vntTmp) > 1 Then
For lngCol = 2 To UBound(vntTmp)
strTmp = strTmp & Trim$(Application.Clean(vntTmp(lngCol))) & Chr(9)
Next
End If
strTmp = strTmp & strTrain(lngC)
lngC = lngC + 1
Print #FF2, strTmp
End If
Loop
Close #FF2
Close #FF1
Kill strTrainFile
Name strTmpFile As strTrainFile
'## retrain.txt erstellen
FF1 = FreeFile
lngIndex = 0
lngC = 0
Open strFile For Input As #FF1
FF2 = FreeFile
Open strTmpFile For Output As #FF2
Do While Not EOF(FF1) And lngC  5 + UBound(strTrain) Then
vntTmp = Split(strTmp, Chr(9))
strTmp = ""
If UBound(vntTmp) > 1 Then
For lngCol = 2 To UBound(vntTmp)
strTmp = strTmp & Trim$(Application.Clean(vntTmp(lngCol))) & Chr(9)
Next
End If
strTmp = strTmp & strReTrain(lngC)
lngC = lngC + 1
Print #FF2, strTmp
End If
Loop
Close #FF2
Close #FF1
Kill strReTrainFile
Name strTmpFile As strReTrainFile
'## test.txt erstellen
FF1 = FreeFile
lngIndex = 0
lngC = 0
Open strFile For Input As #FF1
FF2 = FreeFile
Open strTmpFile For Output As #FF2
Do While Not EOF(FF1) And lngC  5 + UBound(strTrain) + UBound(strReTrain) + 1 Then
vntTmp = Split(strTmp, Chr(9))
strTmp = ""
If UBound(vntTmp) > 1 Then
For lngCol = 2 To UBound(vntTmp)
strTmp = strTmp & Trim$(Application.Clean(vntTmp(lngCol))) & Chr(9)
Next
End If
strTmp = strTmp & strTest(lngC)
lngC = lngC + 1
Print #FF2, strTmp
End If
Loop
Close #FF2
Close #FF1
Kill strTestFile
Name strTmpFile As strTestFile
End Sub

2
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Benutzer
Anzeige
AW: .txt's mit VBA bearbeiten
08.07.2012 22:40:18
Horst
?
AW: .txt's mit VBA bearbeiten
10.07.2012 21:48:10
Horst
Hallo Josef,
wie gebe ich nun im Code an, dass in der train.txt die letzte Zeile gelöscht wird?
Gruß, Horst
Open strFile For Input As #FF1
FF2 = FreeFile
Open strTmpFile For Output As #FF2
Do While Not EOF(FF1) And lngC  5 Then
vntTmp = Split(strTmp, Chr(9))
strTmp = ""
If UBound(vntTmp) > 1 Then
For lngCol = 2 To UBound(vntTmp)
strTmp = strTmp & Trim$(Application.Clean(vntTmp(lngCol))) & Chr(9)
Next
End If
strTmp = strTmp & strTrain(lngC)
lngC = lngC + 1
Print #FF2, strTmp
End If
Loop
Close #FF2
Close #FF1

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige