Printing the Contents of a ListBox

Hi all,

I’m currently running a ListBox, where each column generates numerical data from a For/Next loop. The loop is exited when the last column in the ListBox generates a data value of a certain number. Therefore, while I know the absolute max number of rows the ListBox could have, on any given run of the program the ListBox could be a variety of row numbers in length.

I am looking to print the ListBox. It doesn’t have to be in some sort of “pretty” Report format, just a coded way to print what is displayed in the ListBox at any given time. Does anyone have a suggestion?

Thanks!

You could loop through the listbox and assemble a HTML based table. Save that out as a text file with a .htm extension and then tell the machine to natively open that file with a browser. Hmm. Perhaps you meant to automatically send it to a printer without interaction?

Look at Bens Listbox extras at Ben's Software - REALbasic Stuff. I believe it has a printing routine (if you didn’t want to roll your own).

Otherwise, take a look at the PrinterSetup class http://documentation.xojo.com/index.php/PrinterSetup which can do the OpenPrinterDialog and return the Graphics object. Then it’s a matter of determining X, Y location and the string for the graphics.DrawString method.

I’d be remiss in saying this wouldn’t be very hard to do with the built-in Reporting tool (take a look at GasReport example) or our own BKeeney Shorts reporting tool.

Xojo includes an example to show you how to output a ListBox to a Report, which makes it pretty easy to print:

Examples/Printing and Reporting/Reporting/ListBoxReport

You could try my ListboxPrinter class.

https://dl.dropboxusercontent.com/u/10747116/RealStudioClasses/sbListboxPrinter.zip

This started life as Alex Restreppo’s ListboxPrinter that I have extensively modified to print page numbers, draw lines etc.

[quote=87941:@Simon Berridge]You could try my ListboxPrinter class.

https://dl.dropboxusercontent.com/u/10747116/RealStudioClasses/sbListboxPrinter.zip

This started life as Alex Restreppo’s ListboxPrinter that I have extensively modified to print page numbers, draw lines etc.[/quote]
Amazing!, How did you change the Text Size?

You can try my new sbPrinter set of classes.

These classes allow you to print like an spreadsheet.

Have a look at the project, download here: https://dl.dropboxusercontent.com/u/10747116/RealStudioClasses/sbPrinter.zip

Simon.

[quote=196356:@Simon Berridge]You can try my new sbPrinter set of classes.

These classes allow you to print like an spreadsheet.

Have a look at the project, download here: https://dl.dropboxusercontent.com/u/10747116/RealStudioClasses/sbPrinter.zip

Simon.[/quote]
Thanks very much

You’re welcome.

S.