S
StrandElectric
This works fine aligning the figures for my financial reports (apolgies for
the double linespacing) BUT note the first imports line. Can anyone suggest
a modified coding that does not need this line(anticipating that support for
it may weell disappear...) it is the p.xxx lines that don't work. looks like
the others will.
Imports Microsoft.VisualBasic.PowerPacks.Printing.Compatibility.VB6
Imports System.Drawing
'Added a reference to: Microsoft.VisualBasic.PowerPacks.Vs
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
TestLabel.Text = "starting"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
PrintSample()
End Sub
Private Sub PrintSample()
'Dim col() As Integer
'ReDim col(0 To 3)' if presetting columns
' col(0) = 20... etc
Dim p As New printer
p.PrintAction = Printing.PrintAction.PrintToPrinter 'in System.Drawing
namespace
p.ScaleMode = vbMillimeters ' changed from twips
p.Orientation = vbPRORPortrait ' orientation
p.PaperSize = vbPRPSA4 ' paper size
p.Font = New Font("Arial", 12, FontStyle.Regular)
Dim PrintDialog1 As New PrintDialog() 'just shows dialog and doesn't use it
PrintDialog1.ShowDialog() 'more coding to do to read the ouput from the
dialog
Me.Refresh()
Dim AlanVariable As Decimal = 1234.56 ' experiment
Dim AnotherVariable As Decimal = 45.1 'experiment
Dim ThirdVariable As Decimal = 651.11 ' experiment
Dim FourthVariable As Decimal = 9 ' experiment
'the format produces 2 decimal points
'the TextWidth allows alignment (right) decimal
'the decimals line up perfectly here despite '1', '0' and a proportional
font
p.CurrentY = 80
p.CurrentX = 100 - p.TextWidth(Format(AnotherVariable, "#,###0.00"))
p.Write(Format(AnotherVariable, "#,###0.00"))
p.CurrentY = 85
p.CurrentX = 100 - p.TextWidth(Format(AlanVariable, "#,###0.00"))
p.Write(Format(AlanVariable, "#,###0.00"))
p.CurrentY = 90
p.CurrentX = 100 - p.TextWidth(Format(ThirdVariable, "#,###0.00"))
p.Write(Format(ThirdVariable, "#,###0.00"))
p.CurrentY = 95
p.CurrentX = 100 - p.TextWidth(Format(FourthVariable, "#,###0.00"))
p.Write(Format(FourthVariable, "#,###0.00"))
'p.NewPage() if required (could increment a Line counter)
p.EndDoc()
End Sub
End Class
the double linespacing) BUT note the first imports line. Can anyone suggest
a modified coding that does not need this line(anticipating that support for
it may weell disappear...) it is the p.xxx lines that don't work. looks like
the others will.
Imports Microsoft.VisualBasic.PowerPacks.Printing.Compatibility.VB6
Imports System.Drawing
'Added a reference to: Microsoft.VisualBasic.PowerPacks.Vs
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
TestLabel.Text = "starting"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
PrintSample()
End Sub
Private Sub PrintSample()
'Dim col() As Integer
'ReDim col(0 To 3)' if presetting columns
' col(0) = 20... etc
Dim p As New printer
p.PrintAction = Printing.PrintAction.PrintToPrinter 'in System.Drawing
namespace
p.ScaleMode = vbMillimeters ' changed from twips
p.Orientation = vbPRORPortrait ' orientation
p.PaperSize = vbPRPSA4 ' paper size
p.Font = New Font("Arial", 12, FontStyle.Regular)
Dim PrintDialog1 As New PrintDialog() 'just shows dialog and doesn't use it
PrintDialog1.ShowDialog() 'more coding to do to read the ouput from the
dialog
Me.Refresh()
Dim AlanVariable As Decimal = 1234.56 ' experiment
Dim AnotherVariable As Decimal = 45.1 'experiment
Dim ThirdVariable As Decimal = 651.11 ' experiment
Dim FourthVariable As Decimal = 9 ' experiment
'the format produces 2 decimal points
'the TextWidth allows alignment (right) decimal
'the decimals line up perfectly here despite '1', '0' and a proportional
font
p.CurrentY = 80
p.CurrentX = 100 - p.TextWidth(Format(AnotherVariable, "#,###0.00"))
p.Write(Format(AnotherVariable, "#,###0.00"))
p.CurrentY = 85
p.CurrentX = 100 - p.TextWidth(Format(AlanVariable, "#,###0.00"))
p.Write(Format(AlanVariable, "#,###0.00"))
p.CurrentY = 90
p.CurrentX = 100 - p.TextWidth(Format(ThirdVariable, "#,###0.00"))
p.Write(Format(ThirdVariable, "#,###0.00"))
p.CurrentY = 95
p.CurrentX = 100 - p.TextWidth(Format(FourthVariable, "#,###0.00"))
p.Write(Format(FourthVariable, "#,###0.00"))
'p.NewPage() if required (could increment a Line counter)
p.EndDoc()
End Sub
End Class