Create Cursor test (chk l) Rand(-1) For icx=1 To 65000 Insert Into test Values (Int(Rand()*1000)%2=0) Endfor Select chk From test Into Array aChecks Local ln1, ln2, lnLen, ix, llState, ; lnLenCatch, lnLenMiss, lcCatch, lcMiss, ; lnHandleCatch,lnHandleMiss,lcCatchStr,lcMissStr lnLen = Alen(aChecks) Store '' To m.lcCatchStr,m.lcMissStr * Get padding lengths llState = aChecks[m.lnLen] && Get state of last element ln1 = Floor(Log10(m.lnLen)) + 1 && Set padding length for 1st state If Ascan(aChecks,!m.llState) = 0 && If other state does not exist cut here Store Padl(1,m.ln1,'0')+'-'+Padl(m.lnLen,m.ln1,'0') ; to ( Iif(m.llState,'m.lcCatchStr','m.lcMissStr') ) Else For ix=m.lnLen To 1 Step -1 If aChecks[m.ix] = !m.llState && Found other max ln2 = Floor(Log10(m.ix)) + 1 && Set padding length for 2nd state Exit Endif Endfor lnLenCatch = Iif(m.llState, m.ln1, m.ln2) && Padding lenghts lnLenMiss = Iif(m.llState, m.ln2, m.ln1) * Generate lists * Handling with lowlevel file is faster than string concat lcCatch = Sys(2015)+'.tmp' lcMiss = Sys(2015)+'.tmp' lnHandleCatch = Fcreate(m.lcCatch) lnHandleMiss = Fcreate(m.lcMiss) For ix=1 To m.lnLen llState = aChecks[m.ix] && Get state ln2 = Ascan(aChecks,!m.llState,m.ix) && Get end If ln2 = 0 && Same to end of list ln2 = m.lnLen + 1 Endif * Get handle for this state lnHandle = Iif(m.llState, m.lnHandleCatch, m.lnHandleMiss) * Write this block Fwrite(m.lnHandle,Iif(Fseek(m.lnHandle,0,1)=0,'',',')+; Padl(m.ix,Iif(m.llState,m.lnLenCatch,m.lnLenMiss),'0')) If m.ix < m.ln2-1 Fwrite(m.lnHandle,; '-'+Padl(m.ln2-1,Iif(m.llState,m.lnLenCatch,m.lnLenMiss),'0')) Endif * Adjust ix to new block start ix = m.ln2-1 Endfor Fclose(m.lnHandleCatch) Fclose(m.lnHandleMiss) lcCatchStr = Filetostr(m.lcCatch) lcMissStr = Filetostr(m.lcMiss) Erase (m.lcCatch) Erase (m.lcMiss) Endif Strtofile('Catch :'+Chr(13)+m.lcCatchStr,'output.txt') Strtofile(Chr(13)+'Miss :'+Chr(13)+m.lcMissStr,'output.txt',.T.) Modify Command Output.txtCetin