Click here to Skip to main content
16,004,507 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
This is my code
C#
  //split the action in to lines
  StreamReader sr = new StreamReader("C:\\Users/Kyle/Desktop/jhkhj/Year11-ActionElectivites.txt");
  String line = sr.ReadToEnd();
  string[] split = line.Split(',');

int ReadAllActionLines = 0;
  while (ReadAllActionLines <= split.Length)
  {
      ActionListBox.Items.Add(split[ReadAllActionLines]);
      ReadAllActionLines = ReadAllActionLines + 1;
  }
  sr.Close();

  //split the survice in to lines
  StreamReader sr2 = new StreamReader("C:\\Users/Kyle/Desktop/jhkhj/Year11-SurviceElectivites.txt");
  String line2 = sr2.ReadToEnd();
  string[] split2 = line2.Split(',');

  int ReadAllActionLines2 = 0;
  while (ReadAllActionLines2 <= split2.Length)
  {
      SurviceListBox.Items.Add(split2[ReadAllActionLines2]);
      ReadAllActionLines2 = ReadAllActionLines2 + 1;
  }
  sr2.Close();


for some reason the code stops at

sr.Close();

but i dunno why, it should be keep going! after it has read sr it sould read sr2 but it dosen't can some one please help i don't understand why its not reading sr2
Posted

It does not stop. There is most likely an exception in your code.
Put this code in a try-catch block and then check the error.
 
Share this answer
 
Comments
[no name] 25-Mar-13 5:15am    
i don't know how to do that
Abhinav S 25-Mar-13 5:28am    
I guess you need to start by reading a book on C#. It will help you learn some fundamentals.
Maciej Los 25-Mar-13 5:26am    
+5
Abhinav S 25-Mar-13 5:28am    
Thank you.
Please use try catch block like below and get the exact exception :-
C#
try
{
            //split the action in to lines
            StreamReader sr = new StreamReader("C:\\Users/Kyle/Desktop/jhkhj/Year11-ActionElectivites.txt");
            String line = sr.ReadToEnd();
            string[] split = line.Split(',');
 
          int ReadAllActionLines = 0;
            while (ReadAllActionLines <= split.Length)
            {
                ActionListBox.Items.Add(split[ReadAllActionLines]);
                ReadAllActionLines = ReadAllActionLines + 1;
            }
            sr.Close();
 
            //split the survice in to lines
            StreamReader sr2 = new StreamReader("C:\\Users/Kyle/Desktop/jhkhj/Year11-SurviceElectivites.txt");
            String line2 = sr2.ReadToEnd();
            string[] split2 = line2.Split(',');
 
            int ReadAllActionLines2 = 0;
            while (ReadAllActionLines2 <= split2.Length)
            {
                SurviceListBox.Items.Add(split2[ReadAllActionLines2]);
                ReadAllActionLines2 = ReadAllActionLines2 + 1;
            }
            sr2.Close();
}

catch(Exception ex)
{
  Messagebox.Show(ex.stacktrace);
}
 
Share this answer
 
v2
Comments
[no name] 25-Mar-13 5:22am    
thanks, i know what the problem is, its

ActionListBox.Items.Add(split[ReadAllActionLines]);
Rohit Kumar Mumbai 25-Mar-13 5:25am    
Cheers :) Seems issue with spli[ReadAllActionLines]..
Maciej Los 25-Mar-13 5:27am    
+5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900