Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


How to right align numbers using VB6 Printer Object

Posted on 2003-02-21
Medium Priority
Last Modified: 2008-02-01
To Print data at 100,100 using Printer Object in VB6 my code will be like this.

set myPrinter = printer
myPrinter.print data

by default it will align the text to left, because we are assigning co-ordinets from left to right. But while printing numbers we should align numbers at right side. How we can do that. Adding fixed number of spaces before number does not works.
Question by:Unmesh
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

VBtom earned 200 total points
ID: 7992660
BTW, for printing at (100,100) u use Printer.CurrentX = 100: Printer.CurrentY = 100 (Pset prints a pixel at 100,100)

An example for aligning 2 numbers right (suppose the right side should be at x = 5000)

Dim x as long
x = 123
printer.currentx = 5000 - Printer.Textwidth(x)
printer.print x
x = 123456
printer.currentx = 5000 - Printer.Textwidth(x)
printer.print x


Author Comment

ID: 7997935
Nice code suggested by VBtom!!!!
Here is function I have added in my module.

Public Function PrintNumber(X As Integer, Y As Integer, Data As String) As Boolean
    On Error GoTo PrintNumberErr
        Set PObj = Printer
        Printer.fontsize = FSize 'Font Size
        Printer.FontBold = FBold  'Font Bold
        Printer.FontItalic = FItalic  'Font Italic
        Printer.FontName = FName 'Font Name
        If FSize = 0 Then
            Printer.fontsize = 12
            Printer.fontsize = FSize
        End If
        PObj.CurrentX = X - PObj.TextWidth(Data)
        PObj.CurrentY = Y
        PObj.Print Data
        Exit Function
    MsgBox CStr(Err.Number) + " - " + Err.Description, vbCritical, "Printing Error"
End Function

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A short article about problems I had with the new location API and permissions in Marshmallow
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Starting up a Project

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question