?
Solved

Print to file with PB5.0 in Win2000

Posted on 2003-03-10
7
Medium Priority
?
306 Views
Last Modified: 2013-12-26
I need to print to a file from a datawindow retrieve in my PB5.0 app running under Windows 2000.  Running under Windows NT there are no problems with this - RegistryGet for current print device, RegistrySet to change print device to generic text, PrintOpen(), PrintDataWindow(), PrintClose() and then another RegistrySet to the original print device.  But running in Windows 2000, the PrintOpen() command fails with a -1 return.  I can't seem to find anything on how to get this work from Windows 2000.
0
Comment
Question by:mmmoore3
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 5

Accepted Solution

by:
buasuwan earned 1000 total points
ID: 8104452
Hi,
 I think, setting default printer with RegistrySet() will not work on Windows 2000, XP.
 
 You need to use an External Function for
setting default printer.

1.declare External Function.

Function boolean SetDefaultPrinter(string printer_name) Library "winspool.drv" Alias for "SetDefaultPrinterA"

2.set default printer...before PrintOpen(...)

SetDefaultPrinter("your printer name")
0
 

Author Comment

by:mmmoore3
ID: 8105091
This option doesn't resolve the problem.  I can see in the registry that the update is successful using RegistrySet(), but the real problem appears to be with the PrintOpen() which returns -1.  Is there another method to declare a print job in PB 5.0 since PrintClose() doesn't seem to work in Windows 2000?
0
 
LVL 5

Expert Comment

by:buasuwan
ID: 8109407
RegistrySet() or setting win.ini are not enough for setting default printer on 2000 and XP.

Yes, you can see the update printer name in registry, It does not mean that default printer was changed to what you want.

Have you been try my codes?

ulong li_job

SetDefaultPrinter("HP LaserJet 1100 (MS)")
li_job = PrintOpen()

PrintClose(li_job)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:mmmoore3
ID: 8129979
Well, I'm not REALLY trying to change the printer.  What I need to do is print a datawindow to a file (a text file).  I found the following from the datawindow syntax info that ships with PowerBuilder.  Unfortunately, while it produces a viewable text file from WinNT, it results in garbage output from Win2000.

dw_1.Object.DataWindow.Print.Filename = "MyReportFile.Name"
dw_1.Print()

So I'm looking for any method to use to have a datawindow.Print() command write to a viewable text file.

0
 

Author Comment

by:mmmoore3
ID: 8130334
I tried using SetDefaultPrinter as shown below to write to a file.  It doesn't throw an error, but it physically prints on my default printer instead of writing to the specified file.

ulong li_job
SetDefaultPrinter(lv_gentxt_driver_name)
//argument is "GENTEXT,,C:\PROJECTS\10810210.txt"
li_job = PrintOpen()
li_ret = PrintDataWindow(li_job, dw_1);
PrintClose(li_job)

0
 
LVL 5

Expert Comment

by:buasuwan
ID: 8134080
>it results in garbage output from Win2000.
It sounds like a problem in 'GENTEXT' Printer Driver Setting.

please check printer driver properties on tab 'Device Options', 'Fonts'.

is it the same as NT settting?


0
 
LVL 5

Expert Comment

by:buasuwan
ID: 8145589
sorry, i see 2 wrong codings.

if you want to use 'PrintOpen', and your result will be printed through GENTEXT printer.

ulong li_job, li_ret
SetDefaultPrinter("GENTEXT")
li_job = PrintOpen()
li_ret = PrintDataWindow(li_job, dw_1);
PrintClose(li_job)

or if you want to use dw_1.Print(). you can print to file that you want, then your code should be.

SetDefaultPrinter("GENTEXT")
dw_1.Object.DataWindow.Print.Filename = "C:\10810210.txt"
dw_1.Print()

if you still getting garbage result.
what's it look like?
1.ƒÌƒ €*b8W Ã
2. ..... or ??????  

the first garbage, that means your printer doesn't support printing text.

and second garbage, means that you need to set 'CodePage' to match your character set. you can choose 'CodePage' from printer driver->tab font->code page.


0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question