Online courses in ASP.NET MVC, ASP.NET Core, and Design Patterns conducted by Bipin Joshi. Read more...
Learn ASP.NET MVC, ASP.NET Core, and Design Patterns through our online training programs. Courses conducted by Bipin Joshi on weekends. Read more details here.

<%@ Page %>

Displaying MessageBox using COBOL.NET

Introduction

In the last article we developed a simple hello world application using COBOL.NET. In this article we will see how to display Windows Forms message box. This article will show you how to use .NET namespaces and classes in your COBOL application. As in previous case you need Fujitsu's NetCOBOL compiler for .NET. You can download it from their web site.

COBOL Classes and .NET Base Classes

In this application we will use following .NET Base Classes:
  • System.Windows.Forms.MessageBox - to implement the code to display the messagebox.
  • System.Drawing - for various sizes and fonts.

Source Code

Open VS.NET and select COBOL Projects -> Console Application. Alternatively, you can also write it in Notepad and save the file as messageboxapp.cob. Write the code snippet given below:
000010 CLASS-ID. SHELLO INHERITS Form.
000020 ENVIRONMENT DIVISION.
000030 CONFIGURATION SECTION.
000040 REPOSITORY.
000050     CLASS Form AS "System.Windows.Forms.Form"
000060     CLASS MessageBox AS 
		"System.Windows.Forms.MessageBox"
000070     CLASS Application AS 
		"System.Windows.Forms.Application"
000080     CLASS Container AS "System.ComponentModel.Container"
000090     CLASS Button AS "System.Windows.Forms.Button"
000100     DELEGATE EventHandler AS "System.EventHandler"
000110     CLASS EventArgs AS "System.EventArgs"
000120     CLASS Point AS "System.Drawing.Point"
000130     CLASS Drawing-size AS "System.Drawing.Size"
000140     CLASS Font AS "System.Drawing.Font"
000150     CLASS Sys-Object AS "System.Object"
000160     CLASS Sys-Boolean AS "System.Boolean"
000170     CLASS Control-Collection AS 
		"System.Windows.Forms.Control+ControlCollection"
000180     PROPERTY Prop-Enabled AS "Enabled"
000190     PROPERTY Prop-Location AS "Location"
000200     PROPERTY Prop-Size AS "Size"
000210     PROPERTY Prop-TabIndex AS "TabIndex"
000220     PROPERTY Prop-Font AS "Font"
000230     ENUM Font-Style AS "System.Drawing.FontStyle"
000240     PROPERTY Prop-Bold AS "Bold"
000250     PROPERTY Prop-Text AS "Text"
000260     PROPERTY App-Controls AS "Controls"
000270     PROPERTY Prop-AutoScaleBaseSize 
		AS "AutoScaleBaseSize"
000280     PROPERTY Prop-ClientSize AS "ClientSize".
000290     
000300*Main Block of code
000310 STATIC.
000320 PROCEDURE DIVISION.
000330 METHOD-ID. MAIN.
000340 DATA DIVISION.
000350 WORKING-STORAGE SECTION.
000360 01 OBJ OBJECT REFERENCE SHello.
000370 PROCEDURE DIVISION.
000380     INVOKE SHello "NEW" RETURNING OBJ.
000390     INVOKE Application "Run" USING BY VALUE OBJ.
000400 END METHOD MAIN.
000410 END STATIC.
000420 
000430*
000440 OBJECT.
000450 DATA DIVISION.
000460 WORKING-STORAGE SECTION.
000470 01 COMPONENTS OBJECT REFERENCE Container.
000480 01 Button1 OBJECT REFERENCE Button.
000490 PROCEDURE DIVISION.
000500
000510*Procedure New
000520 METHOD-ID. NEW.
000530 DATA DIVISION.
000540 WORKING-STORAGE SECTION.
000550 PROCEDURE DIVISION.
000560     INVOKE Container "NEW" RETURNING COMPONENTS.
000570     INVOKE SELF "InitializeComponent".
000580 END METHOD NEW.
000590 
000600*Procedure Dispose
000610 METHOD-ID. DISPOSE AS "Dispose" PROTECTED OVERRIDE.
000620 DATA DIVISION.
000630 WORKING-STORAGE SECTION.
000640 01 FLAG PIC 1 USAGE BIT.
000650 LINKAGE SECTION.
000660 01 DISPOSING OBJECT REFERENCE Sys-Boolean.
000670 PROCEDURE DIVISION USING BY VALUE DISPOSING.
000680     SET FLAG TO DISPOSING.
000690     IF FLAG = B"1" AND COMPONENTS NOT = NULL THEN
000700         INVOKE COMPONENTS "Dispose"
000710     END-IF.
000720     INVOKE SUPER "Dispose" USING BY VALUE DISPOSING.
000730 END METHOD DISPOSE.
000740
000750*Procedure Initialize Component
000760 METHOD-ID. InitializeComponent 
		AS "InitializeComponent".
