overlord mode has been enabled
vb.net text aligner
the following program is a text aligner.
the program gets a text via the richtextbox conrol and adds new lines
so that no line's length surpasses the maximum length set by the end user.
the program also takes space characters under consideration, in order to not
break words.
form controls :
button
richtextbox
2 textboxes
all of the control properties are set to default.
paste the to be aligned text using ctrl+v in the richtextbox
set the line limit in textbox1 using an integer
set the minimum characters per line in textbox2 using an integer
and click the button.
vb.net text aligner
the following program is a text aligner.
the program gets a text via the richtextbox conrol and adds new lines
so that no line's length surpasses the maximum length set by the end user.
the program also takes space characters under consideration, in order to not
break words.
form controls :
button
richtextbox
2 textboxes
all of the control properties are set to default.
paste the to be aligned text using ctrl+v in the richtextbox
set the line limit in textbox1 using an integer
set the minimum characters per line in textbox2 using an integer
and click the button.
Code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'* multiline textbox
Dim nEnter As String = "qwertyuiopasdfghjklzxcvbnm,.1234567890-=\ "
nEnter &= "`~!@#$%^&*()_+|QWERTYUIOPASDFGHJKLZXCVBNM<>?:{}[];'./"
nEnter &= """"
Dim result As String = ""
Dim lineLimit As Byte
Dim minCharsPerLine As Byte
Try
minCharsPerLine = TextBox2.Text
Catch ex As Exception
minCharsPerLine = 5
End Try
Dim ch As Char = ""
Try
lineLimit = TextBox1.Text
Catch ex As Exception
lineLimit = 5
End Try
Dim counter As Integer
counter = 0
For index = 0 To RichTextBox1.TextLength - 1
ch = RichTextBox1.Text(index)
If Not nEnter.Contains(ch) Then
counter = -1
End If
If ch = " " And counter > minCharsPerLine Then
ch = vbCrLf
counter = -1
End If
If counter = lineLimit Then
counter = 0
result &= vbCrLf
End If
result &= ch
counter += 1
Next
RichTextBox1.Text = result
End Sub
End Class