Skip to main content

Demo - Using VB.NET and unmanaged COBOL together

  • February 15, 2013
  • 0 replies
  • 0 views

Problem:

This demo shows how to write a VB.NET program to interact with and pass parameters to an unmanaged (procedural) Cobol program. It is different from the way a VB program calls a Cobol program. To find out what is new and different in VB .NET, here is a link to an interesting article: http://www.ondotnet.com/pub/a/dotnet/excerpt/vbnetnut_appa/index.html

Resolution:

BUILD W/RELEASE:     

NetExpress v4.0 & Microsoft VB .NET 2003

INTRODUCTION

==========

The issues that will be addressed in the demo are the way to pass an integer, a string, and a structure.  First, the integer now takes 4 bytes in VB .NET (2 bytes in VB), so it has to be defined as pic x(4) comp-5 in Cobol.

Secondly, there is no fixed-length string in VB. NET. In VB, it was possible to define it as follows:

MyPicX3 string * 3 One way to emulate the above in VB .NET would be to define a string and pad it with spaces to reserve the size to be used by the string. The more conventional way would be to marshal the field with MarshalAsAttribute and UnmanagedType.ByValTSt as shown in the VB .NET source code (Form1.vb).

It is worth to note that parameters are passed By Value by default in VB .NET while it is By Reference in VB.

SOURCE FILES:

==========

Program Files

Description

----------------                   -----------------------------------------------------------

vbCBL\\                            Net Express project folder

.\\vbCBL.app                    Net Express project

.\\coboldll.cbl                    Cobol source code

vbCallCBL\\                       Microsoft Visual Studio solution

.\\vbCallCBL.sln                Microsoft Visual Studio solution object

.\\vbCallCBL.vbproj          Microsoft Visual Basic .NET project

.\\Form1.vb                      Microsoft Visual Basic source code

.\\Form1.resx                   Microsoft Visual Basic .NET ressource file

.\\AssemblyInfo.vb          Microsoft Visual Basic source code

.\\vbCallCBL.suo              Microsoft Visual Studio solution user options

.\\vbCallCBL.vbproj.user     Microsoft Visual Studio Project user options

REQUIREMENTS:

==========

NetExpress v4.0 and Microsoft Visual Bacic .NET 2003

OPERATION:

========

(1) Load vbCBL\\vbCBL.app into Net Express

(2) Rebuild All (Project > Rebuild All) --> The Cobol DLL will be created in the vbCallCBL\\bin folder as the default build directory name has been redirected (Project >Types of Build... > Change)

(3) Load vbCallCBl\\vbCallCBL.sln into MS Visual Studio .NET IDE

(4) Rebuild Solution (Build > Rebuild Solution) --> You can now run or debug the VB .NET code

ADDITIONAL NOTES:

- .RESX file is the MS VB .NET resource file format that consists of XML entries, which specify objects and strings inside XML tags   (see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconresourcesinresxfileformat.asp)

- AssemblyInfo.vb is an information file that contains metadata about the assemblies in a project, such as name, version, and culture information.

==========================================================

Keywords: Example, sample, demo, demonstration, .NET, vbnet2cbl.zip

demo.ex

demo.ne

Attachments:

VBnet2CBL.zip

Old KB# 4356