A case of virtual beer in exchnage for print info!

S

StrandElectric

Hi all

No-one has yet got back to me indicating how in vb.net I can address the
printer properly and print nicely formatted columns of information as I
could with vb6. Having made considerable headway with vb.net, and being
persuaded that it is a very flexible system with many options, I am sure it
must be possible (but possibly undocumented?). I do not want to print a
copy of the form on the screen. I want to print variables by name in the
horizontal position that I choose, preferably simply.

Like this pseudo code:


With Print to Printer
at tab1, MyVariableName
at tab20, MyVariableNet
at tab30, MyVariableGST
at tab40, MyVariableTotal
Linecount = Linecount +1
End With

If linecount >50 then
Lincount =0
NextPage
End If

(I've posted actual vb6 code earlier)

Also, it would be nice to access the printer dialogue box to check which of
my printers I wish to use (failing that I'd go for the default printer). I
definitely want to be able to code portrait or landscape according to the
(financial report) I want to print, like this psedo code at the start of
each report.

Like this pseudo code

Choose Printer.Orientation = Portrait

Any takers? Needing less than 10,000 lines of code please (only kidding
this last bit...)
 
T

Tom Shelton

StrandElectric explained :
Hi all

No-one has yet got back to me indicating how in vb.net I can address the
printer properly and print nicely formatted columns of information as I could
with vb6. Having made considerable headway with vb.net, and being persuaded
that it is a very flexible system with many options, I am sure it must be
possible (but possibly undocumented?). I do not want to print a copy of the
form on the screen. I want to print variables by name in the horizontal
position that I choose, preferably simply.

Like this pseudo code:


With Print to Printer
at tab1, MyVariableName
at tab20, MyVariableNet
at tab30, MyVariableGST
at tab40, MyVariableTotal
Linecount = Linecount +1
End With

If linecount >50 then
Lincount =0
NextPage
End If

(I've posted actual vb6 code earlier)

Also, it would be nice to access the printer dialogue box to check which of
my printers I wish to use (failing that I'd go for the default printer). I
definitely want to be able to code portrait or landscape according to the
(financial report) I want to print, like this psedo code at the start of each
report.

Like this pseudo code

Choose Printer.Orientation = Portrait

Any takers? Needing less than 10,000 lines of code please (only kidding this
last bit...)

I thought the vb power pack had some sort of printer thing similar to
VB6? Not sure though.

This may sound funny, but, I've never really done much printing in
either vb.net or even vb.classic :) So, I can't really advise you on
this much.

Did find this article that SEEMS, though I haven't really tried it, to
cover printing in VB.NET:

http://www.dreamincode.net/forums/topic/44150-printing-in-vbnet/

At least the basics :)
 
S

StrandElectric

Tom Shelton said:
StrandElectric explained :

I thought the vb power pack had some sort of printer thing similar to VB6?
Not sure though.

This may sound funny, but, I've never really done much printing in either
vb.net or even vb.classic :) So, I can't really advise you on this much.

Did find this article that SEEMS, though I haven't really tried it, to
cover printing in VB.NET:

http://www.dreamincode.net/forums/topic/44150-printing-in-vbnet/

At least the basics :)
Well Tom, I strugggled with that reference. I understood the Imports
commands but very little else, and certainly not the code that began with
#Region and used the three single quotes '''. Are those valid starts to a
line? Altogether far too long and also abstract.

It is difficult to imagine anyone in the real world neglecting printing in a
so-called serious tool that will be used in eg financial packages... And
putting it in the 'next framework' is no answer because that means any
application using it won't work in previous frameworks and can't be
presented as a universal exe file that anyone can use.

I've looked for it but can't find the syntax to use for bringing in vb6-like
printing. Can someone tell me again?
 
D

Dennis

This may sound funny, but, I've never really done much printing in
either vb.net or even vb.classic :) So, I can't really advise you on
this much.

I had a customer who wanted to be able to print a DataGridView. I found
a C# class online that did the job.

Other than that, I haven't had the need to do any printing DIRECTLY from
..Net. What I do instead is either write my columnar output to a CSV file
(and open it in the default spreadsheet program), or emit HTML (and open
it in the default browser). I find this approach better than sending
data directly to a printer.
 
T

Tom Shelton

