Created On:  15 August 2012

Problem:

How can I update the message and progress bar indicator on a statusStrip control on a main form from within a called subprogram?

Resolution:

Attached is an example that demonstrates how to update the message and progress bar indicator on a statusStrip control on a main form from within a called COBOL subprogram.

*--------------------------------------------------------------------------------*
*                                DisplayStatus                                   *
*                                                                                *
* This example program demonstrates how to update a statusStrip control on a main*
* Windows Form from a called program in order to change both the status message  *
* and the Progress bar displayed on that form.                                   *
*                                                                                *
* The main form contains a statusStrip control which consists of two items,      *
* toolStripStatusLabel1 and toolStripProgressBar1. The ProgressBar is set to have*
* a maximum (100%) value of 5000 with increments of 1 to match the number of re- *
* cords being written to test-file in Program1.                                  *
*                                                                                *
* The object reference to the current form is passed as SELF to the called pro-  *
* gram so that it can directly invoke its methods.                               *
* Interface Idisplaystatus is defined in Program1.cbl and is used to define the  *
* type passed to the procedural program to allow call back to the form.          *
*--------------------------------------------------------------------------------*

class-id displaystatus.Form1 is partial
   inherits type System.Windows.Forms.Form implements type Idisplaystatus.
working-storage section.
method-id NEW.
procedure division.
   invoke self::InitializeComponent
   invoke self::changeStatus("Click Button to Start File Creation...")
   goback.
end method.
method-id button1_Click private final.
procedure division using by value sender as object e as type System.EventArgs.
   call "Program1" using by value self
   goback
end method.
method-id changeStatus public.
procedure division using newMessage as string.
   set toolStripStatusLabel1::Text to newMessage
   invoke statusStrip1::Refresh
   goback.
end method.
method-id changeProgress public.
procedure division using by value progressCount as binary-long.
   set toolStripProgressBar1::Value to progressCount
   invoke statusStrip1::Refresh
   goback.
end method.
end class.

Program1:

interface-id Idisplaystatus.
method-id changeStatus public.
procedure division using newMessage as string.
end method.
method-id changeProgress public.
procedure division using by value progressCount as binary-long.
end method.
end interface.

program-id. Program1.
   select test-file assign to "testfile.dat"
   organization is indexed
   access is dynamic
   record key is key1
   file status is file-status.
data division.
fd test-file.
01 test-record.
   05 key1 pic 9(5).
   05 rest pic x(5000).
working-storage section.
01 file-status pic x(2).
01 progressCount binary-long.
procedure division using by value mainform as type Idisplaystatus.
   invoke mainform::changeStatus("File Creation Started...")
   open output test-file
   perform varying progressCount from 0 by 1 until progressCount > 5000
      move progressCount to key1
      move all "A" to rest
      write test-recordinvoke mainform::changeProgress(progressCount)
   end-perform
   invoke mainform::changeStatus("File Creation Completed!")
   close test-file
   delete test-file
   goback.
end program Program1.