BBS: Inland Empire Archive Date: 09-09-92 (23:38) Number: 345 From: JOHN WHITE Refer#: NONE To: PAUL KIMBALL Recvd: NO Subj: Formatting text strings. Conf: (2) Quik_Bas
> Does anyone have some code that will take a long text string and format...
' WRAPLINE.SUB, Public Domain, John White 1:3636/2, 09-09-92
'
' slen = Maximum length of each line
' strin$ = The string to parse
' work$ = Temp variable for parsing
' x$() = array holding the parsed strings
' idx = maximum number of parsed strings in x$()
'============================================================================
DEFINT A-Z
DECLARE SUB WRAPLINE (slen, strin$, x$(), idx)
DIM x$(100) 'DIM to max you need or use $DYNAMIC before DIMing & $STATIC after
CLS
strin$ = STRING$(254, "x") 'Test string
WRAPLINE 75, strin$, x$(), idx
IF idx = 0 THEN PRINT "No Data in strin$": END
FOR a = 1 TO idx
PRINT x$(a)
NEXT
'---
SUB WRAPLINE (slen, strin$, x$(), idx)
IF strin$ = "" THEN idx = 0: EXIT SUB 'If string to split is nothing, exit
work$ = strin$ 'Keep original value in strin$
done = 0 'reset flag
DO
IF LEN(work$) > slen THEN
idx = idx + 1 'Increment index to array
x$(idx) = LEFT$(work$, slen) 'Put left (slen) chars in array
work$ = MID$(work$, slen + 1) 'Remove parsed segment from work$
ELSE
done = -1
END IF
LOOP UNTIL done
IF idx THEN
idx = idx + 1 'Save remainder of strin$
x$(idx) = work$
END IF
END SUB
'Hope this helps Paul!
--- GEcho 1.00/beta
* Origin: WhiTech BBS (919) 692-6138 (1:3636/2)

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