ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

center text data

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

  • center text data

    here's a cheap & cheesy tool to center data:

    Code:
         Ddata             s            500a
         Dwrkdata          s            500a
         Dlen              s              3s 0
         Ddatalen          s              3s 0
         Ddivisor          s              3s 0
         Dstrpos           s              3s 0
         C     *Entry        plist
         C                   Parm                    Data
         C                   Parm                    Len
          /free
                  if data <> *blanks;
                  Divisor=Len/2;
                  datalen=%len(%Trim(Data));
                  strpos=datalen/2;
                  strpos=Divisor-strpos;
                  WrkData=Data;
                  Data=*Blanks;
                  if StrPos+DataLen<=%size(Data);
                  %subst(Data:Strpos:DataLen)=%Trim(WrkData);
                  endif;
                  if StrPos+DataLen>%Size(Data);
                  Data=%Trim(WrkData);
                  endif;
                  endif;
                  *INLR=*ON;
                  Return;
          /end-free
    the program receives 2 parms. the data to center and the size of the field that contains the data. the program will place the data so it will be centered for the length passed in.

    The field "Data" is 500a, the "PgmTitle" field is 50a
    example of a call to the program:
    Code:
    PgmTitle = 'Equipment Listing';           
    Data = PgmTitle;                          
    CenterIt( Data : %Len(PgmTitle));         
    PgmTitle = %Subst(Data:1:%Len(PgmTitle));
    the text "Equipment Listing" will be returned from the program in the "Data" field. Just Load your original field using %SUBST.
    I'm not anti-social, I just don't like people -Tommy Holden

  • #2
    Re: center text data

    Question,
    What is the advantage of centering your data? It seems that it would introduce more worry about trimming leading and trailing blanks. I'm just curious...
    Your future President
    Bryce

    ---------------------------------------------
    http://www.bravobryce.com

    Comment


    • #3
      Re: center text data

      for a small example you define a 40 *char field at the top of all your displays
      which is the title of the page.

      you can use the center function to center the data on your page headings..


      jamie
      All my answers were extracted from the "Big Dummy's Guide to the As400"
      and I take no responsibility for any of them.

      www.code400.com

      Comment


      • #4
        Re: center text data

        Originally posted by jamief View Post
        for a small example you define a 40 *char field at the top of all your displays
        which is the title of the page.

        you can use the center function to center the data on your page headings..


        jamie
        BINGO...that and report headings..etc, etc
        I'm not anti-social, I just don't like people -Tommy Holden

        Comment


        • #5
          Re: center text data

          Gotcha, sorry, I was assuming database field. Narrow minded question. That definitely makes more sense now
          Your future President
          Bryce

          ---------------------------------------------
          http://www.bravobryce.com

          Comment


          • #6
            Re: center text data

            Why cheesy ? That could be of a good value in certain circumstances.
            Philippe

            Comment


            • #7
              Re: center text data

              Mercury, not sure I understand your question.... did you post in the right thread?
              Your future President
              Bryce

              ---------------------------------------------
              http://www.bravobryce.com

              Comment


              • #8
                Re: center text data

                Bryce, I think Mercury is referring to Tom's own comment when he first posted this tool.

                Comment


                • #9
                  Re: center text data

                  aahhh....yes, i missed that cheesy comment. Thanks
                  Your future President
                  Bryce

                  ---------------------------------------------
                  http://www.bravobryce.com

                  Comment

                  Working...
                  X