000770 DATA DIVISION.
000780 WORKING-STORAGE SECTION.
000790 01 CLICK-EVENT OBJECT REFERENCE EventHandler.
000800 01 BOLD-Font OBJECT REFERENCE Font-Style.
000810 PROCEDURE DIVISION.
000820     INVOKE Button "NEW" RETURNING Button1.
000830     INVOKE SELF "SuspendLayout".
000840
000850*Set the Properties for the Button
000860     SET Prop-Location OF 
		Button1 TO Point::"NEW" (40, 184).
000870     SET Prop-Size OF 
		Button1 TO Drawing-size::"NEW" (208, 48).
000880     MOVE 0 TO Prop-TabIndex OF Button1.
000890     SET Prop-Text OF Button1 TO "Click".
000900     SET BOLD-Font TO Prop-Bold OF Font-Style.
000910     SET Prop-Font OF Button1 TO
000920         Font::"NEW" ("Verdana", 10.0, BOLD-Font).
000930     INVOKE EventHandler 
		"NEW" USING BY VALUE SELF "Button1_Click"
000940         RETURNING CLICK-EVENT.
000950     INVOKE Button1 "add_Click" 
		USING BY VALUE CLICK-EVENT.
000960     INVOKE App-Controls 
		OF SELF "Add" USING BY VALUE Button1.
000970     SET Prop-Text OF 
		SELF TO "Hello World Using MessageBox".
000980     SET Prop-AutoScaleBaseSize 
		OF SELF TO Drawing-size::"NEW" (5, 13).
000990     SET Prop-ClientSize OF SELF TO 
			Drawing-size::"NEW" (292, 274).
001000     INVOKE SELF "ResumeLayout" USING BY VALUE B'0'.
001010 END METHOD InitializeComponent.
001020
001030*Procedure for Button_Click
001040 METHOD-ID. Button1_Click AS "Button1_Click".
001050 DATA DIVISION.
001060 WORKING-STORAGE SECTION.
001070 01 Enabled PIC 1 USAGE BIT.
001080 LINKAGE SECTION.
001090 01 Sender OBJECT REFERENCE Sys-Object.
001100 01 E OBJECT REFERENCE EventArgs.
001110 PROCEDURE DIVISION USING BY VALUE Sender E.
001120      INVOKE MessageBox "Show" USING BY VALUE 
001130              "Hello COBOL.NET Program".
001140 END METHOD Button1_Click.
001150*
001160 END OBJECT.
001170*
001180 END CLASS SHello.
001190
001200

Compiling the code

You can compile the project from VS.NET or if you are using command line compiler enter following command at command prompt:
cobolc 
/reference:System.DLL,
System.Drawing.DLL,
System.Windows.Forms.DLL
/main:SHELLO,MAIN messageboxapp.cob
Now run the application go to the specific folder and start the .exe generated.

In the next article we will see how to access database using COBOL.NET and .NET namespaces.




Sushila Bowalekar, is presently working as Training Consultant in Mumbai, India. Her skill set includes HTML, JavaScript, VBScript, ASP, Site Server Commerce Edition 3.0 and presently she is working on .NET.

Posted On : 06 Jul 2002



Tags : .NET Framework Visual Studio Components