Skip to main content

Hi folks.


I hope somebody can help me with this problem. I am working on maintaining a large program.

The problem which I have is related to printing documents. On the computer are installed two printers:
1) Bullzip PDF Printer
2) HP LaserJet (default printer)

I had successfully called printer dialog, chose Bullzip PDF Printer for printing. The only first document was printed with Bullzip printer, all other documents are printed with HP LaserJet without showing printing dialog.

Here is my code:
PRNW-OPEN.
*-------- move 1 to Prn-Flags.
move 0 to Prn-WinHand.
move "Greska kod OPEN Printera !!! " to Prn-Errtxt.
MOVE 128 TO Prnw-len.
MOVE PrnDoc-naz TO Prnw-InCHR.
PERFORM PRNW-Title-Len.
IF Prn-IndOPEN equal zero THEN;
CALL "PC_PRINTER_OPEN" using Prn-Handle, Prn-DOC,
by value Prn-Flags
by value Prn-WinHand
returning Prn-RetCode.
if Prn-RetCode not equal zero PERFORM PRNW-ERR.
MOVE 1 TO Prn-IndOPEN.
move zero to Num-Lin.

What I want to achieve is:
1) to choose in the printing dialog the printer and to use it for printing all separate documents (one page is one file with different name).
2) or from the code to tell NetExpress which installed pritner to use for printing without showing the print dialog

Hi folks.


I hope somebody can help me with this problem. I am working on maintaining a large program.

The problem which I have is related to printing documents. On the computer are installed two printers:
1) Bullzip PDF Printer
2) HP LaserJet (default printer)

I had successfully called printer dialog, chose Bullzip PDF Printer for printing. The only first document was printed with Bullzip printer, all other documents are printed with HP LaserJet without showing printing dialog.

Here is my code:
PRNW-OPEN.
*-------- move 1 to Prn-Flags.
move 0 to Prn-WinHand.
move "Greska kod OPEN Printera !!! " to Prn-Errtxt.
MOVE 128 TO Prnw-len.
MOVE PrnDoc-naz TO Prnw-InCHR.
PERFORM PRNW-Title-Len.
IF Prn-IndOPEN equal zero THEN;
CALL "PC_PRINTER_OPEN" using Prn-Handle, Prn-DOC,
by value Prn-Flags
by value Prn-WinHand
returning Prn-RetCode.
if Prn-RetCode not equal zero PERFORM PRNW-ERR.
MOVE 1 TO Prn-IndOPEN.
move zero to Num-Lin.

What I want to achieve is:
1) to choose in the printing dialog the printer and to use it for printing all separate documents (one page is one file with different name).
2) or from the code to tell NetExpress which installed pritner to use for printing without showing the print dialog

You should look at the documentation for PC_PRINTER_SET_DEFAULT library routine as this supports both methods. If you set the default printer first it will be in effect for all subsequent PC_PRINTER calls. I believe that this is supported in Net Express 4.0.

Here is an example of how to set the default printer to a specific printer and then use PC_PRINTER_OPEN and PC_PRINTER_WRITE to create a document.

       working-storage section.                                         
       01 default-info.                                                 
         03 option             pic x(4) comp-5.                         
         03 ourprinter.                                                 
           05 len              pic x(2) comp-5.                         
           05 body             pic x(128).                              
                                                                        
       78 SET-DEFAULT-PRINTER  value h"0001".                           
                                                                        
       01 printer-handle       pic x(4) comp-5.                         
       01 document-title.                                               
          03 cblte-pn-name-len pic x(2) comp-5.                         
          03 cblte-pn-name     pic x(128)      value spaces.            
       01 flags                pic x(4) comp-5 value zeroes.            
       01 window-handle        pic x(4) comp-5 value zeroes.            
       01 status-code          pic x(4) comp-5 value zeroes.            
       01 print-buffer         pic x(20).                               
       01 print-buffer-len     pic x(4) comp-5.                         
       procedure division.                                              
                                                                        
           move "HP OfficeJet Pro 9010 series [FB499A]"                 
             to body of ourprinter of default-info                      
           move 37 to len of ourprinter of default-info                 
           move SET-DEFAULT-PRINTER to option of default-info           
                                                                        
           call "PC_PRINTER_SET_DEFAULT" using                          
                           by value option of default-info,             
                           by reference ourprinter of default-info      
                 returning status-code                                  
           end-call                                                     
                                                                        
           if status-code not = zeroes                                  
               display "Default printer failed = " status-code          
               stop run                                                 
           end-if                                                       
                                                                        
           move "my doc" to cblte-pn-name                               
           move 6 to cblte-pn-name-len                                  
                                                                        
           call "PC_PRINTER_OPEN" using     printer-handle              
                                            document-title              
                                  by value  flags                       
                                  by value  window-handle               
                                  returning status-code                 
           end-call                                                     
           if status-code not = zeroes                                  
              display "Open Failed = " status-code                      
              stop run                                                  
           end-if                                                       
                                                                        
                                                                        
           move "This is line one" to print-buffer                      
           move 20 to print-buffer-len                                  
                                                                        
           call "PC_PRINTER_WRITE" using     printer-handle             
                                             print-buffer               
                                   by value  print-buffer-len           
                                   returning status-code                
           end-call                                                     
           if status-code not = zeroes                                  
              display "Write Failed = " status-code                     
              stop run                                                  
           end-if                                                       
                                                                        
           call "PC_PRINTER_CLOSE" using     printer-handle             
                                   returning status-code                
           end-call                                                     
           if status-code not = zeroes                                  
              display "Close Failed = " status-code                     
              stop run                                                  
           end-if.                                                      
                                                                        
                                                                        


