Quantcast
Channel: Visual COBOL - Forum - Recent Threads
Viewing all articles
Browse latest Browse all 4356

RE: Passing Array Between Forms

$
0
0

The following is an example which demonstrates the following:

1. main form populates an array with an Employee object like Robert explained.
2. Pass this array to a subform where it will be stored in working-storage
3. Subform places the emp-nos from array into a listview control and returns
4. main form displays subform
5. User selects one or more emp-nos from listview and clicks button
6. Subform closes and returns to main form
7. main form calls method iun subform to get array of selected items
8. main form then displays selected items in a listbox

main form:

 

  class-id passarray.Form1 is partial
                 inherits type System.Windows.Forms.Form.
       
       working-storage section.
       01 empArray type Employees occurs any.
       method-id NEW.
       procedure division.
           invoke self::InitializeComponent
           goback.
       end method.

       method-id button1_Click final private.
       procedure division using by value sender as object e as type System.EventArgs.
       
           set size of empArray to 5
           perform varying sub1 as binary-long from 1 by 1 until sub1 > 5
              set empArray(sub1) to new Employees
              set empArray(sub1)::emp-no to sub1
              set empArray(sub1)::checked to false
           end-perform
           
           declare mysubform as type passarray.subform = new passarray.subform
           invoke mysubform::setArray(empArray)
           invoke mysubform::ShowDialog
           
           set empArray to mysubform::getArray
           
           invoke listBox1::Items::Clear
           perform varying ret-emps as type Employees thru empArray
              if ret-emps::checked
                 invoke listBox1::Items::Add(ret-emps::emp-no)
              end-if
           end-perform.
           
       end method.
      
       end class.
       class-id Employees.
       working-storage section.
       01 emp-no    pic 9(9) property.
       01 checked   condition-value property.
       procedure division.
       
       end class.



subform:

       class-id passarray.subform is partial
                 inherits type System.Windows.Forms.Form.

       working-storage section.
       01 empArray type Employees occurs any.
       method-id NEW.
       procedure division.
           invoke self::InitializeComponent()
           goback.
       end method.

       method-id button1_Click final private.
       procedure division using by value sender as object e as type System.EventArgs.
           invoke self::Close
       end method.

       method-id setArray public.
       procedure division using by value myArray as type Employees occurs any.
           
           set empArray to myArray
           
           perform varying myemployee as type Employees thru myArray
              declare lvi as type ListViewItem = new ListViewItem(myEmployee::emp-no::ToString)
              invoke listView1::Items::Add(lvi)
           end-perform
                 
           goback.
       end method.
       method-id getArray public.
       procedure division returning myArray as type Employees occurs any.
           
           perform varying mylistitem as type ListViewItem thru listView1::SelectedItems
              perform varying myemployee as type Employees thru empArray
                 if myemployee::emp-no = type Int32::Parse(mylistitem::Text) 
                    set myemployee::checked to true
                    exit perform
                 end-if
              end-perform
           end-perform
           set myArray to empArray
           goback.
       end method.
       
       end class.

Viewing all articles
Browse latest Browse all 4356

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>