Announcement

Collapse
No announcement yet.

Variable length data printed neatly?

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

  • Michael Mattias
    replied
    PB/Win Code, but I think it will darn near work 'as is' in the latest PB/DOS...

    Code:
    FUNCTION WordBreakString ALIAS "WordBreakString" (szIn AS ASCIIZ, szOut AS ASCIIZ, BYVAL MaxLineLength AS LONG) AS LONG
    ' breaks up szIn into LF =terminated strings not larger than maxLineLength
    ' returns: # of LF-terminated strings szOut
    
       LOCAL Stat AS LONG, I AS LONG, J AS LONG
       LOCAL inLEn AS LONG
       LOCAL LenSzOut AS LONG
    
       LOCAL pIN AS STRING PTR * 1, pOut AS STRING PTR * 1
       LOCAL LineBReak AS LONG, LineLength AS LONG
    
       pIn =  VARPTR (szIn)
       pOut = VARPTR (szOut)
       inLEn = LEN (szIn)
    
       I = 0
       J = 0    ' characters this line
    
       LOCAL forward AS LONG, backward AS LONG, Direction AS LONG
       Forward = 1
       Backward = -1
    
       DECR pIn
       DECR pOut
    
       LineBreak = %FALSE
       Direction = Forward
       LineLength = MaxLineLength
       Stat = 0
    
       WHILE I <= InLen
             pIn   = pIn  + Direction
             pOut  = pOut + Direction
             @Pout = @pin
             J = J + Direction
             I = I + direction
             IF J = LineLength THEN
                SELECT CASE @pin
                       CASE ",", " ",")","!","?"   ' character OK to break on
                          LineBreak = %TRUE
                       CASE ELSE
                      ' go back to first qualifying break character and accept a smaller linelenght
                          Direction = Backward
                          DECR LineLength
                END SELECT
            ELSEIF I = InLen THEN
               LineBreak = %TRUE
            END IF
            IF LineBreak THEN
               INCR pOut
               @pOut = $LF
               INCR Stat
               Direction = Forward
               LineLength = MaxLineLength
               LineBreak = %FALSE
               J = 0
            END IF
       WEND
       FUNCTION = Stat
    
    END FUNCTION
    MCM



    [This message has been edited by Michael Mattias (edited January 01, 2004).]

    Leave a comment:


  • Robert E. Carneal
    started a topic Variable length data printed neatly?

    Variable length data printed neatly?

    I have a data file contaning three fields per record.
    The first field is an abbreviation, the 2nd field is
    the word, and the 3rd field is the meaning of that word.

    Example:
    "DIVF","DIVORCE FILED","Filing of divorce by a spouse."

    Therefore when someone wants to know the meaning of the
    abbreviation, they can type that in.

    Problem: Some definitions are 100s of characters long.

    Does anyone have a easy way of breaking up the meaning into
    several readable lines so that it word wraps neatly? Seems
    like I recall someone doing this, perhaps it was Dan?

    Thank you.

    Robert

    ------------------
Working...
X