2016-07-28

Hi,  In most of the example i found that Winform is loaded from the main programs and on the events of the Controls ( Like Button) call to COBOL program or the invoking of obj for COBOL class is made. here we can pass the values between the Form and Cobol by using reference in procedure division. Can we call a Winform from the COBOL class or program and how would we pass the values between them ? Below is the code where in i want to load the Cobol Class first and then invoke Winform inside it and then access the values of the Form control from the COBOL Class?  Class: class-id CircleWithMessageBox.Main. method-id Main static attribute System.STAThread. local-storage section. 01 mainForm type CircleWithMessageBox.Form1. procedure division. set mainForm to new CircleWithMessageBox.Form1() invoke type System.Windows.Forms.Application::Run(mainForm) goback. end method. end class. Form code: $set sourceformat(free) preservecase ilusing(System.Windows.Forms) class-id CircleWithMessageBox.Form1 is partial inherits type System.Windows.Forms.Form. method-id NEW. procedure division. invoke self::InitializeComponent goback. end method. method-id btnExit_Click final private. procedure division using by value sender as object e as type System.EventArgs. invoke self::Close() end method. method-id btnCalculate_Click final private. Local-storage Section. 01 lo-radius pic 99. 01 lo-radius-X redefines lo-radius pic xx. 01 lo-circumference pic 999V9. 01 lo-circle-area pic 99999V9. 01 lo-edit-circumference pic ZZ9.9. 01 lo-edit-circumference-X redefines lo-edit-circumference pic X(5). 01 lo-edit-circle-area pic ZZ,ZZ9.9. 01 lo-edit-circle-area-X redefines lo-edit-circle-area pic x(8). procedure division using by value sender as object e as type System.EventArgs. * Process radius entry Move self::txtRadius::Text to lo-radius-X If lo-radius 50 Invoke type MessageBox::Show ("Radius entry greater than 50" "WARNING") End-if Evaluate True When lo-radius-X = " " Move " 0" to self::txtRadius::Text Move 0 to lo-radius When lo-radius-X(2:1) = " " Move lo-radius-X(1:1) to lo-radius * When other * Move lo-radius-X to lo-radius End-Evaluate * True Call "circle-calculations" using lo-radius lo-circumference, lo-circle-area Move lo-circumference to lo-edit-circumference Move lo-edit-circumference-X to self::lblCircumference::Text Move lo-circle-area to lo-edit-circle-area Move lo-edit-circle-area-X to self::lblArea::Text Invoke self::txtRadius::Focus Invoke self::txtRadius::SelectAll end method. method-id Form1_Load final private. procedure division using by value sender as object e as type System.EventArgs. end method. end class. Main : class-id CircleWithMessageBox.Main. method-id Main static attribute System.STAThread. local-storage section. 01 mainForm type CircleWithMessageBox.Form1. procedure division. set mainForm to new CircleWithMessageBox.Form1() invoke type System.Windows.Forms.Application::Run(mainForm) goback. end method. end class.

Show more