C# Searching Through Different Groups of RichTextBoxes and Posting Them on CSV File -


building on information got last night, have 3 different groups of existing richtextboxes (meaning painted on form) called cbox#, vbox# , tbox# (the # indicates numerical value ranging 1 n cbox1, cbox2, etc). cbox# , tbox# changes changes color white red or green while 'vbox#' contains kind of string (like 5.0 v).

i set dummy data values , essentially, trying scan through current results , post them on excel file (in case, csv file).

  using (var file = new streamwriter("c:\\test\\" + datetime.now.tostring("yyyymmddhhmmssfff") + ".csv"))         {             file.write("com stat,");             file.write("trip stat,");             file.writeline("voltage");              string comread = null;             string tripread = null;             string voltread = null;              cbox1.backcolor = color.green;             cbox2.backcolor = color.green;             cbox3.backcolor = color.red;             cbox4.backcolor = color.green;             cbox5.backcolor = color.green;             cbox6.backcolor = color.green;             cbox7.backcolor = color.green;             cbox8.backcolor = color.red;             cbox9.backcolor = color.green;             cbox10.backcolor = color.green;              tbox1.backcolor = color.red;             tbox2.backcolor = color.green;             tbox3.backcolor = color.green;             tbox4.backcolor = color.green;             tbox5.backcolor = color.green;             tbox6.backcolor = color.green;             tbox7.backcolor = color.green;             tbox8.backcolor = color.green;             tbox9.backcolor = color.red;             tbox10.backcolor = color.green;              vbox1.text = "10.0 v";             vbox2.text = "5.0 v";             vbox3.text = "---";             vbox4.text = "5.0 v";             vbox5.text = "3.0 v";             vbox6.text = "5.0 v";             vbox7.text = "5.0 v";             vbox8.text = "---";             vbox9.text = "0.0 v";             vbox10.text = "5.0 v";               (int = 1; < 11; i++)             {                 foreach (var richbox in this.controls.oftype<richtextbox>())                 {                     if ((richbox.name.startswith("cbox" + i)) && (richbox.backcolor == color.green))                     {                         comread = "true";                     }                     else                     {                         comread = "false";                     }                      file.write(comread + ",");                      if ((richbox.name.startswith("tbox" + i)) && (richbox.backcolor == color.green))                     {                         tripread = "true";                     }                     else                     {                         tripread = "false";                     }                      file.write(tripread + ",");                      if (richbox.name.startswith("vbox" + i))                     {                         voltread = richbox.text;                     }                      file.writeline(voltread);                 }         }              file.close();              messagebox.show("demo complete");         } 

obviously, doesn't work scan through each 1 individually , making should have been 11 lines on excel file 301 lines.

the obvious question did wrong? want know if there simpler way of doing loop made @ end.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo