Copying and Pasting cs Code

In cs, like in almost any computer programming language, reading data from a file can be tricky. You add extra lines of code to tell the computer what to do. Sometimes you can copy and paste these lines from other peoples’ code.

For example, you can follow the pattern in this listing:

   public frmEnrollment()
   {
    InitializeComponent();

    face = new HaarCascade("haarcascade_frontalface_alt_tree.xml");
             eye = new HaarCascade("haarcascade_eye.xml");
             try
             {
                 string Labelsinfo = File.ReadAllText(Application.StartupPath + "/TrainedFaces/TrainedLabels.txt");
                 string[] Labels = Labelsinfo.Split('%');
                 NumLabels = Convert.ToInt16(Labels[0]);
                 ContTrain = NumLabels;
                 string LoadFaces;

                 for (int tf = 1; tf < NumLabels+1; tf++)
                 {
                     LoadFaces = "face" + tf + ".bmp";
                     trainingImages.Add(new Image(Application.StartupPath + "/TrainedFaces/" + LoadFaces));
                     labels.Add(Labels[tf]);
                 }

             }
             catch(Exception e)
             {
                 MessageBox.Show("Nothing in binary database, please add at least a face", "Triained faces load", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             }

   }