du hattest vor knapp nem Monat mal was zum Thema Zeilen auslesen bei einem unbekannten Fehler geposten. Ich hatte ja ein bisschen was rumgemäckelt und dir versprochen meine Ideen einzubauen und mich zu melden.
Nun ja - hiermit will ich dies dann auch endlich mal tun.
Erstmal mein Kompliment für die Lösung - ist ne gute Möglichkeit gerade die Fehler zu behandeln, an die man nicht denkt, besonders wenn eine Anwendung von anderen Leuten genutzt wird.
Ich habe an deiner Prozedur "AddLn ()" ein bisschen was verändert.
- deine Eingangsprüfung habe ich bei mir auf den Start eines Moduls bezogen, nicht auf das Ende, aber das ist nur Ansichtssachen - wie man´s halt will
- dann habe ich Mid durch Left ersetzt - ebenfalls nur Kosmetik
- mir ist auch aufgefallen, warum du nicht InStr() verwendet hast - gibt Probleme das z.B. Sub auch in ".Subscript" bei Diagrammen vorkommt, deshalt also Mid (oder halt Left)
Nun aber zu den wesentlichen Anpassungen:
- wie letztens schon gesagt, habe ich noch "Option Explicit" mit aufgenommen
- dann gab´s bei mir immer Sorgen mit dem Zeilenumbruch, dann kam manchmal auch in die folgende Zeile die Zeilennummer, was dann die Anweisung unterbrochen hat - Ergebnis Fehler!
- Ähnliches Problem bei "Select Case", zwischen "Select Case" und dem ersten Case darf keine Zeilennummer stehen - keine Ahnung wieso, aber da kam bei mir immer ne Fehlermeldung.
Das war´s auch schon - du kannst also mit recht stolz auf dich sein ;o)
Ach ja - da hätte ich ja fast meine Geistigen Ergüsse vergessen:
'Nicht registrierte Benutzung der Excel Code Jeanie 1.0 <b><span style="color:#000080"; >Sub</span> AddLN()</b> <span style="color:#000080"; >If</span> pstrDatName <> "" <span style="color:#000080"; >And</span> pstrDatName = pstrNeuDatName <span style="color:#000080"; >Then</span> <span style="color:#000080"; >Exit</span> <span style="color:#000080"; >Sub</span> <span style="color:#000080"; >Dim</span> lstrZeile <span style="color:#000080"; >As</span> <span style="color:#000080"; >String</span>, liZeile <span style="color:#000080"; >As</span> <span style="color:#000080"; >Integer</span>, liSuche <span style="color:#000080"; >As</span> <span style="color:#000080"; >Integer</span>, lboLeer <span style="color:#000080"; >As</span> <span style="color:#000080"; >Boolean</span> <span style="color:#000080"; >Dim</span> li_Zaehler <span style="color:#000080"; >As</span> <span style="color:#000080"; >Integer</span> <span style="color:#000080"; >If</span> pstrDatName = "" <span style="color:#000080"; >Then</span> pstrDatName = Application.GetOpenFilename(<span style="color:#800000"; >"Text Files (*.txt), *.txt"</span>, , pstrUeberschrift) <span style="color:#000080"; >End</span> <span style="color:#000080"; >If</span> <span style="color:#000080"; >If</span> pstrDatName = <span style="color:#800000"; >"Falsch"</span> <span style="color:#000080"; >Then</span> <span style="color:#000080"; >Exit</span> <span style="color:#000080"; >Sub</span> liZeile = 1 lboLeer = <span style="color:#000080"; >True</span> <span style="color:#000080"; >Open</span> pstrDatName <span style="color:#000080"; >For</span> <span style="color:#000080"; >Input</span> <span style="color:#000080"; >As</span> #1 <span style="color:#000080"; >Open</span> pstrVerz & <span style="color:#800000"; >"AddDelLN.txt"</span> <span style="color:#000080"; >For</span> Output <span style="color:#000080"; >As</span> #2 <span style="color:#000080"; >Do</span> <span style="color:#000080"; >While</span> <span style="color:#000080"; >Not</span> EOF(1) Line <span style="color:#000080"; >Input</span> #1, lstrZeile <span style="color:#000080"; >If</span> (InStr(1, lstrZeile, <span style="color:#800000"; >"Sub "</span>) <> 0 <span style="color:#000080"; >Or</span> InStr(1, lstrZeile, <span style="color:#800000"; >"Function "</span>) <> 0) _ <span style="color:#000080"; >And</span> InStr(1, lstrZeile, <span style="color:#800000"; >"End"</span>) = 0 <span style="color:#000080"; >And</span> InStr(1, lstrZeile, <span style="color:#800000"; >"Exit"</span>) = 0 <span style="color:#000080"; >Then</span> <span style="color:#008000"; >'Neue Prozedur/ Funktion startet</span> liZeile = 1 <span style="color:#000080"; >End</span> <span style="color:#000080"; >If</span> <span style="color:#000080"; >If</span> Left(lstrZeile, 15) <> <span style="color:#800000"; >"Option Explicit"</span> <span style="color:#000080"; >And</span> _ Left(lstrZeile, 6) <> <span style="color:#800000"; >"Public"</span> <span style="color:#000080"; >And</span> _ Left(lstrZeile, 3) <> <span style="color:#800000"; >"Dim"</span> <span style="color:#000080"; >And</span> _ Left(lstrZeile, 7) <> <span style="color:#800000"; >"Private"</span> <span style="color:#000080"; >And</span> _ Left(lstrZeile, 8) <> <span style="color:#800000"; >"Function"</span> <span style="color:#000080"; >And</span> _ Left(lstrZeile, 12) <> <span style="color:#800000"; >"End Function"</span> <span style="color:#000080"; >And</span> _ Left(lstrZeile, 3) <> <span style="color:#800000"; >"Sub"</span> <span style="color:#000080"; >And</span> _ Left(lstrZeile, 7) <> <span style="color:#800000"; >"End Sub"</span> <span style="color:#000080"; >And</span> _ Right(lstrZeile, 1) <> <span style="color:#800000"; >":"</span> <span style="color:#000080"; >Then</span> <span style="color:#008000"; >'Left(lstrZeile, 1) <> "'" And</span> <span style="color:#000080"; >For</span> liSuche = 1 <span style="color:#000080"; >To</span> Len(lstrZeile) <span style="color:#000080"; >If</span> <span style="color:#000080"; >Mid</span>(lstrZeile, liSuche, 1) <> <span style="color:#800000"; >" "</span> <span style="color:#000080"; >Then</span> <span style="color:#008000"; >'Zeile ist keine Leerzeile!</span> lboLeer = <span style="color:#000080"; >False</span> <span style="color:#000080"; >Exit</span> <span style="color:#000080"; >For</span> <span style="color:#000080"; >End</span> <span style="color:#000080"; >If</span> <span style="color:#000080"; >Next</span> <span style="color:#000080"; >If</span> lboLeer = <span style="color:#000080"; >True</span> <span style="color:#000080"; >Then</span> <span style="color:#008000"; >'=> Leerzeile, wird einfach nur übernommen!</span> <span style="color:#000080"; >Print</span> #2, lstrZeile <span style="color:#000080"; >Else</span> <span style="color:#000080"; >If</span> li_Zaehler = 0 <span style="color:#000080"; >Then</span> <span style="color:#008000"; >'Bisher kein Zeilenumbruch angefangen</span> <span style="color:#000080"; >If</span> InStr(1, lstrZeile, <span style="color:#800000"; >"'"</span>, vbTextCompare) <> 0 <span style="color:#000080"; >Then</span> <span style="color:#000080"; >If</span> Left(lstrZeile, 1) = <span style="color:#800000"; >"'"</span> <span style="color:#000080"; >Then</span> <span style="color:#008000"; >' => ges. Zeile ist ein Kommentar</span> <span style="color:#000080"; >Print</span> #2, lstrZeile lboLeer = <span style="color:#000080"; >True</span> <span style="color:#000080"; >Else</span> <span style="color:#000080"; >For</span> liSuche = 1 <span style="color:#000080"; >To</span> InStr(1, lstrZeile, <span style="color:#800000"; >"'"</span>, vbTextCompare) - 1 <span style="color:#000080"; >If</span> <span style="color:#000080"; >Mid</span>(lstrZeile, liSuche, 1) <> <span style="color:#800000"; >" "</span> <span style="color:#000080"; >Then</span> <span style="color:#008000"; >' Vor dem "'" stehen noch Zeiche => Zeilennummer kann gesetzt werden</span> <span style="color:#000080"; >Print</span> #2, liZeile & <span style="color:#800000"; >" "</span> & lstrZeile liZeile = liZeile + 1 lboLeer = <span style="color:#000080"; >True</span> <span style="color:#000080"; >Exit</span> <span style="color:#000080"; >For</span> <span style="color:#000080"; >End</span> <span style="color:#000080"; >If</span> <span style="color:#000080"; >Next</span> <span style="color:#000080"; >If</span> lboLeer = <span style="color:#000080"; >False</span> <span style="color:#000080"; >Then</span> <span style="color:#008000"; >'vor dem "'" stehen keine Zeichen mehr (nur Leerzeichen)</span> <span style="color:#000080"; >Print</span> #2, lstrZeile lboLeer = <span style="color:#000080"; >True</span> <span style="color:#000080"; >End</span> <span style="color:#000080"; >If</span> <span style="color:#000080"; >End</span> <span style="color:#000080"; >If</span> <span style="color:#000080"; >If</span> Right(lstrZeile, 2) = <span style="color:#800000"; >" _"</span> <span style="color:#000080"; >Then</span> li_Zaehler = li_Zaehler + 1 <span style="color:#000080"; >Else</span> <span style="color:#008000"; >'Prüfung, auf Select Case - Anwendung, wenn ja - ebenfalls keine Ziffer in der nächsten Zeile</span> <span style="color:#000080"; >If</span> InStr(1, lstrZeile, <span style="color:#800000"; >"Select Case "</span>) <> 0 <span style="color:#000080"; >Then</span> <span style="color:#000080"; >For</span> liSuche = InStr(1, lstrZeile, <span style="color:#800000"; >"Select Case "</span>) - 1 <span style="color:#000080"; >To</span> 1 <span style="color:#000080"; >Step</span> -1 <span style="color:#000080"; >If</span> <span style="color:#000080"; >Mid</span>(lstrZeile, liSuche, 1) <> <span style="color:#800000"; >" "</span> <span style="color:#000080"; >Then</span> <span style="color:#008000"; >'Es gibt noch Zeicher vor Select Case => Nummer kann gesetzt werden</span> <span style="color:#000080"; >Exit</span> <span style="color:#000080"; >For</span> <span style="color:#000080"; >End</span> <span style="color:#000080"; >If</span> <span style="color:#000080"; >Next</span> <span style="color:#000080"; >If</span> liSuche > -1 <span style="color:#000080"; >Then</span> li_Zaehler = li_Zaehler + 1 <span style="color:#000080"; >End</span> <span style="color:#000080"; >If</span> <span style="color:#000080"; >End</span> <span style="color:#000080"; >If</span> <span style="color:#000080"; >End</span> <span style="color:#000080"; >If</span> <span style="color:#000080"; >Else</span> <span style="color:#000080"; >If</span> Right(lstrZeile, 2) = <span style="color:#800000"; >" _"</span> <span style="color:#000080"; >Then</span> li_Zaehler = li_Zaehler + 1 <span style="color:#000080"; >Print</span> #2, liZeile & <span style="color:#800000"; >" "</span> & lstrZeile liZeile = liZeile + 1 lboLeer = <span style="color:#000080"; >True</span> <span style="color:#000080"; >Else</span> <span style="color:#008000"; >'Prüfung, auf Select Case - Anwendung, wenn ja - ebenfalls keine Ziffer in der nächsten Zeile</span> <span style="color:#000080"; >If</span> InStr(1, lstrZeile, <span style="color:#800000"; >"Select Case "</span>) <> 0 <span style="color:#000080"; >Then</span> <span style="color:#000080"; >For</span> liSuche = InStr(1, lstrZeile, <span style="color:#800000"; >"Select Case "</span>) - 1 <span style="color:#000080"; >To</span> 1 <span style="color:#000080"; >Step</span> -1 <span style="color:#000080"; >If</span> <span style="color:#000080"; >Mid</span>(lstrZeile, liSuche, 1) <> <span style="color:#800000"; >" "</span> <span style="color:#000080"; >Then</span> <span style="color:#008000"; >'Es gibt noch Zeicher vor Select Case => Nummer kann gesetzt werden</span> <span style="color:#000080"; >Exit</span> <span style="color:#000080"; >For</span> <span style="color:#000080"; >End</span> <span style="color:#000080"; >If</span> <span style="color:#000080"; >Next</span> <span style="color:#000080"; >If</span> liSuche > -1 <span style="color:#000080"; >Then</span> li_Zaehler = li_Zaehler + 1 <span style="color:#000080"; >End</span> <span style="color:#000080"; >If</span> <span style="color:#000080"; >End</span> <span style="color:#000080"; >If</span> <span style="color:#000080"; >Print</span> #2, liZeile & <span style="color:#800000"; >" "</span> & lstrZeile liZeile = liZeile + 1 lboLeer = <span style="color:#000080"; >True</span> <span style="color:#000080"; >End</span> <span style="color:#000080"; >If</span> <span style="color:#000080"; >End</span> <span style="color:#000080"; >If</span> <span style="color:#000080"; >Else</span> <span style="color:#008000"; >'mindestens in der vorhergehenden Zeile ist ein Zeilenumbruch _ => keine Zeilennummer schreiben, da sonst Fehlermeldung</span> <span style="color:#000080"; >If</span> Right(lstrZeile, 2) = <span style="color:#800000"; >" _"</span> <span style="color:#000080"; >Then</span> li_Zaehler = li_Zaehler + 1 <span style="color:#000080"; >Print</span> #2, lstrZeile lboLeer = <span style="color:#000080"; >True</span> <span style="color:#000080"; >Else</span> li_Zaehler = 0 <span style="color:#000080"; >Print</span> #2, lstrZeile lboLeer = <span style="color:#000080"; >True</span> <span style="color:#000080"; >End</span> <span style="color:#000080"; >If</span> <span style="color:#000080"; >End</span> <span style="color:#000080"; >If</span> <span style="color:#000080"; >End</span> <span style="color:#000080"; >If</span> <span style="color:#000080"; >Else</span> <span style="color:#008000"; >'Zeile enthält eines der Schlüsselwörter</span> <span style="color:#008000"; >'Zeile einfach nur kopieren, ohne Zeilennummer</span> <span style="color:#000080"; >Print</span> #2, lstrZeile <span style="color:#000080"; >End</span> <span style="color:#000080"; >If</span> <span style="color:#000080"; >Loop</span> <span style="color:#000080"; >Close</span> <b><span style="color:#000080"; >End</span> <span style="color:#000080"; >Sub</span></b>
Vielleicht findest du ja noch ein paar andere Änderungen, bis jetzt sind mir jedenfalls noch keine Fehler aufgefallen
Gruss
Chris
PS: Ach ja wie kann ich eigentlich auf den alten Thread verweisen?