Hi eierlein,
danke für deine Hilfe, jetzt klappt das auch mit den ä,ü und ö´s
Da jetzt meine Wochenendaufgabe geschafft ist, kann ich noch a bisschen damit rumspielen.
Hab mir jetzt noch ausn Web ein Stück Code gesucht damit ich die Zeilenanzahl bestimmen kann gesucht.
Würde noch gerne eine Progressbar einbauen, damit man sieht wie Weit das Programm mit dem Schreiben ist.
Hier mal das ganze:
Public Class Form1
Dim pfad
Dim Lines As String
Dim LineCount As Integer
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles _
Button2.Click
OpenFileDialog1.Filter = "txt Dateien (*.txt)| *.txt"
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
TextBox1.Text = OpenFileDialog1.FileName
pfad = System.IO.Path.GetDirectoryName(OpenFileDialog1.FileName) & _
"\Ausgepackt\"
If Not IO.Directory.Exists(pfad) Then
IO.Directory.CreateDirectory(pfad)
TextBox2.Text = pfad
Else
IO.Directory.CreateDirectory(pfad)
TextBox2.Text = pfad
End If
Dim Lines As String() = My.Computer.FileSystem.ReadAllText( _
TextBox1.Text, System.Text.Encoding.Default).Split(vbCr)
Dim LineCount As Integer = Lines.Length
Label3.Text = LineCount & "Zeilen"
End If
End Sub
Private Sub SplitFile()
Dim lines As New List(Of String), line As String = ""
Dim outpath As String = pfad, outfile As String = "" 'Zielpfad
Using sr As New IO.StreamReader(OpenFileDialog1.FileName, _
System.Text.Encoding.Default) 'Datendatei
While Not sr.EndOfStream
line = sr.ReadLine
lines.Add(line)
If line.StartsWith("PG_BEZEICHNUNG".ToUpper) Then
Dim filename As String = line.Substring(line.IndexOf("=") + _
1) '& ".txt"
filename = filename.Replace("..", " ")
filename = filename.Replace("/", "&")
filename = filename & ".txt"
outfile = IO.Path.Combine(outpath, filename)
End If
If Not outfile = "" Then
If line.StartsWith("[HAUPTPROGRAMM]".ToUpper) Then
IO.File.WriteAllLines(outfile, lines)
'lines.Clear()
outfile = ""
End If
End If
End While
End Using
If Not lines.Count = 0 And Not outfile = "" Then
IO.File.WriteAllLines(outfile, lines, System.Text.Encoding.Default)
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles _
Button1.Click
SplitFile()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ComboBox1.SelectedIndex = 0
End Sub
Public Function FileLineCount(ByVal Filename As String) As Integer
Dim Lines As Integer = 0
Using oStream As New IO.FileStream(Filename, IO.FileMode.Open, _
IO.FileAccess.Read)
' Blockgröße
Dim BlockSize As Integer = 16384
Dim Bytes(BlockSize) As Byte
Dim ReadSize As Integer
Dim StartIndex As Integer
' Datei blockweise auslesen, bis Dateiende erreicht
Do
ReadSize = oStream.Read(Bytes, 0, BlockSize)
' Anzahl Zeilenumbruchzeichen ermitteln
StartIndex = -1
Do
StartIndex = Array.IndexOf(Bytes, CByte(13), StartIndex + _
1, ReadSize - StartIndex)
If StartIndex >= 0 Then Lines += 1
Loop Until StartIndex < 0
Loop Until ReadSize = 0
oStream.Close()
End Using
Return Lines
End Function
End Class Wie bzw wo müsste ich bei der Progressbar erhöhen damit er mitzählt ?
Könnte ich LineCount verwendun um die 100 Prozent zu bestimmen ?
Leider ist in youtube nur ein Beispiel der mit einen Timer arbeitet, das ist für mich wohl unbrauchbar.
Morgen werden Bücher gekauft ....
Gruß |