Created On:  04 August 2011

Problem:

I have a Visual Cobol Solution, that contains two projects each with a Windows Form. One Windows Form has a button and the other a textbox control.

How can a value (string) be sent across projects, for example, if I click on Button on Form1 I want it to populate the textbox1 on Form2 with some text.

Would the line of code look something like the following for the btnSend_Click method:

        set form2::textbox1::text to "this is a test".

How can I reference components on other forms that are in other projects but in the sane solution?

Resolution:

Add a reference in the Form1 project to the Form2 project.
Form 1 needs to define a data item to hold the instance of Form2.
In this example Form2 will be instantiated from within Form1.

       class-id testtextspace.Form1 is partial
                 inherits type System.Windows.Forms.Form.
       working-storage section.
       01 wsForm2 type project2.Form2.
       method-id NEW.
       procedure division.
           invoke self::InitializeComponent
           set wsForm2 to new project2.Form2
           goback.
       end method.

There are two ways to reference the controls on Form2 from within Form1.
You can add a property in Form2 that can be set from Form1 which will set the textBox1::Text property to the desired value:

      class-id project2.Form2 is partial
                 inherits type System.Windows.Forms.Form.
       
       working-storage section.
       method-id set property textvalue.
       procedure division using textstring as string.
            set textBox1::Text to textstring
            goback.
       end method.

In Form1 you would set this as follows:

       method-id button1_Click final private.
       procedure division using by value sender as object e as type System.EventArgs.
          set wsForm2::textvalue to "From Form 1"
          invoke wsForm2::Show

The alternative, which is not recommended is to modify the .desigher.cbl file for Form2 and make the textBox1 control's definition Public so that it is visible to Form1.

01 textBox1 type System.Windows.Forms.TextBox public.

Then you can set the property directly using:

         set wsForm2::textBox1::Text to "From Form 1"