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
#6
Even this one!
Code: (Select All)
_Title "wrap$ test, press w for widen, d for decrease." 'b+ 2019-12-28  a simple way


test$ = "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."
w = 60: m = 20
Do
    k$ = InKey$
    If k$ = "d" Then w = w - 1
    If k$ = "w" Then w = w + 1
    If w > 70 Then w = 70
    If w < 30 Then w = 30
    m = Int((78 - w) / 2)
    Cls
    printWrap test$, w, 5, m
    _Limit 10
Loop Until _KeyDown(27)

'This function returns the first segment of string less than or equal to maxLen AND
'the remainder of the string (if any) is returned in tail$ to be used by wrap$ again
Function wrap$ (s$, maxLen, tail$)
    If Len(s$) > maxLen Then
        p = maxLen + 1
        While Mid$(s$, p, 1) <> " " And p > 1
            p = p - 1
        Wend
        If p = 1 Then
            wrap$ = Mid$(s$, 1, maxLen): tail$ = Mid$(s$, maxLen + 1)
        Else
            wrap$ = Mid$(s$, 1, p - 1): tail$ = Mid$(s$, p + 1)
        End If
    Else
        wrap$ = s$: tail$ = ""
    End If
End Function

'this sub uses the wrap$ function to print out a string with row and column offsets
Sub printWrap (s$, maxLen, rowOffset, colOffset)
    ss$ = s$ 'work with copy
    Do
        Locate rowOffset + i, colOffset: Print wrap$(ss$, maxLen, st$)
        ss$ = st$
        i = i + 1
    Loop Until Len(ss$) = 0
End Sub

(04-14-2024, 10:07 PM)Pete Wrote: Mine was made for and works in SCREEN 0. Eventually, I will need to make one for graphics screens that includes different text character widths, as my hypertext project.

Pete Wink

man what graphic screen?
b = b + ...
Reply


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



Users browsing this thread: 1 Guest(s)