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

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?

  • 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.

  • Intellisense doesn't want to accept the changes:

  • Intellisense doesn't want to accept the changes:

  • 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.

  • 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.

      

  • 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.

      

  • 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.

    testmultiforms.zip
  • Verified Answer

    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:

  • Verified Answer

    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:

  • Verified Answer

    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: