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
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
My real curiousity is how does the printersetcurrent command problem totally
close my form when the problem occurs.