Highlighted
Respected Contributor.
Respected Contributor.
218 views

Creating Control Arrays in Windows Form (Managed COBOL)

Jump to solution

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.

0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

Re: Creating Control Arrays in Windows Form (Managed COBOL)

Jump to solution

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.

View solution in original post

0 Likes
2 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

Re: Creating Control Arrays in Windows Form (Managed COBOL)

Jump to solution

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.

View solution in original post

0 Likes
Highlighted
Respected Contributor.
Respected Contributor.

Re: Creating Control Arrays in Windows Form (Managed COBOL)

Jump to solution

Thank you, that worked! 

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.