How to right align numbers using VB6 Printer Object

To Print data at 100,100 using Printer Object in VB6 my code will be like this.

set myPrinter = printer
myPrinter.pset(100,100)
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.
UnmeshAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
VBtomConnect With a Mentor Commented:
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


0
 
UnmeshAuthor Commented:
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
        Else
            Printer.fontsize = FSize
        End If
        PObj.CurrentX = X - PObj.TextWidth(Data)
        PObj.CurrentY = Y
        PObj.Print Data
        Exit Function
PrintNumberErr:
    MsgBox CStr(Err.Number) + " - " + Err.Description, vbCritical, "Printing Error"
End Function
0
All Courses

From novice to tech pro — start learning today.