Top
NetCOBOL V11.0 Getting Started
FUJITSU Software

A.15 Sample 14: Visual Basic calling COBOL -Simple ATM Example

Sample 14 demonstrates Visual Basic calling COBOL by using a simple automatic teller machine (ATM) bank account handling example.

Operating this program requires Visual Basic version 5.0 or later.

Overview

The sample program performs the following account functions:

The account data, comprising account number, PIN number, name and balance, is saved in an indexed file.

The structure of the indexed file is:

Account number 9(5) *> (This is the primary record key.)
Password 9(4)
Name X(12)
Deposit 9(9)

When functions are requested from the “ATM terminal” (user screens), the record data for the account in the indexed file is updated.

Files Included in Sample 14

Processing Overview

The Visual Basic application starts, and subroutine JMPCINT2 (which initializes the COBOL run-time system) is called when the main form is loaded.

The Visual Basic forms manage the interface with the user - accepting input data, transaction requests and displaying output data and messages. COBOL programs are called to manage the account data in the indexed file.

When the Visual Basic application is closed, it calls subroutine JMPCINT3 (which terminates the COBOL run-time).

Following figure shows the structure of the application:

COBOL Statements used in Sample 14

The MOVE, IF, PERFORM, COMPUTE, OPEN, READ, WRITE, REWRITE, CLOSE and EXIT statements are used.

COBOL Run-time System Subroutines

The following routines are used to initialize and terminate the COBOL run-time system.

Building/Rebuilding the Program

Project manager's build function is used to create the executable program.

In the following screen snapshots, the sample program was installed to C:\NetCOBOL. Your installation folder may be different.

  1. The project manager is started, and project file "SAMPLE14.PRJ" is opened.

  2. The project file is selected, and "Linker options" is selected from "Project"-"Options" menu.

    The "Linker options" dialog is displayed.

  3. "/EXPORT:K_KEN /EXPORT:K_SIN /EXPORT:K_NYU /EXPORT:K_SYU" is specified for the "Command line" editing box. After confirms it, the OK button is clicked.

    You are now returned to the Project Manager window.

  4. Select "Build" from Project Manager's "Project" menu or click on the Build button in the Project Manager toolbar.

    After the build terminates, check that K_KEN .DLL is created.

  5. When you rebuild executable file of Visual Basic, SAMPLE14.VBP (Visual Basic project file) included in the "Other" folder of the project is selected and "Edit" is selected from the project menu.

    Visual Basic starts; "Make of SAMPLE14.EXE" is selected from the file menu.

Debugging the Program

Applications containing a mixture of COBOL and Visual Basic code can be debugged under the control of both the COBOL and Visual Basic debuggers. To accomplish this, follow these steps:

  1. Select "Run-time Environment Setup Tool" from the "Tools" menu of the Project Manager.

    The run-time environment setup tool is displayed.

  2. Select "Open" on the "File" menu and select COBOL85.CBR in the folder that contains the executable program (SAMPLE14.EXE).

  3. Select the Common tab and enter data as shown below:

    • For the environment variable @CBR_ATTACH_TOOL, specify TEST.

  4. Click the Apply button.

    The data is saved in the object initialization file.

  5. Select "Exit" on the "File" menu to terminate the run-time environment setup tool.

  6. Start Visual Basic and load the SAMPLE14.VBP project.

  7. Start debugging the Visual Basic code when you execute the call to SAMPLE14 (the COBOL program) the COBOL debugger is invoked so that you can continue debugging in the COBOL part of the application.

  8. When you exit from the COBOL application control returns to the Visual Basic code.

The section “H. Debugging with Visual Basic” in Chapter 1’s Quick Tour steps through this example in some detail.

For more information on this topic, see Chapter 3, “Working with Visual Basic and COBOL” and the “NetCOBOL Debugging Guide”.

Executing the Program

To execute the program:

  1. The first application dialog is displayed:

  2. To work with the application click on the “New Account?” button.

    The New Account Information dialog is displayed:

  3. Open a new account. Type in a name (such as Alan), an amount (such as 100000) and a PIN number (such as 1234). Click the OK button.

    A dialog displaying the assigned account number is displayed:

  4. Note the account number and the PIN number you used - you will need to enter them in subsequent transactions.

  5. Click on the OK button to return to the main Sample 14 dialog box.

  6. You can now enter the account and PIN numbers and use the Withdrawal and Deposit functions.