Yes, it's something like that what I did too.
And I don't have any counter limit or limit to the codes in my file. I just load all the lines into a variable in memory and count how many lines were loaded and work with that counter just to control when I'm in the last register. That's all!
I thought myself that it would be harder but it wasn't after all!
Thanks
Psy