Wrote an Application that prints special labels, entry and printing worked perfectly.
Created an executable, again all working fine.
The next week I tried to run the executable and print, I got an exception of class NilObjectException was not handled.
Tried running the program in xojo, I had some problems with it stopping at the following command
dim w as WindowsPrinterMBS = WindowsPrinterMBS.OpenPrinter(Name)
if w.ChangePrinterSettings(d, 2) Then
Made some changes and fixed the error and it was printing correctly again, built an executable and got the NilObjectException error again.
Does anyone have any suggestions? Following is the code.
dim OrgDfltPrt as String
dim MyShell as new shell
Myshell.execute “wmic printer where default=‘TRUE’ get name”
DfltPrt = Myshell.Result
dim d as new WindowsDeviceModeMBS
dim Name as string
Name = DfltPrt
// here we define which values we want to change
d.Fields = d.DM_PAPERSIZE + d.DM_PAPERLENGTH + d.DM_PAPERWIDTH + d.DM_PRINTQUALITY
d.Papersize = 256
d.Paperlength = ContinuousLab_Length * 254 ’ continuousLab_Length = 1" to 20"
d.PaperWidth = 3.54 * 254
d.PrintQuality = 300
dim w as WindowsPrinterMBS = WindowsPrinterMBS.OpenPrinter(Name)
if w.ChangePrinterSettings(d, 2) Then
MessageBox(“Error - could not set the page length.”)
exit sub
end if
dim g as Graphics
dim ps as PrinterSetup
ps = new PrinterSetup
if ps <> nil then
ps.MaximumHorizontalResolution = -1
ps.MaximumVerticalResolution = -1
g = openprinter(ps)
If g <> Nil Then
PrintLabel(g, Ps)
call ClearPrintWin
if OrgDfltPrt <> DfltPrinter then
call ChangeDefaultPrinter(OrgDfltPrt)
end if
if EntryStatus = 2 then
call ExitDieCont
end if
end if
end if