Creating Control Arrays in Windows Form (Managed COBOL)

I have a Windows form with 12 label controls which I want to populate with information I have stored in an Array.  What I have currently is the following:

 

       method-id TPS0010DForm_Load final private.

       procedure division using by value sender as object e as type System.EventArgs.

          

          

          set lbl1::Text to LineArray(1)

          set lbl2::Text to LineArray(2)

          set lbl3::Text to LineArray(3)

          goback.

       end method.

 

I suspect that a better way to do this would be roughly as follows:

       method-id TPS0010DForm_Load final private.

       procedure division using by value sender as object e as type System.EventArgs.

          

           perform varying the-index from 1 by 1

                   until the-index > 12

                   set lbl(array-item)::Text  to LineArray(the-index)

                   compute the-index = the-index 1

           end-perform

           goback.

       end method.

 

But I do not know how to make my labels into an array (set lbl(array-item)::Text). I have another screen that has about 100 labels and so I would not want to write 100 lines just to move information from an array into each label. I want to do it in a loop.

  • Verified Answer

    It doesn't seem to me like a Label control is a good choice in this scenario as a Label itself contains a single value. If you want to control these in a group then it might be better to create a gridview or listbox, etc so that you can use binding to bind the array directly to the group control.

    If you want to use Labels then you will have to create an array of Labels in your program and populate it with all the Labels that you wish to populate.

    Here is a simple example:

    working-storage section. 01 stringarray string occurs 4 times value "Red", "Green", "Blue", "White". 01 labelarray type Label occurs 4 times. method-id NEW. procedure division. invoke self::InitializeComponent set content of labelarray to (label1, label2, label3, label4) goback. end method. method-id Button1_Click final private. procedure division using by value sender as object e as type System.EventArgs. perform varying i as binary-long from 0 by 1 until i = stringarray::Length set labelarray[i]::Text to stringarray[i] end-perform end method.