You should look at the documentation for PC_PRINTER_SET_DEFAULT library routine as this supports both methods. If you set the default printer first it will be in effect for all subsequent PC_PRINTER calls. I believe that this is supported in Net Express 4.0.

Here is an example of how to set the default printer to a specific printer and then use PC_PRINTER_OPEN and PC_PRINTER_WRITE to create a document.

       working-storage section.                                         
       01 default-info.                                                 
         03 option             pic x(4) comp-5.                         
         03 ourprinter.                                                 
           05 len              pic x(2) comp-5.                         
           05 body             pic x(128).                              
                                                                        
       78 SET-DEFAULT-PRINTER  value h"0001".                           
                                                                        
       01 printer-handle       pic x(4) comp-5.                         
       01 document-title.                                               
          03 cblte-pn-name-len pic x(2) comp-5.                         
          03 cblte-pn-name     pic x(128)      value spaces.            
       01 flags                pic x(4) comp-5 value zeroes.            
       01 window-handle        pic x(4) comp-5 value zeroes.            
       01 status-code          pic x(4) comp-5 value zeroes.            
       01 print-buffer         pic x(20).                               
       01 print-buffer-len     pic x(4) comp-5.                         
       procedure division.                                              
                                                                        
           move "HP OfficeJet Pro 9010 series [FB499A]"                 
             to body of ourprinter of default-info                      
           move 37 to len of ourprinter of default-info                 
           move SET-DEFAULT-PRINTER to option of default-info           
                                                                        
           call "PC_PRINTER_SET_DEFAULT" using                          
                           by value option of default-info,             
                           by reference ourprinter of default-info      
                 returning status-code                                  
           end-call                                                     
                                                                        
           if status-code not = zeroes                                  
               display "Default printer failed = " status-code          
               stop run                                                 
           end-if                                                       
                                                                        
           move "my doc" to cblte-pn-name                               
           move 6 to cblte-pn-name-len                                  
                                                                        
           call "PC_PRINTER_OPEN" using     printer-handle              
                                            document-title              
                                  by value  flags                       
                                  by value  window-handle               
                                  returning status-code                 
           end-call                                                     
           if status-code not = zeroes                                  
              display "Open Failed = " status-code                      
              stop run                                                  
           end-if                                                       
                                                                        
                                                                        
           move "This is line one" to print-buffer                      
           move 20 to print-buffer-len                                  
                                                                        
           call "PC_PRINTER_WRITE" using     printer-handle             
                                             print-buffer               
                                   by value  print-buffer-len           
                                   returning status-code                
           end-call                                                     
           if status-code not = zeroes                                  
              display "Write Failed = " status-code                     
              stop run                                                  
           end-if                                                       
                                                                        
           call "PC_PRINTER_CLOSE" using     printer-handle             
                                   returning status-code                
           end-call                                                     
           if status-code not = zeroes                                  
              display "Close Failed = " status-code                     
              stop run                                                  
           end-if.                                                      
                                                                        
                                                                        

Hi Chris.

Thanks for your answer.


Meanwhile, I had successfully changed the default printer. What I had noticed is the fact that works only during the execution of the program. If we have 2 printers installed: pr1, pr2. For example, the default printer is pr2. I want to pr1 be the default printer during the execution. Call of the PC_PRINTER_SET_DEFAULT will let me do that. When I go to Start -> Control Panels -> Printers printer pr2 will still mark as default printer. How I can do this change permanent?

