Initialize multiple elements of an array

I have a Group that is a two dimensional array:

  ArGrp  Group,Dim(60)
  Arg      Long,Dim(4)
         END  !Group

What is the correct syntax to assign values to all four elements of Arg in one statement?
Something like ArGrp[1] = 1,2,3,4 (…which does not work.)

Great thanks in advance.

Maybe the help for “Deep Assignment” would help. Not the greatest, but maybe you’d come up with something that works.
Or maybe put a STRING,OVER your 4 LONGs (by &reference or declaration) then assign like
MyString = ‘<0,0,0,1,0,0,0,2,0,0,0,3,0,0,0,4>’.

Kinda code smelly, but it works.

But you would have to put the bytes in the correct order. Looks like I got it wrong, now that I look again.

Needs to be ‘<1,0,0,0,2,0,0,0,3,0,0,0,4,0,0,0>’

1 Like

My Group is a 60-element array of 4-element arrays of single digit integers. It would be nice to assign each of the 60 group elements a different 4-element array with a single line. That is 60 lines vs. 240 lines if each of the four elements must be done individually.
Modifying Jeff’s suggestion, I find that ArGrp[1].Arg[1:4] = ‘1234’ works; but it still leaves a problem with negative integers: ArGrp[2].Arg[1:4] = ‘123-4’ is a FIVE-member string.

Two thoughts occur: 1) It’s hard to believe this cannot be done easily. It seems to be easy in C++ : int array [ ] = {1,3,34,5,6}
2) I find the context help woefully poor in fine details on many issues.

Negatives are (0FFFFFFFFh - x+1), so -4 should be 0FFFFFFFCh.

I would create a little Procedure so it can be done in 1 line:

  MAP
ArGrp_Assign PROCEDURE(USHORT GrpRow, LONG Arg1, LONG Arg2, LONG Arg3, LONG Arg4)
  END
  CODE
  ArGrp_Assign(1, 1,2,3,4) 
  ArGrp_Assign(2, 5,6,7,8) 
  ArGrp_Assign(3, 9,10,11,12) 
...
  ArGrp_Assign(60, 65,66,67,68) 
  
ArGrp_Assign PROCEDURE(USHORT GrpRow, LONG Arg1, LONG Arg2, LONG Arg3, LONG Arg4)
    CODE
    ArGrp[GrpRow].Arg[1]=Arg1
    ArGrp[GrpRow].Arg[2]=Arg2
    ArGrp[GrpRow].Arg[3]=Arg3
    ArGrp[GrpRow].Arg[4]=Arg4
    RETURN 

Alternative is to make it a CLASS. You will probably have other procedures for this big array:

ArGrpCls CLASS
Assign1     PROCEDURE(USHORT GrpRow, LONG Arg1, LONG Arg2, LONG Arg3, LONG Arg4)
         END

  CODE
  ArGrpCls.Assign1(1, 1,2,3,4) 
  ArGrpCls.Assign1(2, 5,6,7,8) 
  ArGrpCls.Assign1(3, 9,10,11,12) 
...
  ArGrpCls.Assign1(60, 65,66,67,68) 
  
ArGrpCls.Assign1 PROCEDURE(USHORT GrpRow, LONG Arg1, LONG Arg2, LONG Arg3, LONG Arg4)
    CODE
    ArGrp[GrpRow].Arg[1]=Arg1
    ArGrp[GrpRow].Arg[2]=Arg2
    ArGrp[GrpRow].Arg[3]=Arg3
    ArGrp[GrpRow].Arg[4]=Arg4
    RETURN 

2 Likes

I would write (I wrote only 6 lines):

ArGrp2 GROUP,STATIC
LONG(1);LONG(2);LONG(3);LONG(4)
LONG(1);LONG(2);LONG(3);LONG(4)
LONG(1);LONG(2);LONG(3);LONG(4)
LONG(1);LONG(2);LONG(3);LONG(4)
LONG(1);LONG(2);LONG(3);LONG(4)
LONG(1);LONG(2);LONG(3);LONG(4)
END
ArGrp Group,Dim(6),OVER(ArGrp2)
Arg Long,Dim(4)
END !Group

Hi Chris,
» Something like ArGrp[1] = 1,2,3,4

I would declare a separate group, such as
GroupInit GROUP
GI LONG(1)
G2 LONG(2)
G3 LONG(3)
G4 LONG(4)
END

Then, you can assign all four elements in one statement
ArGrp[1] = GroupInit

Bob

Thanks for the help and suggestions. It looks s if there are several ways to approach this problem. I am, of course, looking for the one with the least typing and least prone to typing error. Will see what works best. I cannot help but think that there should be an easy way to assign values to several elements of an array in one statement.