to puzzle: #for and successors | Uniface 9 | Forum

Avatar

Please consider registering
guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

—  Results per page  —








— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters
For a group of consecutive words like 'end of support' use Match phrase

sp_Feed Topic RSS sp_TopicIcon
to puzzle: #for and successors
26 Apr 2018
3:14 pm
Avatar
istiller
Member
Forum Posts: 295
Member Since:
01 Oct 2012
sp_UserOfflineSmall Offline

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

26 Apr 2018
5:51 pm
Avatar
Knut
Member
Forum Posts: 224
Member Since:
01 Oct 2012
sp_UserOfflineSmall Offline

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

27 Apr 2018
11:09 am
Avatar
Iain Sharp
Member
Forum Posts: 674
Member Since:
01 Oct 2012
sp_UserOfflineSmall Offline

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. 

27 Apr 2018
2:10 pm
Avatar
Gilles
Member
Forum Posts: 40
Member Since:
01 Oct 2012
sp_UserOfflineSmall Offline

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.

30 Apr 2018
8:54 am
Avatar
ulrich-merkel
Frankfurt/Germany
Member
Forum Posts: 1868
Member Since:
01 Oct 2012
sp_UserOfflineSmall Offline

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, ….

02 May 2018
11:52 am
Avatar
Lauterbach
Member
Forum Posts: 51
Member Since:
06 Dec 2012
sp_UserOfflineSmall Offline

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

02 May 2018
12:01 pm
Avatar
Iain Sharp
Member
Forum Posts: 674
Member Since:
01 Oct 2012
sp_UserOfflineSmall Offline

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. 

02 May 2018
7:05 pm
Avatar
Henk van der Veer
Member
Forum Posts: 54
Member Since:
01 Oct 2012
sp_UserOfflineSmall Offline
Forum Timezone: Europe/Amsterdam

Most Users Ever Online: 131

Currently Online:
29 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

ulrich-merkel: 1868

Iain Sharp: 674

Theo Neeskens: 366

gianni: 341

Adrian Gosbell: 318

istiller: 295

rogerw: 270

Knut: 224

lalitpct: 197

Arjen van Vliet: 184

Member Stats:

Guest Posters: 3

Members: 10299

Moderators: 0

Admins: 6

Forum Stats:

Groups: 1

Forums: 62

Topics: 2290

Posts: 9937

Newest Members:

Ridgesn, SaphbamE, NanarrjLews, bruceus18, LesleyCag, rebeccavy1, jackieps69, GalenIcew, Gessonv, Tommycoado

Administrators: admin: 23, diseli: 1024, Nico Peereboom: 84, richiet: 406, Mike Taylor: 35, JanCees: 38