|
-
May 11th, 2007, 03:51 AM
#1
Thread Starter
New Member
Printer Alignment
Ok here goes
Im currently Writing a POS System in VB6.its actually quite far
My printing is done on a POS Printer im using the following code that prints the data from a listview and some other controls onto the POS Printer
Printer alignment is my Problem:
vb Code:
ssql = "Select posprinter from [Settings] "
Ocom.CommandText = ssql
Set orec = Ocom.Execute
Dim prnPrinter As Printer
For Each prnPrinter In Printers
If prnPrinter.DeviceName = orec!posprinter Then
Set Printer = prnPrinter
Exit For
End If
Next
'Open Till Draw
Printer.Print "A"
Printer.Font.Size = 9.5
Printer.FontName = "Arial"
Printer.Font.Size = 12
Printer.Font.Bold = True
Set orec = New Recordset
ssql = "Select * from [Company Info]"
Ocom.CommandText = ssql
Set orec = Ocom.Execute
Printer.Print orec!Coname
Printer.Font.Size = 9.5
Printer.FontName = "FontA1x1"
Printer.Print orec!Coline2
Printer.Print orec!coaddress1
Printer.Print orec!coaddress2
Printer.Print orec!coaddress3 + "," + orec!coaddress4
Printer.Print "Tel: " + orec!cophoneno
Printer.Print "Vat Reg: " + orec!coregno
Printer.Font.Size = 19
Printer.FontName = "FontA1x2"
Printer.Print " "
A$ = "TAX INVOICE"
Printer.Print A$
Printer.Font.Size = 9.5
Printer.Font.Size = 9.5
'Printer.FontName = "FontA1x1"
Printer.FontName = "courier new"
Printer.Font.Bold = True
Printer.Print "Customer : " & txtCustomerName
Printer.Print "Date : " & lblDate
Printer.Print "Time : " & lblTime
Printer.Print "Sales Person : " & lblUser
Printer.Print "Slip No : " & InvoiceId
Printer.Print "-----------------------------------------" 'LF
For Each Lst In FrmPOS.lstvInvoice.ListItems
Printer.Print Lst.SubItems(1) & " "
Printer.Print Format(Lst.SubItems(2), "#####0") & " "
Printer.Print Lst.SubItems(4) & " " & Lst.SubItems(10)
Next
Printer.Font.Size = 9.5
Printer.FontName = "Courier New"
'Printer.FontName = "FontA1x1"
Printer.Print "-----------------------------------------" 'LF
Printer.Font.Size = 10
Printer.FontName = "Arial"
Printer.Font.Bold = True
Printer.Print "Total :" + FormatNumber(txtTotal, 2)
Printer.Print "Cash :" + FormatNumber(txtTendered, 2)
Printer.Print "Change :" + FormatNumber(txtChange, 2)
Printer.Font.Size = 9.5
'Printer.FontName = "FontA1x1"
Printer.FontName = "Courier New"
Printer.Font.Bold = True
Printer.Print "Thank you for your Support"
Printer.Print "Visit us: www.distinctiv.net"
Printer.Print "KEEP THIS TILL SLIP AS PROOF OF PURCHASE"
Printer.Print ""
Printer.Print ""
Printer.Print ""
Printer.Print ""
Printer.Print ""
Printer.EndDoc
MsgBox "Please Remove Change and Close Till Draw"
I basically want certain things left aligned and some right aligned
for eg the numeric fields need to be right aligned so that figures line up
Please Assist
Mr Rieda Hoosain
Last edited by Hack; May 11th, 2007 at 06:36 AM.
Reason: Edited EMail address and added VB Highlight Tags
-
May 11th, 2007, 06:37 AM
#2
Re: Printer Alignment
Welcome to the forums. 
I have edited email address in your post.
You should never post a valid email address in an open post on an open forum. Mail spam bots can pick that up and before you know it, your mailbox is full of junk mail.
Thanks.
-
May 11th, 2007, 06:42 AM
#3
Re: Printer Alignment
to right align, you can use printer.currentX = to set the horizantal print position, or you can pad the numeric with spaces to make the amounts align to a decimal position
you can use printer.textwidth("$12345.66") to return the width of the printed text in the currnet font for the printer, then calculate the number of spaces required to align all the amounts to the decimal point,
if you build a function to do this you can just call it each time you want to align the text, something like this
vb Code:
Private Function dectab(amt As Double)
Dim myt As String, myl As Integer, maxl As Integer, strl As Integer, mystr As String
myt = Format(amt, "##,##0.00;##,##0.00")
myl = TextWidth(myt)
maxl = TextWidth("888,888.00")
strl = (maxl - myl) / TextWidth(" ")
mystr = Space(strl)
dectab = mystr & myt
End Function
call like
vb Code:
printer.print dectab(txtTotal)
you can put any additional formating you want within the function
edit: textwidth in the above function should be changed to printer.textwidth, as this function was used to print to a textbox or form, which probably would be using a different font or font size
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
May 12th, 2007, 02:40 AM
#4
Thread Starter
New Member
Re: Printer Alignment
So I needed to Print for see below:
VB Code:
printer.print "Total:" & dectab(txtTotal)
What would I use to left align total and right align txttotal
Should I use printer.currentx or something to that effect
-
May 12th, 2007, 03:17 AM
#5
Re: Printer Alignment
use printer.currentx to set your left margin for each line. then you could use again to set the position for the amount, you would need to calculate the width of the text to the right of the decimal, deduct that from the position of your decimal, then that would be your currentx to print the amount
vb Code:
Printer.CurrentX = lmargin
Printer.Print "Total:";
Printer.CurrentX = decimalpointposition - Printer.TextWidth(Format(txttotal, "######0"))
Printer.Print txttotal
just another way to do it
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|