Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PrintW - print a long string, breaking it at the last space or hyphen before col. 79
#3
One of my may Wrap routines, which is actually also a RAP routine!

 - Use arrows right and left to narrow and widen right screen margin.

Code: (Select All)
WIDTH 160, 42
_FONT 16
_SCREENMOVE 10, 10
w = _WIDTH
DO
    _LIMIT 30
    REM x$ = "In West    Los Angeles born and raised, at    the    yacht club is where I spent most of my      days, 'til a couple of coders      who were up to no good, started making trouble in my neighborhood. I got booted off Discord and my vids wouldn't play, so I moved to the hills in the State of VA. I pulled up to the forum 'bout a week into April and I yelled to the browser save password log in later. Now I'm able to post and my speech is still free as I sit on my throne as the Prince of P.E."
    x$ = "In West Los Angeles born and raised, at the yacht club is where I spent most of my days, 'til a couple of coders who were up to no good, started making trouble in my neighborhood. I got booted off Discord and my vids won't play, so I moved to the hills in the State of VA. I pulled up to the forum 'bout a week into April and I yelled to the browser, 'save password log in later!' Now I'm able to post and my speech is still free as I sit on my throne as the Prince of P.E."
    CLS
    IF w < _WIDTH - 1 THEN
        FOR i = 1 TO _HEIGHT: LOCATE i, w + 1: PRINT CHR$(179);: NEXT
    END IF
    LOCATE 1, 1
    DO
        WHILE -1
            t$ = MID$(x$, 1, w)
            chop = 1
            IF w <> 1 THEN
                DO
                    IF LEFT$(t$, 1) = " " THEN
                        ' Only happens with more than 1 space between characters.
                        IF LTRIM$(t$) = "" THEN EXIT DO ELSE x$ = LTRIM$(x$): EXIT WHILE
                    END IF

                    IF MID$(x$, w + 1, 1) <> " " AND LTRIM$(t$) <> "" THEN ' Now we have to chop it.
                        IF INSTR(x$, " ") > 1 AND INSTR(t$, " ") <> 0 AND LEN(x$) > w THEN
                            t$ = MID$(t$, 1, _INSTRREV(t$, " ") - 1)
                            chop = 2
                        END IF
                    ELSE
                        chop = 2
                    END IF
                    EXIT DO
                LOOP
                x$ = MID$(x$, LEN(t$) + chop)
            ELSE
                x$ = MID$(x$, LEN(t$) + 1)
            END IF
            IF LEN(t$) AND CSRLIN < _HEIGHT - 1 THEN LOCATE , ml + 1: PRINT LTRIM$(t$)
            EXIT WHILE
        WEND
    LOOP UNTIL LEN(t$) AND LEN(LTRIM$(x$)) = 0
    DO
        b$ = INKEY$
        IF LEN(b$) THEN
            IF b$ = CHR$(27) THEN SYSTEM
            SELECT CASE MID$(b$, 2, 1)
                CASE "K"
                    IF w > 1 THEN w = w - 1
                    EXIT DO
                CASE "M"
                    IF w < _WIDTH - 1 THEN w = w + 1
                    EXIT DO
            END SELECT
        END IF
    LOOP
LOOP


Pete

- I love to WRAP!
Reply


Messages In This Thread
RE: PrintW - print a long string, breaking it at the last space or hyphen before col. 79 - by Pete - 04-14-2024, 08:08 PM



Users browsing this thread: 1 Guest(s)