+ Reply to Thread
Results 1 to 6 of 6

Thread: Centering text within a field

  1. #1
    Guest.Visitor Guest

    Default Centering text within a field

    Linda, Here's something I had published in Midrange Computing back in Sep 1999. If you have any questions, please let me know. Center Text Pronto! Looking for a quick way to center text in RPG IV? Try the technique I put together in Figure 2! It’s fast, simple, and, best of all, doesn’t take a lot of lines of code! — Michael C. Schlemme MSchlemme@Banta.com[*][*] Field to contain centered data (pick one definition)[*] D target_field S LIKE(source_field) C *LIKE DEFINE target_field source_field[*][*] Center field[*] C EVAL %SUBST(target_field: C %INTH((%SIZE(source_field)C %LEN(%TRIM(source_field))) / 2 + 1): C %LEN(%TRIM(source_field))) = C %TRIM(source_field)

  2. #2

    Default Centering text within a field

    Create a procedure so it can be reused! This example allows for a dynamic input that is not necessarily the same length as the output field.
    Code

  3. #3
    Guest.Visitor Guest

    Default Centering text within a field

    While I liked seeing Michael's response because I had never used the %int or %inth functions, neither his nor Will's allow for a smaller output string than input string. My preference is to use a procedure also, with a few differences than Will's solution. Also, one advantage that I like about procedures is that you can center back into the same field that you used for input.
    Code

  4. #4
    Guest.Visitor Guest

    Default Centering text within a field

    I use the following code, which requires no additional fields, and is probably not limited to a range of field sizes; typically I use this with fields in the 60-80 byte range but have tested it with larger fields (up to 1024 bytes) with no problems.
    Code

  5. #5
    lindafyeager Guest

    Default Centering text within a field

    What's the best and shortest way to take a field (i.e. Name) and center the text?

  6. #6

    Default Centering text within a field

    I've used the following for about 5 years, so it's well tested. I don't know if it's the "best and shortest", but it's virtually bullet-proof, and it's probably the simplest to use, once the procedure is created. In our shop, we use service programs extensively, so this procedure is one of a handful of "text manipulation" procedures in a single service program. Note that the procedure centers based on the length of the field that is passed, so in some cases, you may want to use the second listed option, depending on the field lengths involved. (Procedure/prototype names used are due to our naming conventions.)
    Code

+ Reply to Thread

Similar Threads

  1. API for Changing the Field Description or Text of a field inPF
    By David Abramowitz in forum Programming
    Replies: 4
    Last Post: 05-25-2001, 06:23 AM
  2. Number in a text field into a numeric field
    By Guest.Visitor in forum Programming
    Replies: 6
    Last Post: 03-15-2001, 01:10 AM
  3. HEX displayed for all numbers in Text field
    By Guest.Visitor in forum Programming
    Replies: 3
    Last Post: 09-11-2000, 11:22 AM
  4. centering of field
    By Guest.Visitor in forum Programming
    Replies: 7
    Last Post: 06-30-1999, 01:52 AM
  5. centering text string
    By wjminc in forum Programming
    Replies: 3
    Last Post: 06-25-1998, 10:54 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts