Something like....
Dim reader As New System.IO.StreamReader(filePath)
Dim textLine As String
Dim count As Integer = MAIN_FORM.wordCountBox.Value
Dim pos As Integer = 0
Do While reader.Peek <> -1
textLine = reader.ReadLine
'Split the line to the individual words
Dim parts = textLine.Split(" "c)
Do
'Add check to see if period is there
Dim Periodfinder As Int32
For Periodfinder = pos To parts.GetUpperBound(0)
If parts(Periodfinder).ToString.Contains(".") Then Exit For
Next
'set periodfinder to difference between it and pos +1
Periodfinder = Periodfinder - pos + 1
'check if it is less than count
If Periodfinder < count Then count = Periodfinder
'Skip the previous words and take the count required
Dim block = parts.Skip(pos).Take(count).ToArray
'position to read the next count words
pos += count
'reset count
count = MAIN_FORM.wordCountBox.Value
If block.Count > 0 Then
block(0) = CultureInfo.InvariantCulture.TextInfo.ToTitleCase(block(0))
End If
MAIN_FORM.previewBox.Items.Add(String.Join(" ", block))
'or if you dont want the period to be carried through
MAIN_FORM.previewBox.Items.Add(String.Join(" ", block).Replace(".",""))
Loop While (pos < parts.Length)
Loop
Code updated to allow for multiple periods in the string.
In the example in your comment below this turns One two three four five six seven eight nine ten into:
One two three four five six seven
Eight nine ten
and one two three. four five six seven. eight nine ten into:
One two three.
Four five six severn.
Eight nine ten
(if you set the limit to 7 words)
I am outputting to console.writeline to test it.
Example in Listbox control
In certain width/height ratios AND if the multicolumn is set to True then it will put the two entries side by side rather than one above the other!