Step is one of the most often forgotten aspects of “For … Next”. I depended on it for much back in MSBASIC/GWBASIC and until Dave’s example I’d forgotten about it and have been doing idiotic things like:
For x = 0 To My Count
// Skip to every third
ProgressBar.Refresh
x = x + 3
Next
what portion of the process do you not understand?
v=split(textArea1.text,endofline) // take the text in the TextArea and split it into individual lines
for i=0 to v.ubound step N // iterate over that set of lines every "N" lines
v(i)=v(i)+endofline // Add an additional endofline to every Nth line
next i // end of loop
textarea1.text=join(v,endofline) // join the array back into the textarea by endofline
Thank you very much.
I did not manage to cause a break after the third line.
Which have me thinking, maybe what I need is a new line insert instead of a EndOfLine
Is there really any difference?
Based on Dave’s code, you might need to tweak the EndOfLine.Macintosh/EndOfLine.Windows depending on your platform.
Dim v() As String
v = Split(textArea1.Text, EndOfLine.Macintosh)
For i As Integer = 0 To v.ubound
v(i) = Str((i Mod 3) + 1) + " " + v(i) + If(i Mod 3 = 2, EndOfLine.Windows, "")
Next i
textarea1.Text = Join(v, EndOfLine.Windows)
or like this if you dont like inline ifs
Dim v() As String
v = Split(textArea1.Text, EndOfLine.Macintosh)
For i As Integer = 0 To v.ubound
v(i) = Str((i Mod 3) + 1) + " " + v(i)
If i Mod 3 = 2 Then
v(i) = v(i) + EndOfLine.Windows
End If
Next i
textarea1.Text = Join(v, EndOfLine.Windows)
Dim v() As String
Const n As Integer = 3 'Change to a Dim not Const if you want to alter this at runtime
v = Split(textArea1.Text, EndOfLine.Macintosh)
For i As Integer = 0 To v.ubound
v(i) = Str((i Mod n) + 1) + " " + v(i) + If(i Mod n = n - 1, EndOfLine.Windows, "")
Next i
textarea1.Text = Join(v, EndOfLine.Windows)