to puzzle: #for and successors

Author: i2stiller@gmx.de (istiller)

Hi freaks I want to shift a few databases field by one position like this: FOR v_I = 9 TO 1 STEP -1   @"FLD_%%(v_ID+1)%%%.TBL" = @"FLD_%%v_ID%%%.TBL" ENDFOR Then I thought, hmmm what about a #for instead of FOR, as the number of fields is known a compile time #for c_I = (9,8,7,6,5,4,3,2,1)   FLD_<C_I+1>.TBL = FLD_<C_I>.TBL #endfor And you, as an expert, see the problem :-) How to solve this? I got a solution, but with drawbacks With that one, you could also write all assignments line by line without a #for  Don't show you my solution not to influence your brain on look out for a general one :-) Ingo

7 Comments

  1. That's sneaky.  But I think it's busted.  If we make the list 9,8,7,6,5,4,3,2,1  we get  FLD_8 = FLD_9 FLD_7 = FLD_8 and so on. Which is moving the data the wrong way.  Change the line to  FLD_<FELD>.DUMMY = FLD_<C_1>.DUMMY  and we get.  FLD_9.dummy = FLD_8.dummy through to  FLD_2.dummy = FLD_1.dummy So that should work. 


    Author: Iain Sharp (i.sharp@pcisystems.co.uk)

  2. Author: Henk van der Veer (henk.van.der.veer@uniface.com)
  3. Hi Ingo,   how about this simple one:   #for c_I = (A,B,C,D,E,F,G,H,I) #IFDEFINED FELD FLD_<C_I>.DUMMY = FLD_<FELD>.DUMMY #ENDIF #define FELD = <C_I> #endfor #undefine FELD   kind regards Norbert


    Author: Lauterbach (norbert.lauterbach@infraserv.com)
  4. Ingo, Store this as a txt string in a config table and retrieve to a variable vs_string = "fld_10.tbl=%%fld_9.tbl,fld_9.tbl=%%fld_8.tbl,fld_8.tbl=%%fld_7.tbl, etc etc etc" vs_string = $replace($expression("%%"%%vs_string%%""), 1, ",", "gold separator", -1) getlistitems/id/field vs_string Done


    Author: Knut (knut.dybendahl@gmail.com)
  5. In a similar vein but without the config table

    forlist v_item in "fld_9=fld_8;fld_8=fld_7;...." @$idpart(v_item)=@$valuepart(v_item) endfor
     

      However, that still doesn't give you the one advantage of the #for statement, compile time warnings of missing fields. 


    Author: Iain Sharp (i.sharp@pcisystems.co.uk)
  6. Hi, a bad workaroundEmbarassed: #for c_1 = (9,8,7,6,5,4,3,2,1),counter #for c_2 = (8,7,6,5,4,3,2,1,0),counter2 #if (<counter>=<counter2>) FLD_<c_1>.TBL = FLD_<c_2>.TBL #endif #endfor #endfor bad because .... generate comment if( counter!=counter2) : [ 4] #for c_1 = (9,8,7,6,5,4,3,2,1),counter [ 5] #for c_2 = (8,7,6,5,4,3,2,1,0),counter2 [ 6] #if (0=0) [ 7] 1 FLD_9.TBL = FLD_8.TBL ------------> OK [ 8] #endif [ 9] #endfor [ 6] #if (0=1) [ 7] ; FLD_9.TBL = FLD_7.TBL  -----------> KO but right ? [ 8] #endif [ 9] #endfor [ 6] #if (0=2) [ 7] ; FLD_9.TBL = FLD_6.TBL [ 8] #endif [ 9] #endfor [ 6] #if (0=3) [ 7] ; FLD_9.TBL = FLD_5.TBL [ 8] #endif [ 9] #endfor [ 6] #if (0=4) [ 7] ; FLD_9.TBL = FLD_4.TBL [ 8] #endif [ 9] #endfor ....   Gilles.


    Author: Gilles (gls.tools@free.fr)
  7. Hi Gilles, see my request on the wishlist dated 20090709 at https://unifaceinfo.com/some-precompiler-directives/ Someone messed up the layout of the description, but the very fist line demanded a

    #forpair v_id, v_value = (test=12,ab=33), v_count

    and the usecase mentioned reads as:

    for a clearer to handle directives. You see directly the pair and do not have 2 lists where you have to take care the positions are kept (current way to handle pairs)

      But as it wastes only some compiletime to generate and skip these KO lines, ....


    Author: ulrich-merkel (ulrichmerkel@web.de)