CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2001
    Posts
    254

    printer object alignment

    how can I aligned printing of numbers from left-justified to right-justified ;

    vValue1=xxx.xx
    vValue2=xxxx.xx
    vValue3=xx.xx

    Printer.print "Value No 1 : " & vValue1
    Printer.print "Value No 2 : " & vValue2
    Printer.print "Value No 3 : " & vValue3

    results
    Value No 1 : xxx.xx
    Value No 2 : xxxx.xx
    Value No 3 : xx.xx


    thanks
    cyrus



  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: printer object alignment

    You may set the currentx property of printer:
    http://codeguru.com/cgi-bin/bbs/wt/s...age=&view=&sb=

    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Micahel
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  3. #3
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: printer object alignment

    Another trick: store numbers in string variable of fixed lenght, aligned to right with format function. Then print the string variables.

    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Micahel
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  4. #4
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: printer object alignment

    As Cimperiali implied, you will have to use the CurrentX property. Then, in assosiation with the TextWidth, you can determine where to start. Note tha in the code I used Me instead of Printer, which results in the text being printed on the form.

    Dim sWidth as Long
    ' compute point where it must be alligned, you can give this a fixed value if you want
    sWidth = me.TextWidth("000000.00")

    me.CurrentX = sWidth - me.TextWidth("1234.56")
    me.print "1234.56"
    me.CurrentX = sWidth - me.TextWidth("123.45")
    me.print "123.45"
    me.CurrentX = sWidth - me.TextWidth("12345.67")
    me.print "12345.67"




    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  5. #5
    Join Date
    Sep 2001
    Posts
    254

    Re: printer object alignment

    excellent, but I left one major issue ,a text preceeded the numbers
    ie
    vGross=123.45
    vDiscount=23.45
    vNett=100.00
    printer.currentx = sWidth - printer.textwidth(vGross)
    printer.print "Gross : " & vGross
    printe.currentx=swidth - printer.textwidht(vDiscount)
    printer.print "Discounts : " & vDiscount
    printer.print " ----------------- "
    printer.currentx=swidth - printer.textwidht(vNett)
    printer.print "Nett : " & vNett

    using Currentx affects alignment of text

    thanks in advance

    cyrus



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

Featured