StrandElectric explained :
Well Tom, I strugggled with that reference. I understood the Imports commands
but very little else, and certainly not the code that began with #Region and
used the three single quotes '''. Are those valid starts to a line?
Altogether far too long and also abstract.

The three ' are xml comments. They are used to generate documentation
from the code comments.

The #Region stuff is so that you can have collapsable sections in your
code. The don't do anything with your code.

As for, using the stuff in the powerpack, it should be install it, add
the reference, use the import statement and write code.

It is difficult to imagine anyone in the real world neglecting printing in a
so-called serious tool that will be used in eg financial packages...

Why do you say that? I've done lots of serious applications, but
printing was never a requirement. Even when I have done stuff that
needed to generate documents, I either generated PDF or XPS documents
and let the user print them from the viewer - no need for me to write
any printing code.
And
putting it in the 'next framework' is no answer because that means any
application using it won't work in previous frameworks and can't be presented
as a universal exe file that anyone can use.

I don't know what you mean by that? Printing is in the .NET framework.
Has been all along... I just haven't had a reason to use it that
much.
 
T

Tom Shelton

Dennis was thinking very hard :
I had a customer who wanted to be able to print a DataGridView. I found
a C# class online that did the job.

Other than that, I haven't had the need to do any printing DIRECTLY from
.Net. What I do instead is either write my columnar output to a CSV file
(and open it in the default spreadsheet program), or emit HTML (and open
it in the default browser). I find this approach better than sending
data directly to a printer.

For formated stuff, I've generally used stuff like ITextSharp to
generate PDF's or used the frameworks support for XPS :)
 
A

Armin Zingler

Am 24.01.2011 19:44, schrieb StrandElectric:
I've looked for it but can't find the syntax to use for bringing in vb6-like
printing. Can someone tell me again?

There is no "vb6-like printing" in .Net. It's up to you now to learn some
basics before trying to understand things that required prior knowledge.
I know that you don't accept this, but I can only tell you the truth.
 
J

Jason Keats

Armin said:
Am 24.01.2011 19:44, schrieb StrandElectric:

There is no "vb6-like printing" in .Net. It's up to you now to learn some
basics before trying to understand things that required prior knowledge.
I know that you don't accept this, but I can only tell you the truth.


There certainly IS VB6-like printing available in .NET.

Just add a reference to: Microsoft.VisualBasic.PowerPacks.Vs

Then put
Imports Microsoft.VisualBasic.PowerPacks.Printing.Compatibility.VB6
Imports System.Drawing

at the top of your code page, then try something like...

Private Sub PrintSample()

Dim col() As Integer

ReDim col(0 To 3)
col(0) = 1000
col(1) = 3000
col(2) = 5000
col(3) = 7000

Dim p As New Printer

p.PrintAction = Printing.PrintAction.PrintToPrinter 'in
System.Drawing namespace

p.ScaleMode = vbTwips
p.PaperSize = vbPRPSA4

'p.Font = New Font("Arial", 20, FontStyle.Bold Or FontStyle.Italic)
p.Font = New Font("Arial", 10, FontStyle.Regular)

p.CurrentY = 1000
p.CurrentX = 500
p.Print("Page 1")

p.Font = New Font("Arial", 20, FontStyle.Bold)

p.CurrentY = 2000
p.CurrentX = col(0)
p.Print("Zero")

p.CurrentY = 2000
p.CurrentX = col(1)
p.Print("One")

p.CurrentY = 2000
p.CurrentX = col(2)
p.Print("Two")

p.CurrentY = 2000
p.CurrentX = col(3)
p.Print("Three")

p.NewPage()

'Page 2...

p.Font = New Font("Arial", 10, FontStyle.Regular)

p.CurrentY = 1000
p.CurrentX = 500
p.Print("Page 2")

p.Font = New Font("Arial", 20, FontStyle.Italic)

p.CurrentY = 2000

p.CurrentX = col(0)
p.Write("Zero")

p.CurrentX = col(1)
p.Write("One")

p.CurrentX = col(2)
p.Write("Two")

p.CurrentX = col(3)
p.Write("Three")

p.EndDoc()

End Sub

Note that the semi-colon is no longer available to prevent line-feeds.

You will notice the first page uses Print, while the second page uses
Write (much simpler).
 
A

Armin Zingler

Am 24.01.2011 23:49, schrieb Jason Keats:
There certainly IS VB6-like printing available in .NET.

Just add a reference to: Microsoft.VisualBasic.PowerPacks.Vs

Tom mentioned it already in his 1st reply, but it doesn't seem
to be appropriate for Mr. Strand or he accidently overlooked
the suggestion.
 
S

StrandElectric

Tom Shelton said:
Why do you say that? I've done lots of serious applications, but printing
was never a requirement.

Every company I ever ran or had association with produced regular management
financial reports on paper that were studied and discussed at board
meetings.
 
S

StrandElectric

Armin Zingler said:
Am 24.01.2011 19:44, schrieb StrandElectric:

There is no "vb6-like printing" in .Net. It's up to you now to learn some
basics before trying to understand things that required prior knowledge.
I know that you don't accept this, but I can only tell you the truth.

I am learning the basics, and now have an application up that works every
day. But it appears that printing was not any kind of a requirement for the
designers of vb.net. The convoluted code suggests a hurried afterthought.
However, it certainly is for me and no doubt for large numbers of people
wishing to print financial reports. The suggested way of doing it via all
the references I've see so far is absolutely absurd. I'm afraid blaming it
on the ignorance of the person trying to print with straighforward code (me,
this time!) won't wash. I've now read countless references from vb.net
people saying it is a serious omission. It probably means that any further
study is meaningless. But someone here did give detailed code at the head of
the form for allowing vb6.like syntax to work (a kludge I suppose but better
than nothing). I wish I could find it. And to Dennis. I am not talking
about web applications, but form based applications.
 
S

StrandElectric

Jason Keats said:
There certainly IS VB6-like printing available in .NET.

Just add a reference to: Microsoft.VisualBasic.PowerPacks.Vs

Then put
Imports Microsoft.VisualBasic.PowerPacks.Printing.Compatibility.VB6
Imports System.Drawing

at the top of your code page, then try something like...

Private Sub PrintSample()

Dim col() As Integer

ReDim col(0 To 3)
col(0) = 1000
col(1) = 3000
col(2) = 5000
col(3) = 7000

Dim p As New Printer

p.PrintAction = Printing.PrintAction.PrintToPrinter 'in
System.Drawing namespace

p.ScaleMode = vbTwips
p.PaperSize = vbPRPSA4

'p.Font = New Font("Arial", 20, FontStyle.Bold Or FontStyle.Italic)
p.Font = New Font("Arial", 10, FontStyle.Regular)

p.CurrentY = 1000
p.CurrentX = 500
p.Print("Page 1")

p.Font = New Font("Arial", 20, FontStyle.Bold)

p.CurrentY = 2000
p.CurrentX = col(0)
p.Print("Zero")

p.CurrentY = 2000
p.CurrentX = col(1)
p.Print("One")

p.CurrentY = 2000
p.CurrentX = col(2)
p.Print("Two")

p.CurrentY = 2000
p.CurrentX = col(3)
p.Print("Three")

p.NewPage()

'Page 2...

p.Font = New Font("Arial", 10, FontStyle.Regular)

p.CurrentY = 1000
p.CurrentX = 500
p.Print("Page 2")

p.Font = New Font("Arial", 20, FontStyle.Italic)

p.CurrentY = 2000

p.CurrentX = col(0)
p.Write("Zero")

p.CurrentX = col(1)
p.Write("One")

p.CurrentX = col(2)
p.Write("Two")

p.CurrentX = col(3)
p.Write("Three")

p.EndDoc()

End Sub

Note that the semi-colon is no longer available to prevent line-feeds.

You will notice the first page uses Print, while the second page uses
Write (much simpler).

Thanks. This crossed over my post. But what exactly do I code for 'add a
reference to Microsoft.VisualBasic.PowerPack.Vs'?
 
T

Tom Shelton

Thanks. This crossed over my post. But what exactly do I code for 'add a
reference to Microsoft.VisualBasic.PowerPack.Vs'?

You don't know how to use the Add Reference dialog? This is the same
concept as was in VB6 - you need to add a reference to the assembly.

Project -> Add Reference... On the .NET tab, find the assembly, select
it, click ok. You should be good.
 
S

StrandElectric

Armin Zingler said:
Am 24.01.2011 23:49, schrieb Jason Keats:

Tom mentioned it already in his 1st reply, but it doesn't seem
to be appropriate for Mr. Strand or he accidently overlooked
the suggestion.

Neither... or perhaps partly the latter. But what do you mean 'Just add a
refernce'? Wht and where? *This* is the ignorance!
 
A

Armin Zingler

Am 25.01.2011 00:21, schrieb StrandElectric:
I am learning the basics, and now have an application up that works every
day. But it appears that printing was not any kind of a requirement for the
designers of vb.net. The convoluted code suggests a hurried afterthought.
However, it certainly is for me and no doubt for large numbers of people
wishing to print financial reports. The suggested way of doing it via all
the references I've see so far is absolutely absurd. I'm afraid blaming it
on the ignorance of the person trying to print with straighforward code (me,
this time!) won't wash. I've now read countless references from vb.net
people saying it is a serious omission. It probably means that any further
study is meaningless. But someone here did give detailed code at the head of
the form for allowing vb6.like syntax to work (a kludge I suppose but better
than nothing). I wish I could find it. And to Dennis. I am not talking
about web applications, but form based applications.

My point was that the link provided by Tom seems to be a very good written
article. You won't find much better ones. Yet you are not satisfied with it.
That makes me write what I wrote.

BTW, in my profession, for printing I've always been using Crystal Reports
that came along with VB (IIRC in all versions til 2008). Not part of Express
versions. Just for completeness: http://msdn.microsoft.com/en-us/library/bb126227(VS.90).aspx

BTW #2, If I wanted to print columns manually, I'd use the Graphics object's
DrawString method passing a layout rectangle and the required StringFormat.
Once again this is done in the PrintDocument's PrintPage event. This one
sentence is all you need. Here it is:
http://msdn.microsoft.com/en-us/library/21kdfbzs(VS.90).aspx
 
A

Armin Zingler

Am 25.01.2011 00:31, schrieb StrandElectric:
Neither... or perhaps partly the latter. But what do you mean 'Just add a
refernce'? Wht and where? *This* is the ignorance!

I don't consider it being ignorant. It's just that not every author can teach you
everything you need to know before being able to understand the example.
Setting a reference is a basic thing, that's why it is not explained
explicitly. If all required prior knowledge would have to be explained
with every example, all examples sould have a lot of redundant information.
 
C

Cor

Jason,

Not so clever to add the compatibility vb6 namespace, I've seen that it is
(was) still can be used in Framework 4 is it at the end of its lifetime.

Cor

"Jason Keats" wrote in message

Armin said:
Am 24.01.2011 19:44, schrieb StrandElectric:

There is no "vb6-like printing" in .Net. It's up to you now to learn some
basics before trying to understand things that required prior knowledge.
I know that you don't accept this, but I can only tell you the truth.


There certainly IS VB6-like printing available in .NET.

Just add a reference to: Microsoft.VisualBasic.PowerPacks.Vs

Then put
Imports Microsoft.VisualBasic.PowerPacks.Printing.Compatibility.VB6
Imports System.Drawing

at the top of your code page, then try something like...

Private Sub PrintSample()

Dim col() As Integer

ReDim col(0 To 3)
col(0) = 1000
col(1) = 3000
col(2) = 5000
col(3) = 7000

Dim p As New Printer

p.PrintAction = Printing.PrintAction.PrintToPrinter 'in
System.Drawing namespace

p.ScaleMode = vbTwips
p.PaperSize = vbPRPSA4

'p.Font = New Font("Arial", 20, FontStyle.Bold Or FontStyle.Italic)
p.Font = New Font("Arial", 10, FontStyle.Regular)

p.CurrentY = 1000
p.CurrentX = 500
p.Print("Page 1")

p.Font = New Font("Arial", 20, FontStyle.Bold)

p.CurrentY = 2000
p.CurrentX = col(0)
p.Print("Zero")

p.CurrentY = 2000
p.CurrentX = col(1)
p.Print("One")

p.CurrentY = 2000
p.CurrentX = col(2)
p.Print("Two")

p.CurrentY = 2000
p.CurrentX = col(3)
p.Print("Three")

p.NewPage()

'Page 2...

p.Font = New Font("Arial", 10, FontStyle.Regular)

p.CurrentY = 1000
p.CurrentX = 500
p.Print("Page 2")

p.Font = New Font("Arial", 20, FontStyle.Italic)

p.CurrentY = 2000

p.CurrentX = col(0)
p.Write("Zero")

p.CurrentX = col(1)
p.Write("One")

p.CurrentX = col(2)
p.Write("Two")

p.CurrentX = col(3)
p.Write("Three")

p.EndDoc()

End Sub

Note that the semi-colon is no longer available to prevent line-feeds.

You will notice the first page uses Print, while the second page uses
Write (much simpler).
 
C

Cor

BTW, in my profession, for printing I've always been using Crystal Reports
that came along with VB (IIRC in all versions til 2008). Not part of Express
versions. Just for completeness:
http://msdn.microsoft.com/en-us/library/bb126227(VS.90).aspx

As this was in fact also with VB6.

Not that I like Crystal Reports, be aware Crystal reports was not free with
VB6 and is neither with any newer version.

Cor
 
C

Cor

See the messages from Armin and me about Crystal reports, mostly we see this
not as VB printing.

Cor

"StrandElectric" wrote in message

Tom Shelton said:
Why do you say that? I've done lots of serious applications, but printing
was never a requirement.

Every company I ever ran or had association with produced regular management
financial reports on paper that were studied and discussed at board
meetings.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top