This project has moved and is read-only. For the latest updates, please go here.

Issue with LoopContainer and segment

Sep 18, 2012 at 10:33 PM

I'm using version 2.3.0.0 and have the following procedure to copy loops and segments from one container to another:

        private void CopySegmentAndLoops(LoopContainer inputContainer, LoopContainer outputContainer, bool copyChildLoops)
        {
            int inputSegmentCount = inputContainer.Segments.Count();
            for (int i = 0; i < inputSegmentCount; i++)
                outputContainer.AddSegment(inputContainer.Segments.ElementAt(i).SegmentString);

            int inputLoopCount = inputContainer.Loops.Count();
            for (int i = 0; i < inputLoopCount; i++)
            {
                try
                {
                    outputContainer.AddLoop(inputContainer.Loops.ElementAt(i).SegmentString);
                    if (copyChildLoops == true)
                        CopySegmentAndLoops(inputContainer.Loops.ElementAt(i), outputContainer.Loops.ElementAt(i), true);
                }
                catch (Exception err)
                {
                    Debug.WriteLine(err.Message);
                }
            }
        }

There seem to be an issue where at times the AddSegment and AddLoop methods don't actually add anything and don't throw an error.  The output container seems to be initialized and the input container has 3 segments and 2 loops.  However, under some undetermined situation the output container object doesn't seem to have anything in it after calling the respective add method.  I've run this over several loops and it seems to work most of the time.  The reason I found this is that I get and exception when I call outputContainer.Loop.ElementAt(i).  It throws and index out of range (count of output container is 0).

I got this code from http://x12parser.codeplex.com/discussions/355921 by alder 8.