WebListBox NilObjectException

Hi, I am working on Xojo2017r1.1 with MBS plugins installed(I’m working on this release due to bieng told to check on an old project).
I was assigned to make a button which saves the contents of a WebListBox into a .pdf . I used DynaPDF plugin in order to make it possible, and so far I do get the file downloaded but it´s corrupted/empty, and in xojo i get the error “NilObjectException”.

Dim f as FolderItem = SpecialFolder.Desktop.child("test2.pdf")
Dim pdfOut As TextOutputStream = TextOutputStream.Create(f)
Dim pdf as MyDynaPDFMBS
dim intX, intY as integer
dim TableWidth as integer = 2000
'call pdf.SetFont("Helvetica", 12)

// creates table

dim ColumnCount as integer = lb.ColumnCount
const AllColumns = -1
const AllRows = -1
dim ColumnWidths() as Double
redim ColumnWidths(ColumnCount-1)

'Counts columns

dim i as integer
dim strColWidths() As string
dim s as string
s = lb.ColumnWidths
strColWidths =  s.Split(",")
dim bolCol() As Boolean
redim bolCol(strColWidths.Ubound)
dim colsVisible as integer

for i=0 to lb.ColumnCount - 1
  if trim(strColWidths(i))="*" or strColWidths(i).val <> 0 then
    colsVisible =colsVisible +1
    if trim(strColWidths(i))="*" then
      ColumnWidths(colsVisible-1) = -1
      ColumnWidths(colsVisible-1) = strColWidths(i).val
    end if
    bolCol(i) = True
    bolCol(i) = False
  end if
next i

dim SumColumnWidth as Double

for Column as integer = 0 to  colsVisible-1
  if ColumnWidths(Column) > 0 then
    SumColumnWidth = SumColumnWidth + ColumnWidths(Column)
  end if

for i=0 to lb.ColumnCount - 1
  if ColumnWidths(i) = -1 then
    ColumnWidths(i) = lb.Width - SumColumnWidth
    SumColumnWidth = SumColumnWidth + ColumnWidths(i)
    exit for
  end if
next i

dim tbl as DynaPDFTableMBS = pdf.CreateTable(lb.ColumnCount, colsvisible, TableWidth, 100.0)
call tbl.SetBorderWidth(AllRows, AllColumns, 1.0, 1.0, 1.0, 1.0)
'call tbl.SetFont(AllRows, AllColumns, "Helvetica", pdf.kfsNone, false, pdf.kcpUnicode)
call tbl.SetGridWidth( 1.0, 1.0)
call tbl.SetGridHorizontalColor(100, 100, 100)
call tbl.SetGridVerticalColor(100, 100, 100)
call tbl.SetBorderColor(AllRows, AllColumns, 100, 100, 100)

// add header row

dim rowNum as integer = tbl.AddRow
call tbl.SetFlags rowNum, -1, tbl.ktfHeaderRow
dim tblColumn as integer
for Column as integer = 0 to ColumnCount-1
  if bolcol(Column) then
    dim t as string = lb.Heading(Column)
    call tbl.SetCellText rowNum, tblColumn, pdf.ktaLeft,   tbl.kcoCenter, t
    tblColumn = tblColumn +1
  end if

// now fill all the cells

dim c as integer = lb.ColumnCount-1
for Row as integer = 0 to c
  tblColumn = 0
  rowNum = tbl.AddRow
  for Column as integer = 0 to ColumnCount-1
    if bolcol(Column) then
      dim AlignMent as integer = pdf.ktaLeft
      'Select case lb.ColumnAlignment(column)
      'case lb.AlignCenter
      'AlignMent = pdf.ktaCenter
      'case lb.AlignRight
      'AlignMent = pdf.ktaRight
      'end Select
      dim t as string = lb.Cell(row, Column)
      call tbl.SetCellText rowNum, tblColumn, AlignMent,  tbl.kcoCenter, t
      tblColumn = tblColumn +1
    end if

dim dblf as Double
dblf = TableWidth / SumColumnWidth
for Column as integer = 0 to colsVisible-1
  ColumnWidths(Column) = ColumnWidths(Column) * dblf
  call tbl.SetColWidth(Column, ColumnWidths(Column), false)
dim intNewY as integer
intNewY = intY + tbl.GetNumRows * 15

// Draw the table now

call tbl.DrawTable(30.0, intY, 0)
while tbl.HaveMore
  call pdf.EndPage
  call pdf.Append
  call tbl.DrawTable(30.0, 50.0, 0)

'Return intNewY

If there´s anyone who can lend me a helping hand i´ll be extremely greatful.

Since this is a web app I recommend creating in a subfolder of the application folder for the PDF output file because you are going to have to make the file available for download and then delete it once the download by the client is successful. Also for the beginning stages it may be wise to test creating the PDF from a simple desktop app first to work out the code you need to get the PDF you want. You can then migrate the method or module to the web app. Start simple and just output a PDF with one line of text to make sure you get a PDF before doing something more complex.

Did you look at the MBS example called DynaPDF Table from Listbox.xojo_binary_project in the MBS-Xojo-Plugins222\Examples\DynaPDF\Tables folder?

I’ll surely give it glimpse thanks!