views:

33

answers:

2

At the moment I have an ArrayList containing EPL printer commands.

In each command it has a line position.

eg/

myList.Add(string.Format(CultureInfo.InvariantCulture, "A26," + YPos + ,0,4,1,1,N,\"Date Printed : {0}\"", DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss")));

myList.Add(string.Format(CultureInfo.InvariantCulture, "A26," + YPos + ",0,4,1,1,N,\"Test Data : {0}\"", "BOO"));

The YPos variable gets 60 added to it after each entry.

At the end of the arraylist getting populated I work through the collection and at every 23 lines I need to add a new entry with blank data

eg/

sb.Add(string.Format(CultureInfo.InvariantCulture, "A26," + YPos + ",0,4,1,1,N,\"{0}\"", ""));

My problem is the YPos value needs to be in sequence and for all entries after it.

At the moment the entries appear at 23 lines apart but the YPos value is the final YPos value with 60 added to it so although the blank lines are 23 lines apart in my ArrayList they actually get printed on the end as my YPos has the greater values.

I thought about using a List or Dictionary to use the incrementers as key identifiers but I would still have to replace all string entries at the end to the correct value so not sure that is the greatest approach.

A: 

The easiest thing would be to add the blank lines during the populating of the arraylist. Increment a counter with each line, and whenever ++count % 23 == 0, bump YPos and add a blank line. Then your YPos would of course be in sequence. Can you do that?

LarsH
A: 

Why can't you do if ((YPos/60) % 23 == 0) {addBlankLine;} ? . I would consider replacing both 60 and 23 with constants defined elsewhere, if you did it this way (and using the same constant to add 60 to YPos between lines).

Brian