EDIT: I've UPDATED the functions...look at the next post.
Hello everybody
I made up two functions that will allow you to use text wrapping in your DBC and DBPRO programs.
The First One:
Function TextWrap_TotalLines(xMax, string$)
linePos = 0 : cursorPos =0
Repeat
Inc linePos : txt$ = ""
Repeat
Inc cursorPos
txt$ = txt$ + Mid$(string$, cursorPos)
Until cursorPos => Len(string$) Or Text Width(txt$) > xMax
If Text Width(txt$) > xMax
Dec cursorPos : txt$ = Left$(txt$, (Len(txt$) - 1))
a = 0
While (Mid$(string$, cursorPos) <> " ")
Dec cursorPos : Inc a
Endwhile
txt$ = Left$(txt$, (Len(txt$) - a))
Endif
Until cursorPos => Len(string$)
Endfunction linePos
The Second One:
Function TextWrap_GetLine(xMax, string$, getLine)
linePos = 0 : cursorPos =0
Repeat
Inc linePos : txt$ = ""
Repeat
Inc cursorPos
txt$ = txt$ + Mid$(string$, cursorPos)
Until cursorPos => Len(string$) Or Text Width(txt$) > xMax
If Text Width(txt$) > xMax
Dec cursorPos : txt$ = Left$(txt$, (Len(txt$) - 1))
a = 0
While (Mid$(string$, cursorPos) <> " ")
Dec cursorPos : Inc a
Endwhile
txt$ = Left$(txt$, (Len(txt$) - a))
Endif
Until cursorPos => Len(string$) Or linePos = getLine
Endfunction txt$
The first function: returns the total number of lines that will be used to wrap the text within the xMax.
The second function: returns the text of a specfic line, be sure the line number is valid.
xMax: is the total text width of each line.
string$: is the entire string you wish to wrap.
getLine: is the number of the line you wish the get.
Here's an example:
rem The parameters.
xMax = 100
string$ = "Here is an example of the text wrapping functions in action. Its easy as! 1 ! 2 ! 3 :)"
rem Make red vertical line to show cut off point.
Ink Rgb(255, 0, 0), 0
Line xMax, 0, XMax, Screen Height()
Ink Rgb(255, 255, 255), 0
rem The actual code that uses the functions.
lines = TextWrap_TotalLines(xMax, string$)
For num = 1 to lines
Print TextWrap_GetLine(xMax, string$, num)
Next num
rem Wait for user, then end.
Wait 1000
Suspend For Key
End
rem The functions.
Function TextWrap_TotalLines(xMax, string$)
linePos = 0 : cursorPos =0
Repeat
Inc linePos : txt$ = ""
Repeat
Inc cursorPos
txt$ = txt$ + Mid$(string$, cursorPos)
Until cursorPos => Len(string$) Or Text Width(txt$) > xMax
If Text Width(txt$) > xMax
Dec cursorPos : txt$ = Left$(txt$, (Len(txt$) - 1))
a = 0
While (Mid$(string$, cursorPos) <> " ")
Dec cursorPos : Inc a
Endwhile
txt$ = Left$(txt$, (Len(txt$) - a))
Endif
Until cursorPos => Len(string$)
Endfunction linePos
Function TextWrap_GetLine(xMax, string$, getLine)
linePos = 0 : cursorPos =0
Repeat
Inc linePos : txt$ = ""
Repeat
Inc cursorPos
txt$ = txt$ + Mid$(string$, cursorPos)
Until cursorPos => Len(string$) Or Text Width(txt$) > xMax
If Text Width(txt$) > xMax
Dec cursorPos : txt$ = Left$(txt$, (Len(txt$) - 1))
a = 0
While (Mid$(string$, cursorPos) <> " ")
Dec cursorPos : Inc a
Endwhile
txt$ = Left$(txt$, (Len(txt$) - a))
Endif
Until cursorPos => Len(string$) Or linePos = getLine
Endfunction txt$
Thats pretty much it. The only thing you have to
watch out for is making sure that there isn't any single word that is greater than your xMax. If anybody finds a bug, let me know