Highlighted
Absent Member.
Absent Member.
4937 views

Getting cobconfig to work.

Jump to solution

I saw a post on how to get MF Visual Cobol to print to a USB printer, instead of the default LPT1. However, it was not as descriptive as I would have hoped. Since I have not worked with Cobol since 1995 and went into the business world using Fortran after that class, I never found the need to set environment variables. I also never used MF Cobol before now. The one post states to create a file called cobconfig.cfg and then set the cobconfig environment variable to point to that file. Well, I have tried a couple of ways on my own and could not get it to set the environment variable of cobconfig and work. Any help that someone can provide in getting the cobconfig environment variable to work in MF Visual Cobol for Visual Studio 2012 would be greatly appreciated. I've looked far and wide on the net and have not yet found any specific help. I did get the old program to work via sending the output to a file, but I want to get it to work as originally intended to a printer and not to the old LPT1 port. A specific example of how to set the variable would be great.

0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Getting cobconfig to work.

Jump to solution

Apologies mozdzierz, I assumed that you were working with a native code project since you referred to setting cobconfig but the exception indicates that you are running a managed code program which does not use that file at all.

In a managed code project you need to add an Application Configuration File to the project (via Add -> New Item on the context menu in Solution Explorer) and add an entry for the printer_redirection tuneable to that. What you need to add is shown in the following topic in the product documentation

Format of a Configuration File for .NET COBOL

and it actually contains both printer_redirection and printer_defaults

Gael

View solution in original post

0 Likes
13 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Getting cobconfig to work.

Jump to solution

Mozdzierz,

Open a Visual COBOL command prompt.

Create your text file containing

set printer_redirection=true

From the command line

set COBCONFIG=<path>\cobconfig.cfg

Run your app. If your USB printer is your default printer and your COBOL code is using ASSIGN TO PRINTER in the file descriptor it should now write to the USB printer.

To do the same from the Visual Studio IDE, open the Properties for your application, go to the Application page, click on the Environment button and set COBCONFIG to the value <path>\cobconfig.cfg. Then when you run your application from within Visual Studio it should pick up the configuration.

I hope that helps,

Gael

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Getting cobconfig to work.

Jump to solution

I will implement this suggestion. I was trying to set cobconfig from within the program itself and that seems to be my problem. Since I was not using a command line compiler like I did in the old days, setting it from what I will call the DOS prompt way totally slipped my mind and the Visual Studio tip will most likely do the trick. I set it in Windows and that did not work. I will let you know how it turns out. Thank You!

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Getting cobconfig to work.

Jump to solution

Mozdzierz,

Setting cobconfig from within the program did not work because the file is read when the COBOL run-time system starts up. Once you are in the COBOL program it has already started so it is too late.

When you said you set it in WIndows, do you mean that you set it as an environment variable from Control Panel -> System -> Advanced -> Environment variables ? That should work so if it failed it could be for one of the following reasons

1. The file could not be found. A full path to the file should be specified as the value

2. The file contains a spelling mistake or does not contain a newline character after the tuneable.

3. The USB printer is not set as the default printer.

To check that the variable has been set correctly you could add the following check to your code

01 cobconfig-value    pic x(255).

...

DISPLAY "COBCONFIG" UPON ENVIRONMENT-NAME

ACCEPT cobconfig-value FROM ENVIRONMENT-VALUE

IF cobconfig-value = SPACES

   DISPLAY "COBCONFIG was not set"

END-IF

Gael

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Getting cobconfig to work.

Jump to solution

Thank you for the added information and I will check that as well. I did exactly that to set the variable in windows. On another note, when I look at the properties in Visual Studio for my program, the configuration drop down is grey and lists N/A. I do only have a student eval copy. I added the code and it did not display, so I imagine that it is being set, but I still get the error with an lpt1. This is how the error reads and when I changed the program to print to a file, it stopped it and executes to that file. Cobolfilehandlingexception was unhandled  'LPT1' : 9/004 (ANS74) 4 illegal filename.

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Getting cobconfig to work.

Jump to solution

I have been fighting with the VA, so my mind is not all there right now. This is one of the reasons why I decided to mess around with my old programs, is to forget about it for a while. So, I forgot to add this information as well. My cobconfig,cfg file contains only this on a single line. set printer_redirection=TRUE. Is the all caps a problem? It may be this that you mentioned, since I don't know what that character is. newline character after the tuneable  My printer is set to the default printer and plugged into the port when executing the program in debug. I appreciate your time in helping me tackle this problem.

Steven

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Getting cobconfig to work.

Jump to solution

Apologies mozdzierz, I assumed that you were working with a native code project since you referred to setting cobconfig but the exception indicates that you are running a managed code program which does not use that file at all.

In a managed code project you need to add an Application Configuration File to the project (via Add -> New Item on the context menu in Solution Explorer) and add an entry for the printer_redirection tuneable to that. What you need to add is shown in the following topic in the product documentation

Format of a Configuration File for .NET COBOL

and it actually contains both printer_redirection and printer_defaults

Gael

View solution in original post

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Getting cobconfig to work.

Jump to solution

No apologies necessary, since I am new to MF Cobol for Visual Studio, the fault lies with me for not being versed on the proper procedures and explaining to others the context of my project. I will look at the help files on the subject you mention and update you.

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Getting cobconfig to work.

Jump to solution

Well, like the other option for configuration, the add tab in solutions Explorer for what I choose as an empty Cobol project is not an option I can choose, since it is grey. Any suggestions? I actually apologize for being such a newbie to this app.

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Getting cobconfig to work.

Jump to solution

I just noticed that I can choose the add option with the program that was run to a file and then choose the correct part of my project and the option was a choice. I will now work on getting it to work with the addition of the configuration file.

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Getting cobconfig to work.

Jump to solution

I just found out that I was in debug when I tried to add the item and that is why it was not a choice.

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Getting cobconfig to work.

Jump to solution

That was the ticket! Now all I have to do is format the output and I saw another post with that help and I hope it is as straight forward as your help was. If I have trouble with that, I will start a post on that topic.

Thank you again.

Steven

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.