Ted, I woke up this morning with a much more elegant solution to your problem. It occurs to me that the Qsequence field in your record becomes redundant once it has been sorted, so you could actually do away with it. (i.e., Qsequence(22) will always be 22) This also eliminates the sort%(50) array. Try this code for inputting your data and you should find everything right where you want it, so you can write it out from top to bottom! I suspect this is what you intended in the beginning. dim index% do line input #2,aa$ // allow space, ; or * to start a comment line; also allows blank lines long if aa[0] <> 0 and aa[1] <> _" " and aa[1] <> _";" and aa[1] <> _"*" ia=1 while (aa$[ia]<>9) inc(ia) wend index = val&(mid$(aa,ia+1)) //QCalsteps.Qsequence(index) = index 'This is possible, but redundant Qcalsteps.Qtablegrade(index) = LEFT$(aa$,ia-1) ia ++ while (aa$[ia]<> 9) inc(ia) wend Qcalsteps.Qkitgrade(index) = mid$(aa,ia+1) lastqgrade ++ end if until eof(2) ' To write, just use your old code... for ib = 0 to lastqgrade print #openfile%,ib;_ctab$; next print #openfile,"" for ib = 0 to lastqgrade print #openfile%,QCalsteps.Qtablegrade(ib);_ctab$; next print #openfile,"" for ib = 0 to lastqgrade print #openfile%,QCalsteps.Qkitgrade(ib);_ctab$; next print #openfile,"" //This section probably unnecessary--it's redundant //for ib = 0 to lastqgrade //print #openfile%,ib;_ctab$; //next //print #openfile,"" e-e =J= a y "