Results 1 to 9 of 9

Thread: Right justify

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    17

    Question Right justify

    Is there a way to right justify the output to a printer. For example, I have an order printing out with the itemized amounts left justified so it looks like this:


    Results:

    900.00
    45.00
    1.99


    I want these results justified to the right so that the decimal point is aligned:

    900.00
    45.00
    1.99
    I use the printer.print method to print to the printer. How can this be done?

  2. #2
    Fanatic Member space_monkey's Avatar
    Join Date
    Apr 2005
    Location
    神と歩くこと
    Posts
    573

    Re: Right justify

    You can do...

    VB Code:
    1. dim strJustify as string
    2.  
    3. strJustify = space(10)
    4.  
    5. Rset strJustify = "900.00"

    I do this alot with reports that i need to format.

    HTH
    Using VB6 or VB.net 2008 with .net 3.5
    "Life... death... either way I'll be confined to a small cubicle!" - Hermes Conrad

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    17

    Re: Right justify

    Thanks for your fast reply Space Monkey, but how do I use Rset in this code:

    VB Code:
    1. printer.print rstPBHnd.fields("Results")

    I have a couple of records that I want to be printed in a column with the decimal point aligned. I have tried to use Format but that didn't work either.

  4. #4
    Fanatic Member space_monkey's Avatar
    Join Date
    Apr 2005
    Location
    神と歩くこと
    Posts
    573

    Re: Right justify

    Is there a reason you can't do this?

    VB Code:
    1. dim strJustify as string
    2. strJustify = space(10)
    3.  
    4. '.........
    5. Rset strJustify = rstPBHnd.fields("Results")
    6. Printer.Print strJustify
    Using VB6 or VB.net 2008 with .net 3.5
    "Life... death... either way I'll be confined to a small cubicle!" - Hermes Conrad

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    17

    Re: Right justify

    Yes, I figured that out eventually. Rset works, but only if the amount of characters is the same.
    If I have a result of 9.8 and another of 10.2 then the decimal points will not be aligned. Do I have to check the length of each record and adjust the amount of space acordingly before printing, or is there an faster way ?

  6. #6
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536

    Re: Right justify

    Is this ok?
    VB Code:
    1. Private Sub Form_Load()
    2.  
    3. Debug.Print RAlign(9.8)
    4. Debug.Print RAlign(10.2)
    5. Debug.Print RAlign(900)
    6. Debug.Print RAlign(45)
    7. Debug.Print RAlign(1.99)
    8.  
    9. End Sub
    10.  
    11. Private Function RAlign(pValue As Single) As String
    12.   RAlign = Right$(Space(10) & Format(pValue, "0.0"), 10)
    13. End Function
    This world is not my home. I'm just passing through.

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

    Re: Right justify

    Quote Originally Posted by trisuglow
    Is this ok?
    VB Code:
    1. Private Sub Form_Load()
    2.  
    3. Debug.Print RAlign(9.8)
    4. Debug.Print RAlign(10.2)
    5. Debug.Print RAlign(900)
    6. Debug.Print RAlign(45)
    7. Debug.Print RAlign(1.99)
    8.  
    9. End Sub
    10.  
    11. Private Function RAlign(pValue As Single) As String
    12.   RAlign = Right$(Space(10) & Format(pValue, "0.0"), 10)
    13. End Function
    Slick!

  8. #8
    Fanatic Member space_monkey's Avatar
    Join Date
    Apr 2005
    Location
    神と歩くこと
    Posts
    573

    Re: Right justify

    The other thing you could do would be.


    VB Code:
    1. dim strJustify as string
    2. strJustify = space(10)
    3.  
    4. '.........
    5. Rset strJustify = Format(rstPBHnd.fields("Results"), "0.00")
    6. Printer.Print strJustify

    that would force it to have two decimals
    Using VB6 or VB.net 2008 with .net 3.5
    "Life... death... either way I'll be confined to a small cubicle!" - Hermes Conrad

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    17

    Re: Right justify

    Thanks for your reply, I will need to do some finetuning for the different amount of chars. I will look into that tomorrow.

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