Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Fri Nov 16, 2018 5:27 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: Printing
PostPosted: Sat Oct 01, 2005 9:55 pm 
Offline

Joined: Fri Sep 30, 2005 9:34 am
Posts: 44
Hello all...

I need some help, since I'm apparently slow and just can't figure this out...

I want to print the contents of a listbox. Can that be done? Can someone point me in the right direction (or provide a snippet of code?)....

Thanks.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Oct 02, 2005 3:58 am 
Offline
User avatar

Joined: Fri Sep 30, 2005 8:05 am
Posts: 61
Location: Edinburgh, Scotland
Really quick and dirty:
Dim g As Graphics = OpenPrinterDialog ()
Dim StartHeight As Integer = 100

If g<> Nil then
For y As Integer = 0 to Listbox1.ListCount - 1
For x As Integer = 0 to Listbox1.ColumnCount - 1

g.DrawString ListBox1.Cell(y, x), (x*ListBox1.Column(x).WidthActual), (y*30)+StartHeight
Next
Next
End if

_________________
Charlie Boisseau
[ My Site | My Blog | Net Tool Box ]


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Oct 02, 2005 6:56 am 
Offline
User avatar

Joined: Fri Sep 30, 2005 3:53 pm
Posts: 3261
Location: England
Charlie Boisseau wrote:
Really quick and dirty:


Or, if you're looking for something a bit more considered, there's a nice Listbox printer module at CallerID.com

_________________
Steve Garman
Using REALbasic 2008r2 Professional on Windows Vista Ultimate
and REALbasic 2009r5.1 Professional on Linux Ubuntu 9.04 Desktop
and REAL Studio 2010r1 Personal on Linux Ubuntu 9.10 Desktop
Occasional blog


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Oct 02, 2005 1:55 pm 
Offline

Joined: Fri Sep 30, 2005 9:34 am
Posts: 44
Charlie Boisseau wrote:
Really quick and dirty:
Dim g As Graphics = OpenPrinterDialog ()
Dim StartHeight As Integer = 100

If g<> Nil then
For y As Integer = 0 to Listbox1.ListCount - 1
For x As Integer = 0 to Listbox1.ColumnCount - 1

g.DrawString ListBox1.Cell(y, x), (x*ListBox1.Column(x).WidthActual), (y*30)+StartHeight
Next
Next
End if


Charlie,

Thanks so much.... a quick question...

I'm losing my first and third column in the printing process..... It's printing columns 2 and 3, but not 1 and 4. Is there something I should be tweaking in your snippet?

Thanks again. I truly appreciate this!


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Oct 02, 2005 3:23 pm 
Offline
User avatar

Joined: Fri Sep 30, 2005 8:05 am
Posts: 61
Location: Edinburgh, Scotland
It works for me. Maybe check your column widths are ok. Also, you may want to check pagesetup info before printing. You should read all the docs on the Language ref.

_________________
Charlie Boisseau
[ My Site | My Blog | Net Tool Box ]


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Oct 02, 2005 4:54 pm 
Offline

Joined: Fri Sep 30, 2005 9:34 am
Posts: 44
Charlie Boisseau wrote:
It works for me. Maybe check your column widths are ok. Also, you may want to check pagesetup info before printing. You should read all the docs on the Language ref.


I'm sorry. I'm new at this, so forgive my ignorance.

What should I check about the column widths? My column widths are 35,110,110 and 380.

All the data appears in the list box itself.....

What am I doing wrong?


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Oct 02, 2005 6:12 pm 
Offline

Joined: Fri Sep 30, 2005 9:30 pm
Posts: 1712
Location: U.S.A.
I don't know if this is any better. It does basically the same thing in a slightly different way. We just upgraded to XP x64, so our printer doesn't work, but it worked Ok when sending output to a edit field.

dim s as String
dim i, j as integer
dim g as Graphics

j = ListBox1.ListCount - 1

for i = 0 to j
//Single column listBox
's = s + ListBox1.List(i) + chr(10)
//Multi-column listBox
s = s + ListBox1.Cell(i, -1) + chr(10)
next i
'Send s to printer as graphics object


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Oct 02, 2005 8:59 pm 
Offline

Joined: Fri Sep 30, 2005 9:30 pm
Posts: 1712
Location: U.S.A.
I finally found it. The code I used to print is this:

dim g as graphics
g = openPrinter()
g.textFont = "Courier"
g.textSize = 8
g.DrawString s, 50, 50


In this case, the string "s" is the source. I'm not sure how this works with word wrap. That might be what the two optional values handle.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Oct 06, 2005 1:32 am 
Offline

Joined: Sat Oct 01, 2005 5:19 pm
Posts: 3216
It doesn't work for word wrap as you must stipulate at what width the wrap takes place at.

You don't need a printer to test your prints, Think of the paper as a canvas, so if you draw to canvas instead of the paper, you'll know exactly what it looks like.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Oct 06, 2005 6:55 pm 
Offline

Joined: Fri Sep 30, 2005 9:34 am
Posts: 44
Jen's code works, but where a space should be between the columns, I get a litte 'square' box instead....

So, now what am I doing wrong? Is there a way to fix that?

Thanks in advance.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Oct 06, 2005 7:20 pm 
Offline

Joined: Fri Sep 30, 2005 9:30 pm
Posts: 1712
Location: U.S.A.
Drawing to a canvas is a good idea. I will try that. I hope to have a new printer soon.

If you are getting a box that means your printer is not recoqnizing the chr(10) code. Try endOfLine. It might even be something diferent on Mac. I can't remember for sure.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Oct 06, 2005 7:23 pm 
Offline

Joined: Fri Sep 30, 2005 9:30 pm
Posts: 1712
Location: U.S.A.
Between columns? That may be something different, but try it just to see. If it is the Chr(10) causing problems, I would expect to see a square at the end of each row.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Oct 07, 2005 12:28 pm 
Offline

Joined: Sat Oct 01, 2005 5:19 pm
Posts: 3216
Speaking from a Win32 box, a square box could be numerous things, but generally it means it's a charactor that the Font you are using doesn't have. Windows for example uses chr(13) +chr(10) for a line return and maybe one or the other is causing it to line return and the other is giving you a square. What you can do is replace all the different line returns with EndOfLine before printing.

You need to do it in this order or you will get a double EndOfLine for the chr(13) + chr(10)

replaceAll(string_to_be_printed, chr(13) + chr(10), EndOfLine)
replaceAll(string_to_be_printed, chr(13), EndOfLine)
replaceAll(string_to_be_printed, chr(10), EndOfLine)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group