Results 1 to 5 of 5

Thread: Printer Alignment

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2007
    Location
    South Africa
    Posts
    3

    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:
    1. ssql = "Select posprinter from [Settings] "
    2. Ocom.CommandText = ssql
    3. Set orec = Ocom.Execute
    4.   Dim prnPrinter As Printer
    5.     For Each prnPrinter In Printers
    6.     If prnPrinter.DeviceName = orec!posprinter Then
    7.     Set Printer = prnPrinter
    8.     Exit For
    9.     End If
    10.     Next
    11.  
    12. 'Open Till Draw
    13. Printer.Print "A"
    14.  
    15. Printer.Font.Size = 9.5
    16. Printer.FontName = "Arial"
    17. Printer.Font.Size = 12
    18.  
    19. Printer.Font.Bold = True
    20. Set orec = New Recordset
    21. ssql = "Select * from [Company Info]"
    22. Ocom.CommandText = ssql
    23. Set orec = Ocom.Execute
    24. Printer.Print orec!Coname
    25.  
    26. Printer.Font.Size = 9.5
    27. Printer.FontName = "FontA1x1"
    28. Printer.Print orec!Coline2
    29. Printer.Print orec!coaddress1
    30. Printer.Print orec!coaddress2
    31. Printer.Print orec!coaddress3 + "," + orec!coaddress4
    32. Printer.Print "Tel: " + orec!cophoneno
    33. Printer.Print "Vat Reg: " + orec!coregno
    34.  
    35. Printer.Font.Size = 19
    36. Printer.FontName = "FontA1x2"
    37. Printer.Print " "
    38. A$ = "TAX INVOICE"
    39. Printer.Print A$
    40.  
    41. Printer.Font.Size = 9.5
    42.  
    43. Printer.Font.Size = 9.5
    44. 'Printer.FontName = "FontA1x1"
    45. Printer.FontName = "courier new"
    46. Printer.Font.Bold = True
    47. Printer.Print "Customer      : " & txtCustomerName
    48. Printer.Print "Date          : " & lblDate
    49. Printer.Print "Time          : " & lblTime
    50. Printer.Print "Sales Person  : " & lblUser
    51. Printer.Print "Slip No       : " & InvoiceId
    52. Printer.Print "-----------------------------------------"  'LF
    53.  
    54. For Each Lst In FrmPOS.lstvInvoice.ListItems
    55. Printer.Print Lst.SubItems(1) & " "
    56.  
    57. Printer.Print Format(Lst.SubItems(2), "#####0") & " "
    58.  
    59. Printer.Print Lst.SubItems(4) & " " & Lst.SubItems(10)
    60. Next
    61.  
    62. Printer.Font.Size = 9.5
    63. Printer.FontName = "Courier New"
    64. 'Printer.FontName = "FontA1x1"
    65. Printer.Print "-----------------------------------------"  'LF
    66.  
    67. Printer.Font.Size = 10
    68. Printer.FontName = "Arial"
    69. Printer.Font.Bold = True
    70.  
    71. Printer.Print "Total  :" + FormatNumber(txtTotal, 2)
    72. Printer.Print "Cash   :" + FormatNumber(txtTendered, 2)
    73. Printer.Print "Change :" + FormatNumber(txtChange, 2)
    74.  
    75. Printer.Font.Size = 9.5
    76. 'Printer.FontName = "FontA1x1"
    77. Printer.FontName = "Courier New"
    78. Printer.Font.Bold = True
    79.  
    80. Printer.Print "Thank you for your Support"
    81. Printer.Print "Visit us: www.distinctiv.net"
    82. Printer.Print "Email us: [email][email protected][/email]"
    83. Printer.Print "KEEP THIS TILL SLIP AS PROOF OF PURCHASE"
    84.  
    85. Printer.Print ""
    86. Printer.Print ""
    87. Printer.Print ""
    88. Printer.Print ""
    89. Printer.Print ""
    90.  
    91. Printer.EndDoc
    92.  
    93. 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

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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:
    1. Private Function dectab(amt As Double)
    2. Dim myt As String, myl As Integer, maxl As Integer, strl As Integer, mystr As String
    3. myt = Format(amt, "##,##0.00;##,##0.00")
    4. myl = TextWidth(myt)
    5. maxl = TextWidth("888,888.00")
    6. strl = (maxl - myl) / TextWidth(" ")
    7. mystr = Space(strl)
    8. dectab = mystr & myt
    9.  
    10. End Function
    call like
    vb Code:
    1. 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

  4. #4

    Thread Starter
    New Member
    Join Date
    May 2007
    Location
    South Africa
    Posts
    3

    Re: Printer Alignment

    So I needed to Print for see below:

    VB Code:
    1. 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

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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:
    1. Printer.CurrentX = lmargin
    2. Printer.Print "Total:";
    3. Printer.CurrentX = decimalpointposition - Printer.TextWidth(Format(txttotal, "######0"))
    4. 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
  •  



Click Here to Expand Forum to Full Width