Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem with Printersetcurrent()

0 views
Skip to first unread message

Wristdoc

unread,
Oct 25, 2000, 3:00:00 AM10/25/00
to
I have a frustrating problem. I use the procedure below many times in my
programs to change the printer (i.e. to Winfax, to HP Laserjet 5L, etc). My
automation programs also use this "selectprinter" procedure in forms which
automatically wake up overnight to fax things off.

Problem... half of the time this "selectprinter" procedure abruptly ends on
the Printersetcurrent command. It gives no error and the form which it belongs
to closes unexpectedly.

If I run the form myself in the Paradox ver8 environment... it always works
perfectly. The only culprit I can think of is that all of the code in the form
is in its "init" method. This is what lets the form automatically do its
processing unattended. My form's init method follows the *****************
lines below.

I hate to ask for help but truely have been trying to debug this problem for
over a month myself without success.

Proc selectprinter(printername string) logical
var
arPrinters,arPrnNames Array[] String
stPrnInfo String
i SmallInt
logfile textstream
endVar
enumPrinters(arPrinters) ; Get a list of installed printers.
for i from 1 to arPrinters.size()
stPrnInfo = arPrinters[i]
stPrnInfo.breakApart(arPrnNames, ",")
if upper(arPrnNames[1]) = upper(printername) then
if readenvironmentstring("Automationcall")="True" and
if printerSetCurrent(stPrnInfo) then
return true
else
errorShow()
return false
endIf
endIf
endFor
return false
endproc

*************************************************************
*************************************************************
method init(var eventInfo Event)

var
prninfo printerinfo
logfile textstream
endvar

dodefault

printergetinfo(prninfo)
icurrentprinter=prninfo.devicename

thisformname=":medisoftreports:Form - Office schedule printfax.fsl"
calledreport=":medisoftreports:Report - Office schedule printfax.rsl"
ignorecaseinstringcompares(yes)
automationcall=readenvironmentstring("Automationcall")
if automationcall<>"True" then
ifaxnum="14143852748"
iprintdate=""
faxrecip=""
istatus="Next click print or fax"
else
;writeenvironmentstring("Automationcall","False") ;prevent retriggering
formname=ltrim(rtrim(readenvironmentstring("Automationformname")))
printto=ltrim(rtrim(readenvironmentstring("Automationprintername")))
faxnum=ltrim(rtrim(readenvironmentstring( "Automationfaxnumber")))
faxrecip=ltrim(rtrim(readenvironmentstring("Automationfaxrecipient")))
parameters=ltrim(rtrim(readenvironmentstring("Automationparameters")))
if parameters="tomorrow" then
if doword(today())=6 then
iprintdate=string(date(dateval(today())+3))
else
if doword(today())=7 then
iprintdate=string(date(dateval(today())+2))
else
iprintdate=string(date(dateval(today())+1))
endif
endif
else
if (parameters="today") or (parameters="") then
iprintdate=string(date(dateval(today())+0))
else
iprintdate=parameters
endif
endif

if printto<>"" then printlocalbutton.pushbutton() endif
if faxnum<>"" then ifaxnum=faxnum faxbutton.pushbutton() endif
close()

endif
endMethod

Bill Sparrow

unread,
Oct 27, 2000, 8:31:00 AM10/27/00
to
I guess the code you have posted is not your actual code, as there is a
syntax error.

if readenvironmentstring("Automationcall")="True" and
if printerSetCurrent(stPrnInfo) then

If you remove the second if...

if readenvironmentstring("Automationcall")="True" and

printerSetCurrent(stPrnInfo) then

then that tidies up the syntax, but that results in a logic error. As
Paradox does not do lazy evaluation of logical expressions, it will still
call printerSetCurrent if the first part of the expression is false.

If you replace the "and" with "then", you will also need to add another
endif, and indent some lines a bit.

if upper(arPrnNames[1]) = upper(printername) then

if readenvironmentstring("Automationcall")="True" then


if printerSetCurrent(stPrnInfo) then
return true
else
errorShow()
return false
endIf

endif
endIf

Whether that will work or not I don't know.

But I can tell you that I have had some strange problems with
printerSetCurrent and WinFax. It seems that printerSetCurrent only does
half the job. After using it to select the Winfax printer, the font
rendering was all wrong, resulting in text that was cropped within its
bounding rectangles. The only way I found to fix it was to use sendKeys
to open the printer setup dialog and close it again. This seemed to
confirm the change of printer. I guess something in Windows or the
printer driver was not getting notified of the change of printer without
this.

--Bill Sparrow--
Member of the UK Borland User Group

Wristdoc

unread,
Oct 27, 2000, 10:52:03 PM10/27/00
to
Sorry about the line with the Automationcall=true. This is not part of my
actual code but was a left over debugging line which I forgot to delete before
posting.

My real curiousity is how does the printersetcurrent command problem totally
close my form when the problem occurs.

Bill Sparrow

unread,
Oct 30, 2000, 3:31:00 PM10/30/00
to
Sorry. I have no idea.
0 new messages