And one more question not related to this topic. I am not familiar too much with Net Express 4.0. I am working on maintaining one large program which had developed my father. Can you point me to some free online books for learning this language? Currently, I am learning this language in the movement.


Regards,

Ivan


Hi Chris.

Thanks for your answer.


Meanwhile, I had successfully changed the default printer. What I had noticed is the fact that works only during the execution of the program. If we have 2 printers installed: pr1, pr2. For example, the default printer is pr2. I want to pr1 be the default printer during the execution. Call of the PC_PRINTER_SET_DEFAULT will let me do that. When I go to Start -> Control Panels -> Printers printer pr2 will still mark as default printer. How I can do this change permanent?

And one more question not related to this topic. I am not familiar too much with Net Express 4.0. I am working on maintaining one large program which had developed my father. Can you point me to some free online books for learning this language? Currently, I am learning this language in the movement.


Regards,

Ivan

You can set the system-wide default printer for the current user using the Windows API function SetPrinterDefault. One way you can do this is with the following program:

       id division.                                              
       program-id. Program1.                                     
       environment division.                                     
       configuration section.                                    
       special-names.                                            
          call-convention 66 is winapi.                          
                                                                 
       data division.                                            
       working-storage section.                                  
       01 printer-name pic x(80) value spaces.                   
       01 status-code  pic x(4) comp-5 value zeroes.             
       01 pp procedure-pointer.                                  
       procedure division.                                       
           set pp to entry "kernel32"                            
           call winapi "LoadLibraryA"                            
              using z"winspool.drv"                              
              returning pp                                       
           end-call                                              
           call winapi "GetProcAddress"                          
              using by value pp                                  
                    by reference z"SetDefaultPrinterA"           
              returning pp                                       
           end-call                                              
           move z"Microsoft Print to PDF" to printer-name        
                                                                 
           call pp                                               
              using printer-name                                 
              returning status-code                              
           end-call                                              
                                                                 
           if status-code not = 0                                
              display "Default Printer Changed"                  
           else                                                  
              display "Default Printer Not Changed!"             
           end-if                                                
                                                                 
           goback.                                               

Are you looking to learn COBOL or the Net Express product. There are hundreds of books and courses for learning COBOL. Net Express 4.0 is an extremely old product and hasn't been supported in years. My suggestion for beginning training in this product is to go thru the tutorials in the documention. More modern successor products like Visual COBOL do have on-line training courses available.


You can set the system-wide default printer for the current user using the Windows API function SetPrinterDefault. One way you can do this is with the following program:

       id division.                                              
       program-id. Program1.                                     
       environment division.                                     
       configuration section.                                    
       special-names.                                            
          call-convention 66 is winapi.                          
                                                                 
       data division.                                            
       working-storage section.                                  
       01 printer-name pic x(80) value spaces.                   
       01 status-code  pic x(4) comp-5 value zeroes.             
       01 pp procedure-pointer.                                  
       procedure division.                                       
           set pp to entry "kernel32"                            
           call winapi "LoadLibraryA"                            
              using z"winspool.drv"                              
              returning pp                                       
           end-call                                              
           call winapi "GetProcAddress"                          
              using by value pp                                  
                    by reference z"SetDefaultPrinterA"           
              returning pp                                       
           end-call                                              
           move z"Microsoft Print to PDF" to printer-name        
                                                                 
           call pp                                               
              using printer-name                                 
              returning status-code                              
           end-call                                              
                                                                 
           if status-code not = 0                                
              display "Default Printer Changed"                  
           else                                                  
              display "Default Printer Not Changed!"             
           end-if                                                
                                                                 
           goback.                                               

Are you looking to learn COBOL or the Net Express product. There are hundreds of books and courses for learning COBOL. Net Express 4.0 is an extremely old product and hasn't been supported in years. My suggestion for beginning training in this product is to go thru the tutorials in the documention. More modern successor products like Visual COBOL do have on-line training courses available.

The program has hundreds of subprograms. Migration to a newer version of Cobol or another language will be some kind of suicide. It is developed for some financial work where they don't need fancy things and etc. Only representing data in character mode or in PDF documents. Cobol 4 is super strong for that and can work on a very bad computer! Maybe, one day I migrate it to a newer language.  A lot of today's language is some kind of garbage. They are very slow, requesting strong hardware.

I am interested in using Net Express 4 IDE for developing programs, Application Server 4. I think the version of Cobol is also 4.

Regards,
Ivan