Autor Beitrag
Scofield2011
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 55

Windows XP, Windows 7, Windows 8
C#, VBA, VB
BeitragVerfasst: Mo 27.06.11 15:03 
Hallo Leute,

ich habe eine Methode geschrieben, die Daten zeilenweise aus einer Text Datei einlesen soll. Das Einlesen klappt auch, aber aus einem mir nicht ersichtlichen Grund wird nur jede zweite Zeile eingelesen. Beginnen tut er dabei mit der zweiten Zeile in der Text Datei. Ich bin sicher das kann nur eine Kleinigkeit im Code sein, aber leider sehe ich es nicht. Es wäre also nett wenn ihr mal einen kurzen Blick auf den folgenden Code werfen könntet.

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
            int counter = 0;
            string sLine = "";
            StreamReader sr = new
            StreamReader(@Global.Path + "abc.txt", System.Text.Encoding.Default, true);
            richTextBox1.Multiline = true;
           
            while (sLine != null)
            {
                sLine = sr.ReadLine();
                if (sLine != null)
                {
                    Global.Names[counter] = sr.ReadLine();
                    counter++;
                }
            }
            sr.Close();


Vielen Dank schon einmal im Voraus.

Scofield2011

Moderiert von user profile iconChristian S.: C#-Tags hinzugefügt
Ralf Jansen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 4708
Erhaltene Danke: 991


VS2010 Pro, VS2012 Pro, VS2013 Pro, VS2015 Pro, Delphi 7 Pro
BeitragVerfasst: Mo 27.06.11 15:39 
Du willst Global.Names[counter] sicherlich sLine zuweisen, so wie jetzt hast du ein 2.tes ReadLine() in der Schleife und das was ursprünglich in sLine eingelesen wurde wird ignoriert und landet nie in deiner Global.Names Liste.
Scofield2011 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 55

Windows XP, Windows 7, Windows 8
C#, VBA, VB
BeitragVerfasst: Mo 27.06.11 16:53 
Danke noch einmal.

Wie konnte ich das nur übersehen.