Highlighted
Absent Member.
Absent Member.
3406 views

passing data from one managed .cbl to another in Visual COBOL

Jump to solution

I have one form (VCSite) that calls another (VCPrint).  VCPrint simply prints a text file.  I need to pass the filename to be printed from VCSite to VCPrint as the filename changes based upon the user.  What is the best way to do this?

0 Likes
1 Solution

Accepted Solutions
Highlighted
Absent Member.
Absent Member.

RE: passing data from one managed .cbl to another in Visual COBOL

Jump to solution

Chris,

The code below is now working, thanks.  I will review your other suggestions as well.  The forms are in different projects.  I believe the main forms are generated automatically when I add the project..  I've been adding projects as Windows Forms Applications, then deleting the form, adding a form with the correct name and changing the project>properties>output type to Class Library.  So should I just be adding a Class Libray project instead, then adding the form?  And can I get rid of all the subsequent Main.cbl pgms?  Probably more things that don't make sense, but I'm learning as I go.  Thanks for your help, here is the code that works:

View solution in original post

0 Likes
7 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: passing data from one managed .cbl to another in Visual COBOL

Jump to solution

The easiest method for passing this parameter is probably to just change the new method of the frmVCPrint so that it takes a string parameter.

      method-id NEW.

      procedure division using filename as string.

          invoke self::InitializeComponent()

          set textBoxFileName::Text to filename

The calling program would then invoke this as follows:

change your statement:

invoke type VCPrint.frmVCPrint::New() returning newvcprintform

to:

invoke type VCPrint.frmVCPrint::New("C:\AIRR\REPORTS\VCPRINT.D80") returning newvcprintform

or  using the new Visual COBOL syntax to simplify things

set newvcprintform to new VCPrint.frmVCPrint("C:\AIRR\REPORTS\VCPRINT.D80")

You could also create a string property in the working-storage of VCPrint and then set it in the calling program before the document is printed.

In VCPrint:

01 myfilename  string property.

In calling program:

set newvcprintform::myfilename to "C:\AIRR\REPORTS\VCPRINT.D80"

If you used the property method then you would have to move your set textBoxFileName::Text to statement out of the New method and place it in the method that actually does the printing.

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: passing data from one managed .cbl to another in Visual COBOL

Jump to solution

Intellisense doesn't want to accept the changes:

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: passing data from one managed .cbl to another in Visual COBOL

Jump to solution

After making change to NEW method in VCPrint, do a Rebuild all to ensure class is built.

Intellisense should then work correctly.

In calling program comment out original invoke statement for "NEW" method.

The replacement set statement should look like:

   set newvcprintform to new VCPrint.frmVCPrint("C:\AIRR\REPORTS\VCPRINT.D80")

where you have any extra "New" method in it.

This works for me just fine.

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: passing data from one managed .cbl to another in Visual COBOL

Jump to solution

Intellisense still doesn't like the first two options so I commented them out.  I had to modify the Main program for VCPrint to get it to compile.  I now get the following exception when it executes the set newvcprintform::myfilename to "C:\AIRR\REPORTS\VCPRINT.D80" line.  Thanks.

  

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: passing data from one managed .cbl to another in Visual COBOL

Jump to solution

I think that there is some confusion going on here.

You cannot comment out the lines which create the new instance because then you cannot set the property on it as it doesn't exist.
You also appear to be creating an instance of this class in your main program as well as from the other form which makes no sense.

Are these forms in the same project or in different projects?
You should only have one main application that runs the main form.
Other forms should be instantiated and displayed as required.

I am attaching a sample project which creates a new instance of a second form class and then calls a method in it which accepts a string parameter and then sets the textbox::text property to that string.

The second form is then displayed using the showdialog method.

Use this as a template for your own application.

If the OO concepts that I am explaining here are new to you, it might be a good idea to take a look at the docs under Reference-->Managed Code here:

Thanks.

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: passing data from one managed .cbl to another in Visual COBOL

Jump to solution

Chris,

The code below is now working, thanks.  I will review your other suggestions as well.  The forms are in different projects.  I believe the main forms are generated automatically when I add the project..  I've been adding projects as Windows Forms Applications, then deleting the form, adding a form with the correct name and changing the project>properties>output type to Class Library.  So should I just be adding a Class Libray project instead, then adding the form?  And can I get rid of all the subsequent Main.cbl pgms?  Probably more things that don't make sense, but I'm learning as I go.  Thanks for your help, here is the code that works:

View solution in original post

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: passing data from one managed .cbl to another in Visual COBOL

Jump to solution

You should create a Forms Application project when you begin. This will create the main form called form1 and the main program that will run the application.

If you need additional forms I would suggest that you right click on the forms project in Solution Explorer select Add-->New Item and then select Windows Form.

This will add the new form to the same project and keep them all together.

You can add the forms in separate projects but you should only have one main Windows Form application and the other projects should be class library projects.

I find it simpler to add them all to the same project unless you wish to share the projects within different solutions.

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.