[code]Function ConcCont(t As Text) As Text
Using Xojo.Math
Const MAX_LENGTH = 248
Dim result() As Text
Dim pos, count As Integer
Dim rest As Integer = t.Length
Dim lines() As Text = t.Split(&uA)
Dim i As Integer
For Each line As Text In lines
count = Min(MAX_LENGTH, line.Length)
result.Append(If(i = 0, "NOTE ", "CONT ") + line.Mid(pos, count))
rest = rest - count
While rest > 0
pos = pos + count
count = Min(MAX_LENGTH, rest)
result.Append("CONC " + line.Mid(pos, count)) // Exception, why?
rest = rest - count
Wend
i = i + 1
Next
Return Text.Join(result, &uA)
Mid(start As Integer) As Text
An overload of Mid that returns all of the characters from start to the end of the text. The start position is a zero-based.
Dont call mid when the start position is > the number of characters
The new framework throws exceptions when you do this
Pos has to be set to 0 at the beginning of the loop, and it is advisable to iterate in a for next loop instead of for each See the warning about for each iterations and index order at http://developer.xojo.com/for-each-next (although currently it will probably work alright).
Also, better compare the length of each line and not against t.length as the sum of all lines.lenghts will differ from the original (the EOLs are stripped).