Splitting a string of text using VB 6.0
Posted on 2011-09-23
I have a variable tmp$ that contains an entire text page of appox. 300 words.
It needs to be divided up into the P$ in lengths of 40 characters max.
Right now it is placing the entire tmp$ into P$.
I not only need it to be no more than 40 characters, it has to not split a word in the middle.
In other words it has to stop on a space dividing a word before the 40 character mark.
Also "On the " would come out as "On the" Should remove end space from sentence.
How can my code below be adjusted to resolve this? Thank You
tmp$="On the first friday of every month our staff members ..."
STRAIGHT 40 RESULT
P$(0)="On the first friday of every month our s"
P(0)$="On the first friday of every month our"
P(1)$="staff members ..."
Dim vSplitTemp As Variant
vSplitTemp = Split(tmp$, vbCrLf)
For x% = LBound(vSplitTemp) To UBound(vSplitTemp)
P$(x% + 1) = vSplitTemp(x%)