Word wrap code

 BBS: Inland Empire Archive
Date: 12-10-92 (08:20)             Number: 354
From: RON PIERCE                   Refer#: NONE
  To: TERRY ROSSI                   Recvd: NO  
Subj: Word wrap code                 Conf: (2) Quik_Bas
TR>so the the next line begins with a complete word.   Anybody have any

        Hi Terry.  WHat you need to do is locate the last " " (SPACE) in
the string you are processing and clip the string there and "carry-over"
the remainder of the string as a new string.  Here is some sample code
which should do this.

' ====================================================================
' =====================  Word Wrap Subroutine  =======================
' ====================================================================
' Max%  = Maximum length allowed for "b$" (the string we are processing
' CurLen% = Length of String we are processing
' b$ = String being processed
' b1$ = String containing what's "left over" from b$ after wrap

  CurLen% = LEN(b$)

  IF CurLen% >= Max% THEN    '
      FOR Posit% = LEN(b$) TO 1 STEP -1

          i% = ASC(MID$(b$, Posit%, 1))

          IF i% = 32 THEN
             IF Curlen% = Max% THEN
                b$ = LEFT$(b$, Posit% -1)
                EXIT FOR
                IF Posit% < Max% THEN
                   b1$ = MID$(b$, Posit% +1)   ' "remainder" String
                   b$ = LEFT$(b$, Posit% - 1)  ' Return "wrapped" b$
                   EXIT FOR
                END IF
             END IF
          END IF

      NEXT Posit%

The above is untested but should "almost" work.  I use assembler to
speed this up but actually it is fast enough with BASIC code alone.


 * SLMR 2.0 #1376 * Whatever became of the ROCK Band "Cactus" (1970)

--- WM v2.05/92-0545
 * Origin: Toast House - (314) 994-0312 - (1:100/560)
Outer Court
Echo Basic Postings

Books at Amazon:

Back to BASIC: The History, Corruption, and Future of the Language

Hackers: Heroes of the Computer Revolution (including Tiny BASIC)

Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution

The Advent of the Algorithm: The Idea that Rules the World

Moths in the Machine: The Power and Perils of Programming

Mastering Visual Basic .NET