Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Adding element of one array at the end of anothar array

85 views
Skip to first unread message

Marco Boschi

unread,
Jul 18, 2022, 9:50:35 AM7/18/22
to
Hi to all!

Is it possible to add elements of aSoloRic Array after this sequence { "ONE" , "TWO" , "THREE" , "FOUR" , "FIVE" } using a particular syntax?

For every line of aResult Array I Have 5 fixed elements and than other elements but I don't know how many.
aSoloRic could contain from zero to n elements


otherwise I Create a little function to goal



FUNCTION MAIN()

LOCAL aSoloRic1 := {}
LOCAL aResult := {}

aSoloRic1 := { "0001" , "0002" , "0003" , "0004" }

AADD( aResult , { "ONE" , "TWO" , "THREE" , "FOUR" , "FIVE" , aSoloRic1 } )

RETURN NIL

Ariel Paredes

unread,
Jul 20, 2022, 9:06:31 AM7/20/22
to
Hi
try Hash

// The example creates an associative array and deletes
// the third key/value pair.
PROCEDURE Main
LOCAL hArray := Hash()
HSetAACompatibility( hArray, .T. )
hArray[ "One" ] := 10
hArray[ "Two" ] := 20
hArray[ "Three"] := 30
hArray[ "Four" ] := 40
hArray[ "Five" ] := 50
? hArray[ 3 ] // result: 30
? hArray["Four"] // result: 40
HaaDelAt( hArray, 3 )
? hArray[ 3 ] // result: 40
? hArray["Four"] // result: 40
RETURN

Dan

unread,
Jul 20, 2022, 10:05:10 AM7/20/22
to
LOCAL aSoloRic1 := { "0001" , "0002" , "0003" , "0004" }
LOCAL aResult := {}
AADD( aResult , { "ONE" , "TWO" , "THREE" , "FOUR" , "FIVE"})

// aResult={{ "ONE" , "TWO" , "THREE" , "FOUR" , "FIVE"}}
// aresult[1] is the first element of array aResult and it is an array
itself. It is NOT aResult={ "ONE" , "TWO" , "THREE" , "FOUR" , "FIVE"}

aeval(aSoloRic1,{|x|aadd(aResult[1],x)})

// we added elements to the sub-array
// aResult={{ "ONE" , "TWO" , "THREE" , "FOUR" , "FIVE", "0001" ,
"0002" , "0003" , "0004" }}
// Otherwise you obtain:
// aResult={{ "ONE" , "TWO" , "THREE" , "FOUR" , "FIVE"},{"0001" ,
"0002" , "0003" , "0004" }}

HTH
Dan

Marco Boschi

unread,
Jul 21, 2022, 3:44:26 AM7/21/22
to
Many thanks to all!
0 new messages