Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
For-loop handling on String and Array..
Message
De
02/01/2004 23:08:01
 
 
À
02/01/2004 06:54:50
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00863386
Message ID:
00863602
Vues:
9
>>My Mind is Nested... ~>_<~
>>
>>The Coding below work right on:
>>Pre-Condition: AChecks(9999) is an Array carry simple .T. or .F.
>>Post-Condition: CTNLIST show out the Simplest form on number list, Carry the Carton# of used.
>>
>>How to make another CTNMISS carry the .F. List, which mean missing Carton#
>>
>>For example,
>>
>>ITEM# CTN_NOS
>>A111 003,005-008
>>B222 004,007-012
>>C333 014,016,020-030
>>
>>Result:
>>CTNLIST: 003-014,016,020-030
>>[b]How to modify the below coding to give this Expected CTNMISS:
>>013,015,017-019[/b]
>>
>>Another String Carry Duplicate Carton# is simply done as similiar copy of below For-loop.
>>
>>I have tried a whole day on adding new code, but still fail of my expect result...
>>Thus, post the correct starting code for you on helping me...
>>
>>Thank you.
>>
>With expected list and code it's unclear what you're after. Hope something like this :
>
>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.txt
>
Cetin

Thanks, Cetin.
I wonder I made my coding too complex to handle..
The most important thing is I revise the order of For-loop..
The reason is to getting last .T. element on carry PADL len.

Another to learn, maybe I am too lazy.. :P
> * Handling with lowlevel file is faster than string concat
The weak wait for chance, The strong bid for chance,
The clever notch up chance, but The merciful give you chance.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform