Member Avatar for Member #100915

Hi all,
Working in a Pos System and using this code for print all product from the list. The code wrk fine the only prb is:
The text begin printing from the middle of paper and not from the left side. Where is the prb?
This is the code:

Private Sub cmdPrint_Click()
Dim WhatDay$, Count%
Dim Tab1%, Tab2%, StoreCurrY%

If frmPOS.List1.ListCount = 0 Then
MsgBox "No has selectado ningun producto", , gStanCap
Exit Sub
End If

Printer.EndDoc
Tab1 = 0
Tab2 = 0
With Printer

.Font = "Courrier New"
.FontSize = 12
.FontBold = True
.FontUnderline = True
.FontSize = 12
.FontUnderline = False

Printer.Print
Printer.Print

.CurrentX = .CurrentX + 1
.FontBold = False
Printer.Print

Do
.CurrentX = Tab1
StoreCurrY = .CurrentY
Printer.Print frmPOS.List1.List(Count)
If Count + 1 = frmPOS.List1.ListCount Then .FontUnderline = True
.CurrentX = Tab2
.CurrentY = StoreCurrY
Printer.Print
Count = Count + 1
Loop While Count < frmPOS.List1.ListCount

.FontUnderline = False
.FontBold = True

.CurrentX = Tab2
.FontBold = True
.FontSize = 14
.CurrentX = (.Width - .TextWidth(" TOTAL:- " & frmPOS.txtTotal)) / 2
Printer.Print "TOTAL:- " & frmPOS.txtTotal
Printer.Print

.CurrentX = Tab1
.FontBold = True
.FontSize = 14
.CurrentX = (.Width - .TextWidth(" GRACIAS POR SU VISITA ")) / 2
Printer.Print " GRACIAS POR SU VISITA "

Printer.EndDoc

End With

End Sub

I`m using a epson tm-u220d and the paper size is 76x292 mm

Tks in advance
Costel

Dani AI

Generated

A short diagnostic and fix list for the “prints from the middle” symptom observed in ’s code.

  • Root cause most likely: the VB Printer object is positioning using the page size the Windows driver reports, not the narrow receipt printable area. Printer.Width and the Printer coordinate system are in twips and reflect the driver-selected paper size; if the driver is still set to a full page (A4/Letter) the left edge used by VB will appear offset on a 76 mm roll. Check the printer driver/paper-size first. (Printer.Width docs). (learn.microsoft.com)

  • Quick tests and VB-side checks: print one short line with a visible left marker to see where the driver is actually placing the left margin. Confirm the printing units (ScaleMode) are twips so CurrentX, Width and TextWidth use the same unit, and note that EndDoc resets coordinates to 0 — calling it at the wrong time can confuse positions. For column math rely on TextWidth (measured in the same units) and use a fixed-width font spelled correctly (for example, Courier New) so text columns line up. (Printer.CurrentX docs, TextWidth docs). (learn.microsoft.com)

  • POS-printer option (recommended when using an Epson TM-U220): use the printer’s native ESC/POS alignment and margin commands (for example, ESC a n to select justification) rather than relying on VB centering math. To send those control bytes reliably, send raw bytes to the spooler (Win32 spooler APIs / “raw” print) so the driver does not strip ESC/POS codes. (ESC/POS select-justification, MS guidance on raw printing). (download4.epson.biz)

Practical checklist tied to the posted code:

  • Verify Windows printer preferences are set to the receipt/76 mm paper and the correct Epson driver.
  • Fix the font assignment (use the Printer.Font object / Courier New), and use TextWidth for column math.
  • Remove or move any EndDoc that is being called before printing starts.
  • If driver/page-size fixes don’t work, switch to ESC/POS alignment (or raw-WritePrinter) for predictable left/center/right behavior.

Note: ’s HTML-preview suggestion is useful for visual layout checks, but HTML/Windows preview will not reproduce ESC/POS/driver behavior — use it for design only, and test final output on the actual printer.

Hi Cos,

Can you try populating the contents to a HTML File instead of issuing a direct print? By this way you can open the HTML file and use print preview to see how it looks.


Regards
Marikanna

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.