Announcement

Collapse
No announcement yet.

Right justify of strings in PBCC

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Right justify of strings in PBCC

    I might be missing something in the commands of PBCC, however I am looking for a way to right-hand justify a proportional font in an XPRINT statement such that on the printed paper all of the text aligns on right. An example would be:
    Name: Joe Smith
    Address: 111 First Street
    Where the colons would line up on the printed page - a sort of "reverse XPRINT SET POS" command. Is there already an intrinsic capability or will I have to come up with my own function to provide this ability?

  • #2
    Using a proportional font, you have to print the colon at 'the spot' then print the label right-justified to its left and the data left-justified to its right.

    Or you can print 'label & ":"' right-justified at "the spot" and add the data left-justified to the right of that.

    It's a little easier using a non-proportional font, but of course that tends to look cheap and dirty. (Probably because it is cheap and dirty).


    MCM
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Print to the screen:

      print;tab(x) - len(text$);text$

      Just make sure the resuling TAB is within a valid range.
      There are no atheists in a fox hole or the morning of a math test.
      If my flag offends you, I'll help you pack.

      Comment


      • #4
        Denny,
        first use the XPRINT TEXT SIZE statement with your string to determine how big your printed string will be. Then set the printing position so your string will end exactly where you want.

        Paul.

        Comment


        • #5
          IF "label" and "data" are not always the same length - meaning "equal" when using a proportional font - you cannot line up the colons without using at least two (2) PRINT statements per line. (Unless you set the TABs just right and no one label is longer than one tabstop-length).
          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            Mike:
            I appreciate the explanation as that is exactly what I need to do. However, is there such an animal as right justified xprint or left justified xprint?

            Comment


            • #7
              Paul:
              Will the xprint text size return the size of the text in the XPRINT scale so that I can subtract the returned value from a virtual XPRINT POS on the paper?

              Comment


              • #8
                PB Help says:
                This statement calculates the total size of the printed text, based upon the current font for the graphic target. The sizes returned are specified in the same terms (pixels or dialog units) as the parent dialog (or world coordinates, if those were chosen with GRAPHIC SCALE).
                This allows you to easily calculate the appropriate print position, particularly when using a proportional font.
                Last edited by Richard Angell; 23 Jan 2008, 11:33 AM.
                Rick Angell

                Comment


                • #9
                  Mike:
                  I don't mind using two XPRINT's per line if I can exactly XPRINT SET POS the right justified text at a calculated point. The left justified text is a no brainer, as it just flows from the colon as any text would after XPRINT SET POS at a point after the colon.

                  All of the left justified stuff is working out perfect. I print the colon at a predetermined coordinate on the line, space to the right by taste, and print the text that follows the colon. The text to the left of the colon is the part that I would like to do with a calculated position derived by subtracting from the colon's position ( much like Paul's suggestion previously ) once knowing how much space the text will take. The issue, I think is, can I calculate this position within the XPRINT SCALE established?

                  Comment


                  • #10
                    Rick:
                    I'm sorry I missed which statement you were refering to.

                    Comment


                    • #11
                      Originally posted by Denny Mela View Post
                      Rick:
                      I'm sorry I missed which statement you were refering to.
                      "Will the xprint text size return the size of the text in the XPRINT scale so that I can subtract the returned value from a virtual XPRINT POS on the paper?"

                      I think there are other posts in the forum showing the justification of text. Having specific commands was wished for some time ago. At any rate, pop the code below into PBWin, compile and press test

                      Code:
                      #COMPILE EXE
                      #CONSOLE OFF
                      #DIM ALL
                      #INCLUDE "Win32API.inc"
                      '
                      SUB LJGRAPHICPRINT(BYVAL ploc AS SINGLE,BYVAL txt AS STRING)
                          'GRAPHIC ATTACH should have already been made
                          LOCAL x!, y!
                          GRAPHIC GET POS TO x!, y!
                          'ploc is the print position left side
                          GRAPHIC SET POS (ploc, y!)
                          GRAPHIC PRINT txt
                      END SUB
                      '
                      SUB RJGRAPHICPRINT(BYVAL ploc AS SINGLE,BYVAL txt AS STRING)
                          'GRAPHIC ATTACH should have already been made
                          LOCAL x!, y!, nWidth!, nHeight!
                          GRAPHIC GET POS TO x!, y!
                          GRAPHIC TEXT SIZE txt$ TO nWidth!, nHeight!
                          'ploc is the print position right side
                          ploc =  ploc - nWidth!
                          GRAPHIC SET POS (ploc, y!)
                          GRAPHIC PRINT txt
                      END SUB
                      '
                      SUB CJGRAPHICPRINT(BYVAL ploc AS SINGLE,BYVAL txt AS STRING)
                          'GRAPHIC ATTACH should have already been made
                          LOCAL x!, y!, nWidth!, nHeight!
                          GRAPHIC GET POS TO x!, y!
                          GRAPHIC TEXT SIZE txt$ TO nWidth!, nHeight!
                          'ploc is the cener of the desired print area
                          ploc =  ploc - (nWidth!/2)
                          GRAPHIC SET POS (ploc, y!)
                          GRAPHIC PRINT txt
                      END SUB
                      '
                      FUNCTION PBMAIN () AS LONG
                          LOCAL caption$,hWin???
                          LOCAL ts1$,ts2$,ts3$,psloc!,ncWidth!, ncHeight!
                          
                          GRAPHIC WINDOW caption$, 200,100, 400, 300 TO hWin???
                              GRAPHIC ATTACH hWin???,0
                              GRAPHIC GET CLIENT TO ncWidth!, ncHeight!
                              GRAPHIC SET POS (0,10)
                      
                              ts1$ = "The short string goes here:"
                              ts2$ = "The nominal string goes here:"
                              ts3$ = "The long string goes here:"
                              psloc! = ncWidth!/2
                              'right justified
                              RJGRAPHICPRINT(psloc!,"RIGHT JUSTIFIED")
                              RJGRAPHICPRINT(psloc!,ts1$)
                              RJGRAPHICPRINT(psloc!,ts2$)
                              RJGRAPHICPRINT(psloc!,ts3$)
                              GRAPHIC PRINT ""
                              'center justified
                              RJGRAPHICPRINT(psloc!,"CENTER JUSTIFIED")
                              CJGRAPHICPRINT(psloc!,ts1$)
                              CJGRAPHICPRINT(psloc!,ts2$)
                              CJGRAPHICPRINT(psloc!,ts3$)
                              GRAPHIC PRINT ""
                              'left justified
                              RJGRAPHICPRINT(psloc!,"LEFT JUSTIFIED")
                              LJGRAPHICPRINT(psloc!,ts1$)
                              LJGRAPHICPRINT(psloc!,ts2$)
                              LJGRAPHICPRINT(psloc!,ts3$)
                              
                              SLEEP 5000
                              GRAPHIC WINDOW END
                      END FUNCTION
                      '
                      .
                      Last edited by Richard Angell; 23 Jan 2008, 11:20 AM. Reason: REPOSTED FOR PBCC
                      Rick Angell

                      Comment


                      • #12
                        I'm using PBCC, Rick. Won't work.

                        Comment


                        • #13
                          picky, picky!

                          Replaced code with PBCC example, no change to the justification functions.
                          Rick Angell

                          Comment


                          • #14
                            > The issue, I think is, can I calculate this position within the XPRINT SCALE established?

                            What happened when you tried?

                            (Show test code if it didn't work and you need more help)
                            Michael Mattias
                            Tal Systems (retired)
                            Port Washington WI USA
                            [email protected]
                            http://www.talsystems.com

                            Comment


                            • #15
                              Hey guys:

                              Thanks to all for your help. I now know how to do this with your help. I have used the XPRINT TEXT SIZE FUNCTION as suggested and can now figure out where to XPRINT SET POS based on the returned values. I'll creating a sub much like Rick's example and will be able to use the info as described in your responses to create lined up colons in the header of my invoice routine.

                              You guys have put me on the right track where before I was frustrated.

                              Comment

                              Working...
                              X