title: Read Richtextbox first line when true then next line when false in every tick
body: <p><a href="https://i.stack.imgur.com/EaTlw.png" rel="nofollow noreferrer">enter image description here</a></p>
  
  <p>This is what I am aiming to do. In everytime the clock ticks, and i get some errors
  Well this is my codes so far.</p>
  
  <pre><code> private void timer1_Tick(object sender, EventArgs e)
      {
          //get current time
          int hh = DateTime.Now.Hour;
          int mm = DateTime.Now.Minute;
          int ss = DateTime.Now.Second;
          int ms = DateTime.Now.Millisecond;
          //time
          string time = "";
          //padding leading zero
          if (hh &lt; 10)
          { time += hh; }
          else
          {
  
              if (hh &gt;= 12)
              {
                  int h = hh - 12;
                  if (h == 0)
                  {
  
                      time += 12;
                  }
                  else
                  {
                      time += h;
                  }
  
              }
              else { time += hh; }
  
  
          }
  
          time += ":";
          if (mm &lt; 10)
          { time += "0" + mm; }
          else
          { time += mm; }
          time += ":";
          if (ss &lt; 10)
          { time += "0" + ss; }
          else
          { time += ss; }
          //update Ltime label
          string[] ports = SerialPort.GetPortNames();
  
          // SerialPort.GetPortNames() returns multiple strings in an array, not just one string.
  
          //You need to go through each item in the array, and run your Contains() and Add() for each item.
          foreach (var p in ports) // Go through each string in the array
          {
              if (!comboBox1.Items.Contains(p))
                  comboBox1.Items.Add(p);
          }
  
  
          if (hh &lt; 12)
          { Ltime.Text = time + "am"; }
          else { Ltime.Text = time + "pm"; }
  
          int count = sched1.Lines.Count();//isulod sa var count kung pila ka line unod ni sched1.Text
          if (count == i)
          {
              display2.Text = "No Available Schedule";
          }
          else
          {
              /////reading the schedules
              for (int x = 0; x &lt; count; x++)
              {
  
                  if (string.IsNullOrWhiteSpace(sched1.Lines[x+1]))
                  {
                      display2.Text = "Empty";
                  }
                  /////okay ni/
                  else
                  {
  
                      if (sched1.Lines[x+1] == (DateTime.Now.DayOfWeek.ToString()))
                      {
                          if (string.IsNullOrWhiteSpace(sched2.Text))
                          {
                              display2.Text = "Empty";
                          }
                          ///okay mn
                          else
                          {
                              int count2 = sched2.Lines.Count();
                              if (count2 == i)
                              {
                                  display2.Text = "No Available Schedule";
                              }
                              else
                              {
                                  for (int y = 0; x &lt; count2; y++)
                                      if (sched2.Lines[y+1].Equals(Ltime.Text))
                                      {
  
  
                                          serialPort1.Write("1");
  
                                          try
                                          {
                                              display2.Text = serialPort1.ReadExisting();
  
  
                                          }
                                          catch (TimeoutException)
                                          {
                                              display2.Text = "Timeout Exception";
                                          }
                                      }
                              }
                          }
                      }
                      else { display2.Text = "Empty"; }
                      //ok mn
                  }
              }
          }
  
          }
    But it display  "Index was outside the bounds of the array." in 
  </code></pre>
  
  <p>if (string.IsNullOrWhiteSpace(sched1.Lines[x+1])) I don't know what would be the problem.</p>